Skip to content

Commit

Permalink
scripts: Use getopt command for collect script
Browse files Browse the repository at this point in the history
Switch to using the `getopt(1)` command for argument parsing as it
supports short and long options.

Signed-off-by: James O. D. Hunt <[email protected]>
  • Loading branch information
jodh-intel committed Mar 9, 2018
1 parent f101d48 commit 16fece2
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions data/collect-data.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,35 @@ show_runtime()

main()
{
case "$1" in
-h|--help) usage && exit 0;;
-v|--version) version && exit 0;;
esac
args=$(getopt \
-n "$script_name" \
-a \
--options="hv" \
--longoptions="help version" \
-- "$@")

eval set -- "$args"
[ $? -ne 0 ] && { usage && exit 1; }
[ $# -eq 0 ] && { usage && exit 0; }

while [ $# -gt 1 ]
do
case "$1" in
-h|--help)
usage && exit 0
;;

-v|--version)
version && exit 0
;;

--)
shift
break
;;
esac
shift
done

[ $(id -u) -eq 0 ] || die "Need to run as root"
[ -n "$runtime" ] || die "cannot find runtime '$runtime_name'"
Expand Down

0 comments on commit 16fece2

Please sign in to comment.