#!/usr/bin/env bash # # scripts/lib-boot-args.sh — shared CLI parsing for the QEMU boot scripts. # Sourced, not executed. The caller sets default values for GUI/DEBUG/ # MEM/SMP first, then calls `parse_boot_args "$@"`. A caller with extra # flags defines its own `handle_arg()` to intercept them before the # shared cases run (unknown args still fail loudly). set -euo pipefail parse_boot_args() { while [ $# -gt 0 ]; do case "$1" in --gui | -g) GUI="-vga std" ;; --debug | -d) DEBUG="-s -S" ;; --mem) shift MEM="$1" ;; --smp) shift SMP="$1" ;; --help | -h) head -20 "$0" | grep "^#" | sed 's/^# //' exit 0 ;; *) handle_arg "$1" ;; esac shift done } # Default: no extra flags. A script with more defines its own before # calling parse_boot_args. handle_arg() { echo "unknown: $1" exit 1 }