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."