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

75
sit
View file

@ -4,18 +4,19 @@
# #
# Copyright (c) 2011-2016 Christoph Niethammer <niethammer@hlrs.de> # Copyright (c) 2011-2016 Christoph Niethammer <niethammer@hlrs.de>
# #
# exit on any error!
set -e
# for debugging:
# set -x
set -e
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"| \ --debug)
"build"| \ echo "Debug mode enabled"
"pretest"| \ set -x
"install"| \ debug=1
"posttest"| \ ;;
"postinst"| \ -v|--verbose)
"copy_logs"| \ verbose=$((verbose + 1))
"setperms") ;;
sit_action=$1
;; sitinfo| \
"-*h"|"--help"|"help"|"usage") all| \
usage $@ unpack| \
exit 0 prepare| \
;; configure| \
*) build| \
sit_classfile=$1 pretest| \
;; install| \
posttest| \
postinst| \
copy_logs| \
setperms)
sit_action=$1
;;
*)
sit_classfile=$1
;;
esac esac
shift shift
done done