New function step to execute other steps also by alias

Possibilty to skip a step, if run without quiet option

WIP build-in function documentation
This commit is contained in:
2019-12-08 21:38:42 +00:00
parent 4feb26103b
commit 3d1097bb5d

View File

@@ -6,7 +6,7 @@
## Version information
VERSION_REV=6
VERSION_REV=7
VERSION_MAJOR=0
VERSION_MINOR=0
@@ -30,6 +30,8 @@ helpSequencer() {
echo " --dry-run, -d : Only print to console what would be done"
echo " ! Attention - Sequence must support this"
echo " --help, -h : Display help"
echo " --helpapi, -ha : Display help about build-in supporting functions"
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 " --verbose, -v : Verbose output (use exe() function to call shell commands in seqs)"
@@ -49,10 +51,36 @@ helpSequencer() {
echo " \$1 is always the step number"
}
helpApi() {
echo "sequencer.sh build-in functions"
echo
echo " echoerr <...>"
echo " echo output to stderr"
echo " <...> - all parameter are forwarded to echo"
echo
echo " endCheckEmpty <Variable Name> [Description]"
echo " exit 666 if variable is empty"
echo " <Variable Name> - Name used within eval"
echo " [Description] - Additional text for error output"
echo
echo " saveReturn [Error Code]"
echo " Save error code if it is != 0 for later use with endReturn"
echo
echo " endReturn [-f] [Message]"
echo " Notifys user that there was an error (previously saved by saveReturn)"
echo " and asks to continue or end sequence. Always exits with saved error code."
echo " -f : force exit with the last saved error code without user input"
echo
echo " step <Step number or alias>"
echo " Executes a single step also by alias. Useful if step numbers get reorganized."
echo " dry-run is not applied in this function! The executed step is responsible."
echo
}
# Echo to stderr
echoerr() { >&2 echo "$@"; }
# endCheckEmpty [VariableName] [DESCRIPTION]
# endCheckEmpty <VariableName> [DESCRIPTION]
# DESCRIPTION : Optional text for error
endCheckEmpty() {
local errorText=$1
@@ -260,11 +288,14 @@ execute() {
echo
fi
if [ $QUIET -ne 1 ] ; then
read -p "Start: y/[n]? " answer
read -p "Start: (y)es/[n]o/(s)kip? " answer
case $answer in
[yY])
step_$1 $1 $STEP_ARGS
;;
[sS]) # skip step
return 0
;;
*)
echo " [I] Stopping sequence at step $1"
exit 1;
@@ -302,6 +333,26 @@ checkStep() {
fi
}
# step <Step Number of Alias>
# execute given step
step() {
local stepNo=0
checkStep "$1"
stepNo=$?
if [ "$stepNo" == "0" ] ; then
return 1
else
existsFunction step_${stepNo}
if [ $? -eq 0 ] ; then
eval 'step_'"$stepNo"
else
echoerr " [E] Invalid step: $stepNo"
return 2
fi
fi
}
# continous <Starting Step Number>
# (max $MAX_STEP)
# execute sequence continously from given starting step
@@ -499,6 +550,10 @@ main() {
displayHelp
exit 0;
;;
--helpapi|-ha) #show build-in functions
helpApi
exit 0;
;;
--quiet|-q) # detect if option quiet is available
QUIET=1
shift