Improve command line parsing adding --debug option to enable bash debug mode.
This commit is contained in:
parent
e4e02bbd21
commit
7819d971c2
1 changed files with 43 additions and 32 deletions
63
sit
63
sit
|
@ -5,17 +5,18 @@
|
|||
# Copyright (c) 2011-2016 Christoph Niethammer <niethammer@hlrs.de>
|
||||
#
|
||||
|
||||
# exit on any error!
|
||||
set -e
|
||||
# for debugging:
|
||||
# set -x
|
||||
|
||||
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)
|
||||
show_help
|
||||
exit
|
||||
;;
|
||||
"-*h"|"--help"|"help"|"usage")
|
||||
usage $@
|
||||
exit 0
|
||||
--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
|
||||
|
||||
|
|
Loading…
Reference in a new issue