Improve command line parsing adding --debug option to enable bash debug mode.

This commit is contained in:
Christoph Niethammer 2016-05-03 06:52:25 +00:00
parent e4e02bbd21
commit 7819d971c2

63
sit
View file

@ -5,17 +5,18 @@
# Copyright (c) 2011-2016 Christoph Niethammer <niethammer@hlrs.de> # Copyright (c) 2011-2016 Christoph Niethammer <niethammer@hlrs.de>
# #
# exit on any error!
set -e set -e
# for debugging:
# set -x
SIT_PATH=$(cd $(dirname $PWD/$0); pwd) SIT_PATH=$(cd $(dirname $PWD/$0); pwd)
SIT_CONFIG_FILE=$SIT_PATH/etc/sit.conf SIT_CONFIG_FILE=$SIT_PATH/etc/sit.conf
SIT_USER_CONFIG_FILE=$HOME/.sit SIT_USER_CONFIG_FILE=$HOME/.sit
function usage() { function show_help() {
echo "Usage: $0 [action] <sit package name>" echo "Usage: $0 [options] [action] <sit package name>"
echo "Options:"
echo " -h,--help"
echo " -v,--verbose"
echo " --debug"
echo
echo "Valid actions:" echo "Valid actions:"
echo " sitinfo" echo " sitinfo"
echo " unpack" echo " unpack"
@ -31,35 +32,45 @@ function usage() {
echo " all" echo " all"
} }
# sit class file to be installed verbose=0
sit_classfile="" debug=0
# sit action to be performed sit_classfile="" # sit class file to be installed
sit_action="all" sit_action="all" # sit action to be performed
while [ "$1" != "" ] ; do while [ "$1" != "" ] ; do
case $1 in case $1 in
"sitinfo"| \ -h|-\?|--help)
"all"| \ show_help
"unpack"| \ exit
"prepare"| \
"configure"| \
"build"| \
"pretest"| \
"install"| \
"posttest"| \
"postinst"| \
"copy_logs"| \
"setperms")
sit_action=$1
;; ;;
"-*h"|"--help"|"help"|"usage") --debug)
usage $@ echo "Debug mode enabled"
exit 0 set -x
debug=1
;;
-v|--verbose)
verbose=$((verbose + 1))
;;
sitinfo| \
all| \
unpack| \
prepare| \
configure| \
build| \
pretest| \
install| \
posttest| \
postinst| \
copy_logs| \
setperms)
sit_action=$1
;; ;;
*) *)
sit_classfile=$1 sit_classfile=$1
;; ;;
esac esac
shift shift
done done