Adding --liststeps and --version

This commit is contained in:
2022-05-11 15:14:19 +02:00
parent b758adc513
commit ea6e85a020

View File

@@ -14,6 +14,11 @@ set -o pipefail
## Globals
{
readonly _sqr_version=16
readonly _sqr_versionMajor=0
readonly _sqr_versionMinor=0
readonly _sqr_versionString="${_sqr_version}.${_sqr_versionMajor}.${_sqr_versionMinor}"
## Seq
readonly seq_name="${_sqn_alias:-${0##*/}}"
readonly seq_dir="$(cd -- "$(dirname -- "${0}")" && pwd)"
@@ -34,6 +39,7 @@ set -o pipefail
readonly sqr_origin="$(cd -- "$(dirname -- \
"$(readlink -f -- "${BASH_SOURCE[0]}")")" && pwd)"
_sqr_stepMax=512
_sqr_interactive=1
_sqr_debug=0
_sqr_dry=0
@@ -210,6 +216,11 @@ set -o pipefail
# trap 'sqr::error_report "${FUNCNAME:-.}" ${LINENO}' ERR
}
# check if there is another PID other than this one
running() {
pidof -o %PPID -x "${0##*/}">>/dev/null
}
# exists [-f] [--] [ELEMENT]
# [ELEMENT]
# : either a variable name or
@@ -227,12 +238,12 @@ exists() {
func="${2:-}"
esac
done
sqr::debugContinue
if [[ -n "${func}" ]] ; then
declare -F "${func}" &>>/dev/null
else
[[ -n "${!1:-}" ]]
fi
sqr::debugContinue
}
# interactive
@@ -351,6 +362,42 @@ ask() {
fi
}
# listSteps [FILTER STRING]
# [FILTER STRING]
# show only steps and aliases starting with [FILTER STRING]
listSteps() {
local aList=()
local aSearch="${1:-}"
local locAlias=
for ((i=1; i<=${_sqr_stepMax}; i++)); do
# Display step reference in help if step function exists
exists -f step_${i} || continue
# Display alias if exists
if exists -f step_${i}_alias ; then
step_${i}_alias
locAlias=("$ALIAS")
else
locAlias=("$i")
fi
if [ -z "$aSearch" ]; then
aList+=("$locAlias")
elif [[ "$locAlias" =~ ^$aSearch ]]; then
aList+=("$locAlias")
fi
done
[ ${#aList[@]} -ne 0 ] && printf '%s\n' "${aList[@]}"
}
# showVersion
showVersion() {
printf 'Sequencer %s\n' "${_sqr_versionString}"
printf 'Seq Revision %s\n' "${VERSION_SEQREV:-"-"}"
}
# exe <COMMAND>
# Handle dry run and verbose output for commands without pipe and/or redirects
exe() {
@@ -388,6 +435,10 @@ sqr::main() {
--dry-run|-d)
_sqr_dry=1
shift ;;
--liststeps|-ls)
shift
listSteps "${1:-}"
exit 0;;
--quiet|-q)
_sqr_interactive=0
shift ;;
@@ -398,6 +449,9 @@ sqr::main() {
--verbose|-v)
_sqr_verbose=1
shift ;;
--version) # version request
showVersion
exit 0;;
esac
done
@@ -410,7 +464,6 @@ sqr::main() {
fi
sqr::print 'Running...\n'
confirm -y 'Continue?'
seq_config 2>/dev/null || true
step_1 "$@"
}