gistfile1.txt
· 752 B · Text
Raw
function wgctl::dispatch() {
local raw_cmd="${1:-help}"
shift || true
local cmd
cmd="$(wgctl::resolve_alias "$raw_cmd")"
case "$cmd" in
help) wgctl::help; return ;;
shell) : ;;
*) config::validate || exit 1 ;;
esac
# If alias resolved to service, pass original cmd as subcommand
if [[ "$cmd" == "service" ]]; then
load_command service
command::run service "$raw_cmd" "$@"
return
fi
if load_command "$cmd"; then
if command::exists "$cmd"; then
command::run "$cmd" "$@"
else
log::error "Command '${cmd}' loaded but $(command::fn "$cmd" run) is not defined"
exit 1
fi
else
log::error "Unknown command: '${raw_cmd}'"
echo "Run 'wgctl help' to see available commands."
| 1 | function wgctl::dispatch() { |
| 2 | local raw_cmd="${1:-help}" |
| 3 | shift || true |
| 4 | |
| 5 | local cmd |
| 6 | cmd="$(wgctl::resolve_alias "$raw_cmd")" |
| 7 | |
| 8 | case "$cmd" in |
| 9 | help) wgctl::help; return ;; |
| 10 | shell) : ;; |
| 11 | *) config::validate || exit 1 ;; |
| 12 | esac |
| 13 | |
| 14 | # If alias resolved to service, pass original cmd as subcommand |
| 15 | if [[ "$cmd" == "service" ]]; then |
| 16 | load_command service |
| 17 | command::run service "$raw_cmd" "$@" |
| 18 | return |
| 19 | fi |
| 20 | |
| 21 | if load_command "$cmd"; then |
| 22 | if command::exists "$cmd"; then |
| 23 | command::run "$cmd" "$@" |
| 24 | else |
| 25 | log::error "Command '${cmd}' loaded but $(command::fn "$cmd" run) is not defined" |
| 26 | exit 1 |
| 27 | fi |
| 28 | else |
| 29 | log::error "Unknown command: '${raw_cmd}'" |
| 30 | echo "Run 'wgctl help' to see available commands." |
| 31 |