Rework step options handling
This commit is contained in:
46
sequencer.sh
46
sequencer.sh
@@ -77,12 +77,6 @@ set -o pipefail
|
||||
readonly _sqr_term
|
||||
_sqr_colorAlways=0
|
||||
|
||||
## Terminal position
|
||||
_sqr_savePosAlias= ;[ -t 1 ] && _sqr_savePosAlias='\033[1A\033[1C\033[s\033[1B\033[1C'
|
||||
_sqr_savePosExe= ;[ -t 1 ] && _sqr_savePosExe='\033[s'
|
||||
_sqr_savePos= ;[ -t 1 ] && _sqr_savePos='\033[3D\033[s\033[3C'
|
||||
_sqr_restorePos= ;[ -t 1 ] && _sqr_restorePos='\033[u'
|
||||
|
||||
## Terminal colors
|
||||
col_black='\033[0;30m'
|
||||
col_darkgrey='\033[1;30m'
|
||||
@@ -157,7 +151,7 @@ sequencer.sh API
|
||||
|
||||
The sequencer.sh build-in functions are available in all sequence functions:
|
||||
- seq_config
|
||||
If optional step_config is defined in the sequence, it will be called once before execution of steps.
|
||||
If optional seq_config is defined in the sequence, it will be called once before execution of steps.
|
||||
- step_[1-${_sqr_stepMax}]_info
|
||||
- step_[1-${_sqr_stepMax}]_alias
|
||||
- step_[1-${_sqr_stepMax}]
|
||||
@@ -526,17 +520,6 @@ USAGE_API
|
||||
printf '%s' "$_sqr_indentExe"; echo "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
# Echo info about step arguments
|
||||
# Needs to be called first in _info() function
|
||||
echoinfoArgs() {
|
||||
echo -e "${_sqr_restorePos}$*"
|
||||
if [ $_sqr_contextExe -ne 0 ]; then
|
||||
printf '%s' "$_sqr_indentExe"
|
||||
else
|
||||
printf '%s' "$_sqr_indentHelp"
|
||||
fi
|
||||
}
|
||||
}
|
||||
|
||||
## Traps
|
||||
@@ -955,7 +938,7 @@ step() {
|
||||
# Parse alias functions "step_[STEP NUBER]_alias" to create
|
||||
# back reference variable of schema:
|
||||
# alias_[ALIAS]=[STEP NUMBER]
|
||||
parseAlias() {
|
||||
sqr::parseAlias() {
|
||||
sqr::debugPause
|
||||
local i
|
||||
for ((i=1; i<=_sqr_stepMax; i++)); do
|
||||
@@ -969,12 +952,17 @@ parseAlias() {
|
||||
}
|
||||
|
||||
# Creating a minimal seq (step definition) template
|
||||
createTemplate() {
|
||||
sqr::createTemplate() {
|
||||
[ -f "${seq_template}" ] && return 1
|
||||
|
||||
exe cp "${sqr_origin}/${seq_template}" "${seq_template}"
|
||||
}
|
||||
|
||||
# sqr::stepOptions <STEP NUMBER> [PREFIX]
|
||||
sqr::stepOptions() {
|
||||
exists -f "step_${1:?}_options" && echo -n "${2:-}$(step_${1:?}_options)"
|
||||
}
|
||||
|
||||
# displayHelp [OPTIONS] [STEP NUMBER OR ALIAS]
|
||||
# [OPTIONS]
|
||||
# -t : Ask for template creation
|
||||
@@ -1019,7 +1007,7 @@ displayHelp() {
|
||||
|
||||
# check if help is requested for a single step
|
||||
if [ -n "${1:-}" ]; then
|
||||
parseAlias
|
||||
sqr::parseAlias
|
||||
loopStart="$(checkStep "${1}")"
|
||||
fi
|
||||
|
||||
@@ -1036,7 +1024,7 @@ displayHelp() {
|
||||
printf ' %s\n\n' "Please create a sequence script first."
|
||||
if (( createTemplate )) ; then
|
||||
if confirm " Create a template now?" ; then
|
||||
if createTemplate ; then
|
||||
if sqr::createTemplate ; then
|
||||
printf '\n %s\n' "${seq_template} created."
|
||||
else
|
||||
printf '\n %s\n' "${seq_template} exists...Nothing to do!"
|
||||
@@ -1072,11 +1060,12 @@ 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::stepOptions "${i}" ' ')"
|
||||
# Newline only if step info() exists
|
||||
exists -f "step_${i}_info" && printf '\n%s' "$_sqr_indentHelp"
|
||||
exists -f "step_${i}_info" && printf '\n%s' "${_sqr_indentHelp}"
|
||||
else
|
||||
echo -en " : ${_sqr_savePos}"
|
||||
echo -en " : $(sqr::stepOptions "${i}")"
|
||||
exists -f "step_${i}_options" && printf '\n%s' "${_sqr_indentAppendHelp}"
|
||||
fi
|
||||
|
||||
# Display step help only if info function exists
|
||||
@@ -1302,11 +1291,12 @@ 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::stepOptions "${1}" ' ')"
|
||||
# Only add newline if step info() available
|
||||
exists -f "step_${1}_info" && printf '\n%s' "${_sqr_indentExe}"
|
||||
else
|
||||
echo -en "${_sqr_savePosExe}"
|
||||
echo -en "$(sqr::stepOptions "${1}")"
|
||||
exists -f "step_${1}_options" && printf '\n%s' "${_sqr_indentExe}"
|
||||
fi
|
||||
|
||||
if exists -f "step_${1}_info" ; then
|
||||
@@ -1593,7 +1583,7 @@ sqr::main() {
|
||||
## Fall back to error message
|
||||
[ -z "${_sqr_editor}" ] && _sqr_editor="sqr::noEditor"
|
||||
|
||||
parseAlias
|
||||
sqr::parseAlias
|
||||
|
||||
# run configuration for sequence only if available and if first step is valid
|
||||
if exists -f seq_config ; then
|
||||
|
Reference in New Issue
Block a user