sequencer - output only step help with -h and use less if output is longer than one line

This commit is contained in:
2022-12-10 23:12:07 +01:00
parent 960af0bbf1
commit f844160d02

View File

@@ -1030,10 +1030,10 @@ createTemplate() {
exe cp "${sqr_origin}/${seq_template}" "${seq_template}" exe cp "${sqr_origin}/${seq_template}" "${seq_template}"
} }
# displayHelp [NO TEMPLATE] [STEP NUMBER OR ALIAS] # displayHelp [OPTIONS] [STEP NUMBER OR ALIAS]
# [NO TEMPLATE] # [OPTIONS]
# 0 (default) : Ask for template creation # -t : Ask for template creation
# 1 : Do not ask for template creation # -s : Display only step help
# [STEP NUMBER OR ALIAS] # [STEP NUMBER OR ALIAS]
# [NO TEMPLATE] must be set # [NO TEMPLATE] must be set
# Display step info function only for given step # Display step info function only for given step
@@ -1044,45 +1044,52 @@ displayHelp() {
sqr::debugPause sqr::debugPause
local i local i
local answer local answer
local arg
local fullHelp=1
local clusterSize=0 local clusterSize=0
local lastClusterSize=0 local lastClusterSize=0
local createTemplate=1 local createTemplate=0
local stepFound=0 local stepFound=0
local loopStart=0 local loopStart=0
local loopEnd="${_sqr_stepMax}" local loopEnd="${_sqr_stepMax}"
_sqr_contextHelp=1 _sqr_contextHelp=1
# check if help is requested for a single step while getopts "st" arg; do
if [ -n "${2:-}" ]; then case "${arg}" in
parseAlias s) fullHelp=0 ;;
loopStart="$(checkStep "$2")" t) createTemplate=1 ;;
fi *) ;;
esac
if [[ "$loopStart" == "0" ]] ; then done
helpSequencer shift "$((OPTIND-1))"; OPTIND=1
loopStart=1
else
# Output loop only for one step
loopEnd=$loopStart
fi
if [ -n "${1:-}" ] && [[ ${1:-} -eq 1 ]] ; then
createTemplate=0
fi
# check if step definition exists by looking for a step_*() function # check if step definition exists by looking for a step_*() function
for ((i=1; i<=_sqr_stepMax; i++)); do for ((i=1; i<=_sqr_stepMax; i++)); do
if ! exists -f "step_${i}" ; then if ! exists -f "step_${i}" ; then
continue continue
fi fi
stepFound=$i stepFound=${i}
break break
done done
if [[ "$stepFound" -eq 0 ]] ; then # check if help is requested for a single step
if [ -n "${1:-}" ]; then
parseAlias
loopStart="$(checkStep "${1}")"
fi
if (( ! loopStart )) ; then
(( fullHelp )) || (( ! stepFound )) && helpSequencer
loopStart=1
else
# Output loop only for one step
loopEnd=${loopStart}
fi
if (( ! stepFound )) ; then
printf '\n %s\n' "It seems ${0##*/} was called directly." printf '\n %s\n' "It seems ${0##*/} was called directly."
printf ' %s\n\n' "Please create a sequence script first." printf ' %s\n\n' "Please create a sequence script first."
if [ $createTemplate -ne 0 ] ; then if (( createTemplate )) ; then
if confirm " Create a template now?" ; then if confirm " Create a template now?" ; then
if createTemplate ; then if createTemplate ; then
printf '\n %s\n' "${seq_template} created." printf '\n %s\n' "${seq_template} created."
@@ -1100,7 +1107,7 @@ displayHelp() {
# Display step reference in help if step function exists # Display step reference in help if step function exists
if ! exists -f "step_${i}" ; then if ! exists -f "step_${i}" ; then
if [ $clusterSize -ne 0 ] ; then if (( clusterSize )) ; then
# Mark the end of a cluster # Mark the end of a cluster
lastClusterSize=$clusterSize lastClusterSize=$clusterSize
clusterSize=0 clusterSize=0
@@ -1108,7 +1115,7 @@ displayHelp() {
continue continue
fi fi
(( clusterSize+=1 )) (( clusterSize+=1 ))
if [ $lastClusterSize -gt 1 ] ; then if [[ $lastClusterSize -gt 1 ]] ; then
# Add separation at the end of a cluster # Add separation at the end of a cluster
lastClusterSize=0 lastClusterSize=0
echo echo
@@ -1530,7 +1537,10 @@ sqr::main() {
sqr_args+=" $1" sqr_args+=" $1"
_sqr_dry=1 _sqr_dry=1
shift ;; shift ;;
--help|-h) # show only help --help) # show only full help
local _sqr_optHelp=2
shift ;;
-h) # show only step help
local _sqr_optHelp=1 local _sqr_optHelp=1
shift ;; shift ;;
--helpapi|-ha) #show build-in functions --helpapi|-ha) #show build-in functions
@@ -1577,7 +1587,15 @@ sqr::main() {
esac esac
done done
((${_sqr_optHelp:-})) && displayHelp 1 "${1:-}" && exit 0 if (( ${_sqr_optHelp:-} )) ; then
if [[ ${_sqr_optHelp} == 2 ]] ; then
_sqr_optHelp=""
else
_sqr_optHelp="-s"
fi
displayHelp ${_sqr_optHelp:-} "${1:-}" | less -FREX
exit 0
fi
(( ${_sqr_optHelpapi:-} )) && helpApi | less -R && exit 0 (( ${_sqr_optHelpapi:-} )) && helpApi | less -R && exit 0
# debug mode # debug mode
@@ -1594,7 +1612,7 @@ sqr::main() {
if [ -z "${1:-}" ] && (( ! quickStartOne )) ; then if [ -z "${1:-}" ] && (( ! quickStartOne )) ; then
if ! quiet && [[ ${LOG_LEVEL} -ge $log_info ]] ; then if ! quiet && [[ ${LOG_LEVEL} -ge $log_info ]] ; then
# Empty -> show help # Empty -> show help
displayHelp displayHelp -st
fi fi
# Assume starting at one for interactive mode # Assume starting at one for interactive mode
toStart=( "1" ) toStart=( "1" )