Principle:20000419 Fauxnix CLI Dispatch
| Knowledge Sources | |
|---|---|
| Domains | CLI, Dispatch |
| Last Updated | 2026-10-26 00:00 GMT |
Overview
A command-dispatch pattern that inspects the first argv token and routes to a subcommand handler, with the default verb joining the remaining tokens into a command string for immediate execution.
Description
CLI Dispatch is the routing layer of a multi-verb command-line tool. Rather than a single fixed behavior, the tool inspects the first argument (the "verb") and delegates to a specialized handler: translate, mcp, list, check, doctor, install, facade, or --version. When no recognized verb is present, the default behavior joins all argv tokens into a single command string and executes it. This dual nature — subcommand router plus default pass-through executor — lets a single binary serve as both an interactive command runner and a management tool. It solves the problem of overloading a thin CLI entry with many distinct operational modes while keeping the common case (run a command) zero-friction.
Usage
Use this pattern when a single CLI binary must support both a primary action (execute a command) and a set of management subcommands (install, diagnose, serve). It is the right choice when the primary action's input is naturally "the rest of the argv" and the subcommands are opt-in.
Theoretical Basis
The dispatch is a simple prefix-match on argv[0]:
if argv[0] in {translate, mcp, list, check, doctor, install, facade, --version}:
delegate to subcommand(argv[1:])
else:
command = join(argv, ' ')
parse → translate → execute → print
No option parsing framework is needed because the verbs are mutually exclusive and the default path consumes the entire argv. Subcommands that take flags (install --claude) parse their own rest slice.