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