support multiple shell arguments (e.g. -v -q)

new verbose output (-v) to echo commands called with exe() before execution
This commit is contained in:
2019-04-10 11:12:28 +01:00
parent a124608e36
commit 3b23840277
2 changed files with 45 additions and 25 deletions

View File

@@ -13,7 +13,7 @@
step_1_info() { echo "Step $1 header"; } step_1_info() { echo "Step $1 header"; }
step_1_alias() { ALIAS="begin"; } step_1_alias() { ALIAS="begin"; }
step_1() { step_1() {
cat .nofile exe cat '.no f"le'
saveReturn $? saveReturn $?
} }

View File

@@ -13,6 +13,7 @@ VERSION_MINOR=0
## Start of generic script part ## Start of generic script part
QUIET=0 QUIET=0
VERBOSE=0
ERNO=0 ERNO=0
MAX_STEP=255 MAX_STEP=255
ALIAS= ALIAS=
@@ -24,10 +25,12 @@ helpSequencer() {
echo "Usage: ${0##*/} [OPTIONS] [STEP NUMBER(s) or ALIAS]" echo "Usage: ${0##*/} [OPTIONS] [STEP NUMBER(s) or ALIAS]"
echo echo
echo " [OPTIONS]" echo " [OPTIONS]"
echo " --help, -h : Display help" echo " --help, -h : Display help"
echo " --quiet, -q : Don't ask for permission to execute steps" echo " --quiet, -q : Don't ask for permission to execute steps"
echo " If called without starting step number, only this help is shown" echo " If called without starting step number, only this help is shown"
echo " --version,-v : Display version of sequencer and revision of sequence" echo " --verbose, -v : Verbose output (use exe() function to call shell commands in seqs)"
echo " ( e.g.: exe apt update )"
echo " --version : Display version of sequencer and revision of sequence"
echo echo
echo " [STEP NUMBER(s) 1-${MAX_STEP} or ALIAS]" echo " [STEP NUMBER(s) 1-${MAX_STEP} or ALIAS]"
echo " Single STEP or ALIAS : starting point of process" echo " Single STEP or ALIAS : starting point of process"
@@ -331,29 +334,46 @@ showVersion() {
fi fi
} }
exe() {
arr=("$@")
if [ $VERBOSE -eq 1 ] ; then
(set -x; "${arr[@]}")
else
"${arr[@]}"
fi
}
main() { main() {
local START=0 local START=0
# option check # options check
case "$1" in for arg in "$@" ; do
--help|-h) # show only help case "$arg" in
displayHelp --help|-h) # show only help
exit 0; displayHelp
;; exit 0;
--quiet|-q) # detect if option quiet is available ;;
QUIET=1 --quiet|-q) # detect if option quiet is available
shift QUIET=1
;; shift
--version|-v) # version request ;;
showVersion --verbose|-v) # set verbose flag
exit 0; VERBOSE=1
;; shift
"") # Empty -> show help ;;
displayHelp --version) # version request
# Assume starting at one for interactive mode showVersion
START=1 exit 0;
;; ;;
esac esac
done
if [ -z $1 ] || [ "$1" == "" ] ; then
# Empty -> show help
displayHelp
# Assume starting at one for interactive mode
START=1
fi
# compatibility check of sequence # compatibility check of sequence
if [ ! -z $VERSION_SEQREV ] && [ $VERSION_SEQREV -gt $VERSION_REV ] ; then if [ ! -z $VERSION_SEQREV ] && [ $VERSION_SEQREV -gt $VERSION_REV ] ; then