lightning-runner/

55 lines
1.1 KiB
Plaintext
Raw Normal View History

2021-12-21 02:42:18 +00:00
#!/usr/bin/env bash
main() {
redefine-functions-defined-with-selector-16
if [[ $(type -t "⚡$1") == "function" ]]; then
⚡$1
2021-12-21 02:44:51 +00:00
else
⚡help
2021-12-21 02:44:51 +00:00
fi
}
redefine-functions-defined-with-selector-16() {
for function in $(compgen -c $(printf "⚡\uFE0F")); do
original_definition="$(typeset -f $function)"
eval "${original_definition//$(printf "⚡\uFE0F")/⚡}"
unset $function
done
}
⚡help() {
2021-12-21 02:44:51 +00:00
_help-line "Show this list" "$@"
echo Usage: "$0" SUBCOMMAND
echo
echo "Available subcommands:"
for subcommand in $(_subcommands); do
if [[ $(type ⚡$subcommand) =~ _help-line ]]; then
printf "\t%-20s - %s\n" "$subcommand" "$(⚡$subcommand help-line)"
2021-12-21 02:44:51 +00:00
else
2021-12-21 04:51:18 +00:00
printf "\t%-20s\n" $subcommand
2021-12-21 02:44:51 +00:00
fi
done
}
_subcommands() {
compgen -c ⚡ | cut -c2-
2021-12-21 02:44:51 +00:00
}
_help-line() {
if [[ "$#" == 2 && "$2" == "help-line" ]]; then
echo "$1" && exit 0
fi
2021-12-21 02:42:18 +00:00
}
2021-12-21 04:51:18 +00:00
_good-message() {
echo -e "\e[32m$@\e[0m"
}
_bad-message() {
echo -e "\e[31m$@\e[0m"
}
2021-12-21 05:10:46 +00:00
[[ $(type -t _verify-prerequisites) == "function" ]] && ! _verify-prerequisites && exit 1
2021-12-21 02:42:18 +00:00
main "$@"