-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_args.sh
More file actions
executable file
·48 lines (44 loc) · 929 Bytes
/
parse_args.sh
File metadata and controls
executable file
·48 lines (44 loc) · 929 Bytes
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
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
set -euo pipefail
# Default values
action="help"
ACTION_SET=0
CMD_ARGS=()
POSITIONAL_ARGS=()
DRY_RUN=0
SHOW_HELP=0
SKIP_PROMPT=0
while [[ "$#" -gt 0 ]]; do
case "$1" in
-h|--help)
SHOW_HELP=1
CMD_ARGS+=("$1")
shift
;;
-n|--dry-run)
DRY_RUN=1
CMD_ARGS+=("$1")
shift
;;
-y|--skip-prompt)
SKIP_PROMPT=1
CMD_ARGS+=("$1")
shift
;;
--version)
action="version"
ACTION_SET=1
shift
;;
*)
if [[ $ACTION_SET -eq 0 ]]; then
action="$1"
ACTION_SET=1
else
POSITIONAL_ARGS+=("$1")
fi
shift
;;
esac
done
export action DRY_RUN SHOW_HELP SKIP_PROMPT CMD_ARGS POSITIONAL_ARGS