bash-util/dynamic_main.bash

19 lines
382 B
Bash
Raw Normal View History

command -v dedcat || \
source "$(dirname ${BASH_SOURCE[0]})/logging.bash"
[ -z "${fns[@]}" ] && dedcat 'ERROR: Empty or undefined ${fns[@]} array!'
read -d '' HELPSTR <<EOH
Usage: $0 OPERATION
$EXTRA_NOTE
Operations:
$(for fn in ${fns[@]}; do echo " $fn: $($fn help)"; done)
EOH
[[ " ${fns[*]} " =~ [[:space:]]${1}[[:space:]] ]] \
|| dedcat "$HELPSTR"
op="$1"
shift
$op $@