summaryrefslogtreecommitdiffstats
path: root/scripts/lib-boot-args.sh
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--scripts/lib-boot-args.sh38
1 files changed, 38 insertions, 0 deletions
diff --git a/scripts/lib-boot-args.sh b/scripts/lib-boot-args.sh
new file mode 100644
index 0000000..ec97500
--- /dev/null
+++ b/scripts/lib-boot-args.sh
@@ -0,0 +1,38 @@
1#!/usr/bin/env bash
2#
3# scripts/lib-boot-args.sh — shared CLI parsing for the QEMU boot scripts.
4# Sourced, not executed. The caller sets default values for GUI/DEBUG/
5# MEM/SMP first, then calls `parse_boot_args "$@"`. A caller with extra
6# flags defines its own `handle_arg()` to intercept them before the
7# shared cases run (unknown args still fail loudly).
8set -euo pipefail
9
10parse_boot_args() {
11 while [ $# -gt 0 ]; do
12 case "$1" in
13 --gui | -g) GUI="-vga std" ;;
14 --debug | -d) DEBUG="-s -S" ;;
15 --mem)
16 shift
17 MEM="$1"
18 ;;
19 --smp)
20 shift
21 SMP="$1"
22 ;;
23 --help | -h)
24 head -20 "$0" | grep "^#" | sed 's/^# //'
25 exit 0
26 ;;
27 *) handle_arg "$1" ;;
28 esac
29 shift
30 done
31}
32
33# Default: no extra flags. A script with more defines its own before
34# calling parse_boot_args.
35handle_arg() {
36 echo "unknown: $1"
37 exit 1
38}