cli_router library
Public library for cli_router.
Import package:cli_router/cli_router.dart to use:
- CliRouter, CliRequest, CliHandler, CliMiddleware
- OptionSpec, ParsedOption, looksLikeOption, OptionOrdering
- CliRoute, CliOutcome, CliResolution, CliRejection, CliRejectionKind, CliRejectionHandler
- ListedCommand
- handler(...) helper
Classes
- CliOutcome
- The result of CliRouter.resolve: either a CliResolution or a CliRejection. A pure, sealed value; resolving performs no I/O.
- CliRejection
- An invocation that did not resolve.
- CliRequest
- A concrete, resolved invocation, handed to a route's CliHandler.
- CliResolution
- An invocation that matched a route.
- CliRoute
- A registered route, as exposed to the outside: its command words, its positional parameters, and the option schema that applies to it.
- CliRouter
- A trie based CLI router. Routes are registered with cmd, resolved (purely, no I/O) with resolve, and dispatched with run.
- ListedCommand
- A registered route, as seen from outside the router.
- OptionSpec
-
The declared shape of one option: a flag (present or not, no value) or a
value option (
--name value,--name=value,-n value). - ParsedOption
- One occurrence of an option, exactly as it was written on the invocation.
Enums
- CliRejectionKind
- Every way a router can fail to resolve an invocation, per spec 8.5. The router only classifies; it never maps a kind to an exit code, that is an application (SDK) concern.
- OptionOrdering
- How CliRouter.resolve treats an option written after an operand has already started.
Functions
-
handler(
FutureOr< void> fn(CliRequest req)) → CliHandler - Wraps a function that reports nothing into a CliHandler that returns 0 once it completes.
-
looksLikeOption(
String token) → bool -
Whether
tokenhas the shape of an option, per grammar G11:-followed by a letter,--followed by a letter, or exactly--.
Typedefs
-
CliHandler
= FutureOr<
int> Function(CliRequest req) - Handler type. Returns an exit code (0 OK, 64 invalid usage, etc.)
- CliMiddleware = CliHandler Function(CliHandler next)
- Shelf-like middleware: receives the next handler and returns a wrapped one.
-
CliRejectionHandler
= FutureOr<
int> Function(CliRejection rejection) - Decides how a rejected invocation is reported, and with which exit code.