Add possibility to -h to display info only for one specified step

New way to display step arguments by moving the cursor around with escape sequences
This commit is contained in:
2022-01-16 23:37:50 +01:00
parent f30f2ea205
commit 1edef40342

View File

@@ -7,8 +7,8 @@
## Version information ## Version information
VERSION_REV=13 VERSION_REV=14
VERSION_MAJOR=3 VERSION_MAJOR=0
VERSION_MINOR=0 VERSION_MINOR=0
## Start of generic script part ## Start of generic script part
@@ -24,6 +24,7 @@ STEP_RETURN=255
MAX_STEP=512 MAX_STEP=512
ALIAS= ALIAS=
CONTEXT_HELP=0 CONTEXT_HELP=0
CONTEXT_EXE=0
SEQ_CONFIG_EDIT=0 SEQ_CONFIG_EDIT=0
SEQ_CONFIG_NAME=".seqs" SEQ_CONFIG_NAME=".seqs"
SEQ_CONFIG_FILE= SEQ_CONFIG_FILE=
@@ -53,6 +54,10 @@ LIGHTCYAN= ; [ -t 1 ] && LIGHTCYAN='\033[1;36m'
LIGHTGRAY= ; [ -t 1 ] && LIGHTGRAY='\033[0;37m' LIGHTGRAY= ; [ -t 1 ] && LIGHTGRAY='\033[0;37m'
WHITE= ; [ -t 1 ] && WHITE='\033[1;37m' WHITE= ; [ -t 1 ] && WHITE='\033[1;37m'
NC= ;[ -t 1 ] && NC='\033[0m' # No Color NC= ;[ -t 1 ] && NC='\033[0m' # No Color
SAVE_POS_ALIAS= ;[ -t 1 ] && SAVE_POS_ALIAS='\033[1A\033[1C\033[s\033[1B\033[1C'
SAVE_POS_EXE= ;[ -t 1 ] && SAVE_POS_EXE='\033[s'
SAVE_POS= ;[ -t 1 ] && SAVE_POS='\033[3D\033[s\033[3C'
RESTORE_POS= ;[ -t 1 ] && RESTORE_POS='\033[u'
helpSequencer() { helpSequencer() {
cat <<USAGE_EOF cat <<USAGE_EOF
@@ -208,7 +213,14 @@ USAGE_API
echo -e "${GREEN} echoinfo [...]${NC}" echo -e "${GREEN} echoinfo [...]${NC}"
cat <<USAGE_API cat <<USAGE_API
echo additional correctly indented line to step info echo additional correctly indented line to step info
[...] : all parrameter are forwared to echo [...] : all parameter are forwared to echo
USAGE_API
echo -e "${GREEN} echoinfoArgs [...]${NC}"
cat <<USAGE_API
echo argument description after step number or alias.
This must be called first in the step info function.
[...] : no parameter are forwared to echo
USAGE_API USAGE_API
echo -e "${GREEN} endCheckEmpty <VARIABLENAME> [DESCRIPTION]${NC}" echo -e "${GREEN} endCheckEmpty <VARIABLENAME> [DESCRIPTION]${NC}"
@@ -309,12 +321,22 @@ outColor() {
# Echo additional line to info correctly indented # Echo additional line to info correctly indented
INDENT_HELP=' : ' INDENT_HELP=' : '
INDENTAPPEND_HELP=' ' INDENTAPPEND_HELP=' '
INDENTAPPEND_INFO=' '
echoinfo() { echoinfo() {
if [ $CONTEXT_HELP -ne 0 ] ; then if [ $CONTEXT_HELP -ne 0 ] ; then
printf '%s' "$INDENTAPPEND_HELP"; echo "$@" printf '%s' "$INDENTAPPEND_HELP"; echo "$@"
else else
printf '%s' "$INDENTAPPEND_INFO"; echo "$@" echo -ne "${RESTORE_POS}"; echo "$@"
fi
}
# Echo info about step arguments
# Needs to be called first in _info() function
echoinfoArgs() {
echo -e "${RESTORE_POS}$@"
if [ $CONTEXT_EXE -ne 0 ]; then
echo -ne "${RESTORE_POS}"
else
printf '%s' "$INDENT_HELP"
fi fi
} }
@@ -685,10 +707,12 @@ execute() {
fi fi
if [ $QUIET -ne 2 ] ; then if [ $QUIET -ne 2 ] ; then
echo -en "\n [STEP $1] " echo -en "\n [STEP $1] ${SAVE_POS_EXE}"
existsFunction step_${1}_info existsFunction step_${1}_info
if [ $? -eq 0 ] ; then if [ $? -eq 0 ] ; then
CONTEXT_EXE=1
step_${1}_info $1 "${STEP_ARGS[@]}" step_${1}_info $1 "${STEP_ARGS[@]}"
CONTEXT_EXE=0
outColor outColor
else else
# Add newline if no info is given # Add newline if no info is given
@@ -910,11 +934,15 @@ parseAlias() {
done done
} }
# displayHelp [NO TEMPLATE] # displayHelp [NO TEMPLATE] [STEP NUMBER OR ALIAS]
# [NO TEMPLATE] # [NO TEMPLATE]
# 0 (default) : Ask for template creation # 0 (default) : Ask for template creation
# 1 : Do not ask for template creation # 1 : Do not ask for template creation
# - Always display sequencer help and, if available, sequence help # [STEP NUMBER OR ALIAS]
# [NO TEMPLATE] must be set
# Display step info function only for given step
#
# - Display sequencer help and, if available, sequence help
# - Cluster continous (more than 1) steps visually together # - Cluster continous (more than 1) steps visually together
displayHelp() { displayHelp() {
local i local i
@@ -923,8 +951,24 @@ displayHelp() {
local lastClusterSize=0 local lastClusterSize=0
local createTemplate=1 local createTemplate=1
local stepsFound=0 local stepsFound=0
local loopStart=0
local loopEnd=${MAX_STEP}
CONTEXT_HELP=1 CONTEXT_HELP=1
helpSequencer
# check if help is requested for a single step
if [ ! -z "$2" ]; then
parseAlias
checkStep "$2"
loopStart=$?
fi
if [ "$loopStart" == "0" ]; then
helpSequencer
loopStart=1
else
# Output loop only for one step
loopEnd=$loopStart
fi
if [ ! -z $1 ] && [ $1 -eq 1 ] ; then if [ ! -z $1 ] && [ $1 -eq 1 ] ; then
createTemplate=0 createTemplate=0
@@ -961,7 +1005,7 @@ displayHelp() {
exit 1; exit 1;
else else
echo -e "\n Step (= alias) documentation:" echo -e "\n Step (= alias) documentation:"
for ((i=1; i<=${MAX_STEP}; i++)); do for ((i=$loopStart; i<=$loopEnd; i++)); do
# Display step reference in help if step function exists # Display step reference in help if step function exists
existsFunction step_${i} existsFunction step_${i}
@@ -983,10 +1027,10 @@ displayHelp() {
existsFunction step_${i}_alias existsFunction step_${i}_alias
if [ $? -eq 0 ] ; then if [ $? -eq 0 ] ; then
step_${i}_alias step_${i}_alias
echo -e " = ${ORANGE}$ALIAS${NC}" echo -e " = ${ORANGE}$ALIAS${NC}${SAVE_POS_ALIAS}"
printf '%s' "$INDENT_HELP" printf '%s' "$INDENT_HELP"
else else
echo -n " : " echo -en " : ${SAVE_POS}"
fi fi
# Display step help only if info function exists # Display step help only if info function exists
@@ -1095,7 +1139,7 @@ main() {
SEQUENCER_ARGS+=" $1" SEQUENCER_ARGS+=" $1"
shift;; shift;;
--help|-h) # show only help --help|-h) # show only help
displayHelp 1 displayHelp 1 "$2"
exit 0;; exit 0;;
--helpapi|-ha) #show build-in functions --helpapi|-ha) #show build-in functions
helpApi helpApi