From 2e6984aac8bf37cea3cf31e0e2cbcbd77b8543bb Mon Sep 17 00:00:00 2001 From: Martin Winkler Date: Sun, 5 Jan 2020 15:04:20 +0100 Subject: [PATCH] New option -qq to suppress regular output Usefull when step are called from another seq --- sequencer/sequencer.sh | 54 +++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/sequencer/sequencer.sh b/sequencer/sequencer.sh index 5c3f96e..8ba6bb6 100755 --- a/sequencer/sequencer.sh +++ b/sequencer/sequencer.sh @@ -8,7 +8,7 @@ ## Version information VERSION_REV=9 -VERSION_MAJOR=1 +VERSION_MAJOR=2 VERSION_MINOR=0 ## Start of generic script part @@ -36,6 +36,7 @@ helpSequencer() { echo " (e.g. exe,addconf,echerr,...)" echo " --quiet, -q : Don't ask for permission to execute steps" echo " If called without starting step number, only this help is shown" + echo " -qq : Same as --quiet but suppresses regular sequencer.sh output" echo " --single, -s : Execute only one step" echo " If more than one step is requested, only the first will be executed" echo " --verbose, -v : Verbose output (use exe() function to call shell commands in seqs)" @@ -64,6 +65,16 @@ helpApi() { echo "- step_[1-${MAX_STEP}]_alias" echo "- step_[1-${MAX_STEP}]" echo + echo "sequencer.sh global variables:" + echo + echo " \$QUIET" + echo " 0 : default" + echo " 1 (-q) : No user interaction (e.g. question to start a step)" + echo " 2 (-qq) : 1 and no regular output of sequencer.sh" + echo " \$DRY" + echo " 0 : default" + echo " 1 (-d) : Commands shall only be printed but not executed" + echo echo "sequencer.sh build-in functions:" echo echo " exe [COMMANDLINE]" @@ -376,15 +387,18 @@ execute() { return $NOTFOUND fi - echo -en "\n [STEP $1] " - existsFunction step_${1}_info - if [ $? -eq 0 ] ; then - step_${1}_info $1 "${STEP_ARGS[@]}" - else - # Add newline if no info is given - echo + if [ $QUIET -ne 2 ] ; then + echo -en "\n [STEP $1] " + existsFunction step_${1}_info + if [ $? -eq 0 ] ; then + step_${1}_info $1 "${STEP_ARGS[@]}" + else + # Add newline if no info is given + echo + fi fi - if [ $QUIET -ne 1 ] ; then + + if [ $QUIET -eq 0 ] ; then read -p "Start: (y)es/[n]o/(s)kip? " answer case $answer in [yY]) @@ -469,8 +483,8 @@ continous() { if [[ $step == 0 ]] ; then return 1 fi - - echo " [I] Staring sequence $(realpath $0) ..." + + if [ $QUIET -ne 2 ]; then echo " [I] Starting sequence $(realpath $0) ..."; fi for ((i=$step; i<=${MAX_STEP}; i++)); do execute -q $i @@ -492,7 +506,7 @@ selection() { return 1 fi - echo " [I] Staring sequence $(realpath $0) ..." + if [ $QUIET -ne 2 ]; then echo " [I] Starting sequence $(realpath $0) ..."; fi for i in ${array[@]} ; do checkStep "$i" @@ -685,8 +699,12 @@ main() { helpApi exit 0; ;; - --quiet|-q) # detect if option quiet is available - QUIET=1 + --quiet|-q|-qq) # detect if option quiet is available + if [ "$1" == "-qq" ] ; then + QUIET=2 + else + QUIET=1 + fi shift ;; --single|-s) # execute only one step and stop @@ -733,7 +751,7 @@ main() { fi # End here on quiet mode and no step was given - if [ $EMPTYCALL -ne 0 ] && [ $QUIET -eq 1 ] ; then + if [ $EMPTYCALL -ne 0 ] && [ $QUIET -ne 0 ] ; then exit 1; fi @@ -763,8 +781,10 @@ main() { continous $START fi - echo - echo "${0##*/} finished" + if [ $QUIET -ne 2 ] ; then + echo + echo "${0##*/} finished" + fi } main "$@"