sequencer - fix uncought error in new col_off function
sequencer - add debug and dry-run to sqr_args
This commit is contained in:
110
sequencer.sh
110
sequencer.sh
@@ -84,24 +84,30 @@ set -o pipefail
|
||||
_sqr_restorePos= ;[ -t 1 ] && _sqr_restorePos='\033[u'
|
||||
|
||||
## Terminal colors
|
||||
col_black() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[0;30m';}
|
||||
col_darkgrey() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[1;30m';}
|
||||
col_red() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[0;31m';}
|
||||
col_lightred() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[1;31m';}
|
||||
col_green() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[0;32m';}
|
||||
col_lightgreen() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[1;32m';}
|
||||
col_orange() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[0;33m';}
|
||||
col_yellow() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[1;33m';}
|
||||
col_blue() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[0;34m';}
|
||||
col_lightblue() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[1;34m';}
|
||||
col_purple() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[0;35m';}
|
||||
col_lightpurple() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[1;35m';}
|
||||
col_cyan() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[0;36m';}
|
||||
col_lightcyan() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[1;36m';}
|
||||
col_lightgray() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[0;37m';}
|
||||
col_white() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[1;37m';}
|
||||
col_black='\033[0;30m'
|
||||
col_darkgrey='\033[1;30m'
|
||||
col_red='\033[0;31m'
|
||||
col_lightred='\033[1;31m'
|
||||
col_green='\033[0;32m'
|
||||
col_lightgreen='\033[1;32m'
|
||||
col_orange='\033[0;33m'
|
||||
col_yellow='\033[1;33m'
|
||||
col_blue='\033[0;34m'
|
||||
col_lightblue='\033[1;34m'
|
||||
col_purple='\033[0;35m'
|
||||
col_lightpurple='\033[1;35m'
|
||||
col_cyan='\033[0;36m'
|
||||
col_lightcyan='\033[1;36m'
|
||||
col_lightgray='\033[0;37m'
|
||||
col_white='\033[1;37m'
|
||||
## No Color
|
||||
col_off() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[0m';}
|
||||
col_off='\033[0m'
|
||||
|
||||
col() {
|
||||
local colVar="col_${1:-"off"}"
|
||||
((_sqr_term)) || ((_sqr_colorAlways)) && echo "${!colVar}"
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
helpSequencer() {
|
||||
@@ -175,19 +181,19 @@ sequencer.sh global variables:
|
||||
|
||||
sequencer.sh build-in functions:
|
||||
USAGE_API
|
||||
echo -e "$(col_green) root$(col_off)"
|
||||
echo -e "$(col green) root$(col off)"
|
||||
cat <<USAGE_API
|
||||
Returns true if current user is root.
|
||||
e.g. root || echo "Not root"
|
||||
|
||||
USAGE_API
|
||||
echo -e "$(col_green) running$(col_off)"
|
||||
echo -e "$(col green) running$(col off)"
|
||||
cat <<USAGE_API
|
||||
Returns true if same script already runs.
|
||||
e.g. running && exit 1
|
||||
|
||||
USAGE_API
|
||||
echo -e "$(col_green) exists [OPTIONS] [ELEMENT]$(col_off)"
|
||||
echo -e "$(col green) exists [OPTIONS] [ELEMENT]$(col off)"
|
||||
cat <<USAGE_API
|
||||
[ELEMENT]
|
||||
: either a variable- or a funtion name (-f)
|
||||
@@ -195,37 +201,37 @@ USAGE_API
|
||||
-f : a function
|
||||
-- : end of options
|
||||
USAGE_API
|
||||
echo -e "$(col_green) quiet$(col_off)"
|
||||
echo -e "$(col green) quiet$(col off)"
|
||||
cat <<USAGE_API
|
||||
Returns true if seq runs non-interactive (-q|-qq).
|
||||
|
||||
USAGE_API
|
||||
echo -e "$(col_green) silent$(col_off)"
|
||||
echo -e "$(col green) silent$(col off)"
|
||||
cat <<USAGE_API
|
||||
Returns true if seq runs interactive.
|
||||
|
||||
USAGE_API
|
||||
echo -e "$(col_green) dry$(col_off)"
|
||||
echo -e "$(col green) dry$(col off)"
|
||||
cat <<USAGE_API
|
||||
Returns true if seq runs in dry-run mode (-d)
|
||||
|
||||
USAGE_API
|
||||
echo -e "$(col_green) verbose$(col_off)"
|
||||
echo -e "$(col green) verbose$(col off)"
|
||||
cat <<USAGE_API
|
||||
Returns true if seq runs in verbose mode (-v)
|
||||
|
||||
USAGE_API
|
||||
echo -e "$(col_green) contextHelp$(col_off)"
|
||||
echo -e "$(col green) contextHelp$(col off)"
|
||||
cat <<USAGE_API
|
||||
Returns true if current output is only for help purposes.
|
||||
|
||||
USAGE_API
|
||||
echo -e "$(col_green) contextExe$(col_off)"
|
||||
echo -e "$(col green) contextExe$(col off)"
|
||||
cat <<USAGE_API
|
||||
Returns true if current output is in execution mode.
|
||||
|
||||
USAGE_API
|
||||
echo -e "$(col_green) confirm [OPTIONS] [QUESTION]$(col_off)"
|
||||
echo -e "$(col green) confirm [OPTIONS] [QUESTION]$(col off)"
|
||||
cat <<USAGE_API
|
||||
Default (empty character) = no
|
||||
Invalid character trigger the default
|
||||
@@ -236,7 +242,7 @@ USAGE_API
|
||||
-- : end of options
|
||||
|
||||
USAGE_API
|
||||
echo -e "$(col_green) ask [OPTION] [QUESTION] [DEFAULT]$(col_off)"
|
||||
echo -e "$(col green) ask [OPTION] [QUESTION] [DEFAULT]$(col off)"
|
||||
cat <<USAGE_API
|
||||
Will ask for input even if quiet, when [DEFAULT] is empty
|
||||
[OPTION]
|
||||
@@ -248,14 +254,14 @@ USAGE_API
|
||||
-- : End of options
|
||||
|
||||
USAGE_API
|
||||
echo -e "$(col_green) exe [COMMANDLINE]$(col_off)"
|
||||
echo -e "$(col green) exe [COMMANDLINE]$(col off)"
|
||||
cat <<USAGE_API
|
||||
Execute command line without pipes or redirects (>,<,|).
|
||||
Supporting: dry-run (-d): only print command without execution
|
||||
verbose (-v): print command before execution
|
||||
|
||||
USAGE_API
|
||||
echo -e "$(col_green) exep \"[COMMAND STRING(s)]\"$(col_off)"
|
||||
echo -e "$(col green) exep \"[COMMAND STRING(s)]\"$(col off)"
|
||||
cat <<USAGE_API
|
||||
See exe, but support for pipes or redirects.
|
||||
e.g.: exep echo hello world \\> \\'out put.log\\'
|
||||
@@ -267,13 +273,13 @@ USAGE_API
|
||||
- All apostrophes need to be esacped since the command line is given as string.
|
||||
|
||||
USAGE_API
|
||||
echo -e "$(col_green) escpath <PATH>$(col_off)"
|
||||
echo -e "$(col green) escpath <PATH>$(col off)"
|
||||
cat <<USAGE_API
|
||||
Escaping non-printable characters with the proposed POSIX $'' syntax
|
||||
e.g. \$(escpath /my own/ho me/path) = $(escpath /my own/ho me/path)
|
||||
|
||||
USAGE_API
|
||||
echo -e "$(col_green) initSeqConfig [OPTION] <NAME> [TEMPLATE]$(col_off)"
|
||||
echo -e "$(col green) initSeqConfig [OPTION] <NAME> [TEMPLATE]$(col off)"
|
||||
cat <<USAGE_API
|
||||
Create a configuration file in ${seq_configRoot}/ and source it if already existent.
|
||||
[OPTION]
|
||||
@@ -288,7 +294,7 @@ USAGE_API
|
||||
3 : No configuration created
|
||||
|
||||
USAGE_API
|
||||
echo -e "$(col_green) addConf <OPTIONS> [SOURCE TYPE] <SOURCE> <DESTINATION FILE>$(col_off)"
|
||||
echo -e "$(col green) addConf <OPTIONS> [SOURCE TYPE] <SOURCE> <DESTINATION FILE>$(col off)"
|
||||
cat <<USAGE_API
|
||||
Trying to write or append text or a file (<SOURCE>) to a destination file.
|
||||
If the CONFIGFILE exists, a backup (name_%Y%m%d-%H%M%S.bck) is saved at the same location.
|
||||
@@ -307,13 +313,13 @@ USAGE_API
|
||||
Target file to be created or modified.
|
||||
|
||||
USAGE_API
|
||||
echo -e "$(col_green) step <STEP NUMBER OR ALIAS>$(col_off)"
|
||||
echo -e "$(col green) step <STEP NUMBER OR ALIAS>$(col off)"
|
||||
cat <<USAGE_API
|
||||
Executes a single step also by alias. Useful if step numbers get reorganized.
|
||||
dry-run is not applied in this function! The executed step is responsible.
|
||||
|
||||
USAGE_API
|
||||
echo -e "$(col_green) color [FOREGROUND COLOR] [BACKGROUND COLOR]$(col_off)"
|
||||
echo -e "$(col green) color [FOREGROUND COLOR] [BACKGROUND COLOR]$(col off)"
|
||||
cat <<USAGE_API
|
||||
Set output color permanently until reset.
|
||||
No argument or unknown foreground color restores shell default (reset).
|
||||
@@ -321,7 +327,7 @@ USAGE_API
|
||||
[COLOR]: black, red, green, yellow, blue, magenta, cyan, white
|
||||
|
||||
USAGE_API
|
||||
echo -e "$(col_green) info|warning|error|debug [OPTIONS] [STRING]$(col_off)"
|
||||
echo -e "$(col green) info|warning|error|debug [OPTIONS] [STRING]$(col off)"
|
||||
cat <<USAGE_API
|
||||
Output [STRING] (can be multiline) to stdout according to log level.
|
||||
[OPTIONS]
|
||||
@@ -331,13 +337,13 @@ USAGE_API
|
||||
-n : No newline
|
||||
|
||||
USAGE_API
|
||||
echo -e "$(col_green) echoinfo [...]$(col_off)"
|
||||
echo -e "$(col green) echoinfo [...]$(col off)"
|
||||
cat <<USAGE_API
|
||||
echo additional correctly indented line to step info
|
||||
[...] : all parameter are forwared to echo
|
||||
|
||||
USAGE_API
|
||||
echo -e "$(col_green) echoinfoArgs [...]$(col_off)"
|
||||
echo -e "$(col green) echoinfoArgs [...]$(col off)"
|
||||
cat <<USAGE_API
|
||||
echo argument description after step number or alias.
|
||||
This must be called first in the step info function.
|
||||
@@ -345,24 +351,24 @@ USAGE_API
|
||||
[...] : no parameter are forwared to echo
|
||||
|
||||
USAGE_API
|
||||
echo -e "$(col_green) endIfEmpty <VARIABLENAME> [DESCRIPTION]$(col_off)"
|
||||
echo -e "$(col green) endIfEmpty <VARIABLENAME> [DESCRIPTION]$(col off)"
|
||||
cat <<USAGE_API
|
||||
exit 6 if variable is empty
|
||||
<VARIABLENAME> : Name without \$
|
||||
[DESCRIPTION] : Additional text for error output
|
||||
|
||||
USAGE_API
|
||||
echo -e "$(col_green) saveReturn [ERRORCODE]$(col_off)"
|
||||
echo -e "$(col green) saveReturn [ERRORCODE]$(col off)"
|
||||
cat <<USAGE_API
|
||||
Save ERRORCODE if it is != 0 for later use with endReturn
|
||||
|
||||
USAGE_API
|
||||
echo -e "$(col_green) getReturn$(col_off)"
|
||||
echo -e "$(col green) getReturn$(col off)"
|
||||
cat <<USAGE_API
|
||||
Return last saved error code
|
||||
|
||||
USAGE_API
|
||||
echo -e "$(col_green) endReturn [OPTIONS] [MESSAGE]$(col_off)"
|
||||
echo -e "$(col green) endReturn [OPTIONS] [MESSAGE]$(col off)"
|
||||
cat <<USAGE_API
|
||||
Notifys user that there was an error (previously saved by saveReturn,
|
||||
or -o [ERRORCODE]) and asks to continue or end the sequence.
|
||||
@@ -399,12 +405,12 @@ USAGE_API
|
||||
# -- : End of options
|
||||
#
|
||||
sqr::log () {
|
||||
sqr::debugPause
|
||||
#sqr::debugPause
|
||||
local appendText=
|
||||
local direct=0 # no prefix and timestamp
|
||||
local newline='\n'
|
||||
local col_end=
|
||||
col_end="$(col_off)"
|
||||
col_end="$(col off)"
|
||||
local outp='/dev/stdout'
|
||||
|
||||
local log_level="${1:-}"
|
||||
@@ -462,12 +468,12 @@ USAGE_API
|
||||
sqr::debugContinue
|
||||
}
|
||||
|
||||
fatal () { sqr::log "stop" "$(col_red)" "${@}"; exit 1; }
|
||||
fatal () { sqr::log "stop" "$(col red)" "${@}"; exit 1; }
|
||||
die () { sqr::log "end" "" "${@}"; exit 1; }
|
||||
error () { [[ "${LOG_LEVEL:-0}" -ge ${log_error} ]] && sqr::log "e" "$(col_red)" "${@}"; true; }
|
||||
warning () { [[ "${LOG_LEVEL:-0}" -ge ${log_warning} ]] && sqr::log "w" "$(col_orange)" "${@}"; true; }
|
||||
error () { [[ "${LOG_LEVEL:-0}" -ge ${log_error} ]] && sqr::log "e" "$(col red)" "${@}"; true; }
|
||||
warning () { [[ "${LOG_LEVEL:-0}" -ge ${log_warning} ]] && sqr::log "w" "$(col orange)" "${@}"; true; }
|
||||
info () { [[ "${LOG_LEVEL:-0}" -ge ${log_info} ]] && sqr::log "i" "" "${@}"; true; }
|
||||
debug () { [[ "${LOG_LEVEL:-0}" -ge ${log_debug} ]] && sqr::log "dbug" "$(col_lightpurple)" "${@}"; true; }
|
||||
debug () { [[ "${LOG_LEVEL:-0}" -ge ${log_debug} ]] && sqr::log "dbug" "$(col lightpurple)" "${@}"; true; }
|
||||
|
||||
# internal print(s) same loglevel as error
|
||||
# shellcheck disable=SC2059 # don't use variables in format
|
||||
@@ -636,7 +642,7 @@ contextExe() {
|
||||
# editor [FILE(s)..]
|
||||
# Starts the detected system text editor
|
||||
editor() {
|
||||
"${_sqr_editor}" "$@"
|
||||
exe "${_sqr_editor}" "$@"
|
||||
}
|
||||
|
||||
### interactive
|
||||
@@ -1114,7 +1120,7 @@ displayHelp() {
|
||||
|
||||
# Display alias if exists
|
||||
if exists -f "step_${i}_alias" ; then
|
||||
echo -en " = $(col_orange)$("step_${i}_alias")$(col_off)${_sqr_savePosAlias}"
|
||||
echo -en " = $(col orange)$("step_${i}_alias")$(col off)${_sqr_savePosAlias}"
|
||||
# Newline only if step info() exists
|
||||
exists -f "step_${i}_info" && printf '\n%s' "$_sqr_indentHelp"
|
||||
else
|
||||
@@ -1347,7 +1353,7 @@ execute() {
|
||||
exists -f "step_${1}_alias" && stepAlias=$("step_${1}_alias")
|
||||
printf '\n [%3d] ' "${1}"
|
||||
if [ -n "${stepAlias}" ]; then
|
||||
echo -en "$(col_orange)${stepAlias}$(col_off)${_sqr_savePosAlias}"
|
||||
echo -en "$(col orange)${stepAlias}$(col off)${_sqr_savePosAlias}"
|
||||
# Only add newline if step info() available
|
||||
exists -f "step_${1}_info" && printf '\n%s' "${_sqr_indentExe}"
|
||||
else
|
||||
@@ -1517,9 +1523,11 @@ sqr::main() {
|
||||
_sqr_colorAlways=1
|
||||
shift ;;
|
||||
--debug)
|
||||
sqr_args+=" $1"
|
||||
_sqr_debug="1"
|
||||
shift ;;
|
||||
--dry-run|-d)
|
||||
sqr_args+=" $1"
|
||||
_sqr_dry=1
|
||||
shift ;;
|
||||
--help|-h) # show only help
|
||||
|
Reference in New Issue
Block a user