add self-contained and unified option parsing
This commit is contained in:
parent
def086fb8d
commit
b3480b1653
55
libisoburn/trunk/releng/inc/releng_getopts.inc
Normal file
55
libisoburn/trunk/releng/inc/releng_getopts.inc
Normal file
@ -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
|
12
libisoburn/trunk/releng/inc/test_releng_getopt
Executable file
12
libisoburn/trunk/releng/inc/test_releng_getopt
Executable file
@ -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…
Reference in New Issue
Block a user