CliRouter class

A trie based CLI router. Routes are registered with cmd, resolved (purely, no I/O) with resolve, and dispatched with run.

Every behavior-changing registration detail is a required named parameter: the router applies no defaults and guesses nothing.

Constructors

CliRouter({required List<OptionSpec> globalOptions})

Properties

hashCode → int
The hash code for this object.
no setterinherited
reservedWords → List<String>
Every literal word reachable as the first token of some route, mount prefixes included. Useful to check a word is not already taken before adding a new command or mount.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

cmd(String pattern, CliHandler handler, {required List<OptionSpec> options, required bool globals, String? description}) → void
Registers a route.
listCommands() → List<ListedCommand>
Every registered route, mounts flattened in.
mount(String prefix, CliRouter router) → void
Grafts every route of router under a single literal prefix word.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
resolve(List<String> argv) → CliOutcome
Resolves argv against the registered routes. Pure: performs no I/O and never throws for a malformed invocation, only for a bug in the router itself.
run(List<String> args, {required CliRejectionHandler onReject, IOSink? stdout, IOSink? stderr}) → Future<int>
Resolves and dispatches args. onReject is required: it takes over for every invocation that does not resolve to a route, and decides the process exit code; the router itself never maps a rejection to one.
toString() → String
A string representation of this object.
inherited
use(CliMiddleware middleware) → void
Adds middleware, applied in registration order around the resolved route's handler.

Operators

operator ==(Object other) → bool
The equality operator.
inherited