summaryrefslogtreecommitdiffstats
path: root/scripts/lib-boot-args.sh
blob: ec97500f364b465518ffa00bc1fa5e0e0961f9b7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/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
}