add self-contained and unified option parsing

master
George Danchev 11 years ago
parent 0c8b8b86e5
commit 1466254129
  1. 55
      releng/inc/releng_getopts.inc
  2. 12
      releng/inc/test_releng_getopt

@ -0,0 +1,55 @@
SELF=$(basename $0)
RELENG_XORRISO=0
KEEP=0
SIMULATE_FAILURE=0
usage() {
cat << EOF
Usage: $SELF -x path/to/xorriso [-k0|1] [-f0|1] [-h]
-x absolute or relative path to binary to be run.
-k keep selfgenerated data, values 0,1 default 0.
-f simulate failure, values 0,1 default 0.
EOF
}
while getopts “x:k:f:h” OPTION
do
case $OPTION in
x)
RELENG_XORRISO=$OPTARG
;;
k)
KEEP=$OPTARG
;;
f)
SIMULATE_FAILURE=$OPTARG
;;
h)
usage
exit 0
;;
*)
usage
exit 31
;;
esac
done
if [ ! -x $RELENG_XORRISO ]; then
usage
printf "\n${SELF}: -x absolute or relative path to binary to be run.\n\n"
exit 31
fi
if [ x"$KEEP" != x"0" -a x"$KEEP" != x"1" ]; then
usage
printf "\n${SELF}: -k keep selfgenerated data, values 0,1 default 0.\n\n"
exit 31
fi
if [ x"$SIMULATE_FAILURE" != x"0" -a x"$SIMULATE_FAILURE" != x"1" ]; then
usage
printf "\n${SELF}: -f simulate failure, values 0,1 default 0.\n\n"
exit 31
fi

@ -0,0 +1,12 @@
#!/bin/bash
set -e
. releng_getopts.inc
printf "\nRELENG_XORRISO =${RELENG_XORRISO}"
printf "\nKEEP =${KEEP}"
printf "\nSIMULATE_FAILURE =${SIMULATE_FAILURE}"
printf "\n"
exit 0
Loading…
Cancel
Save