Expand description
std.cli — argparse-equivalent for end-user Lex programs
(Rubric port follow-up).
The Rubric CLI has six subcommands with a mixed bag of positional / option / flag arguments, JSON-envelope output, and ACLI introspection. Hand-rolling each subcommand’s parser is days of clipped-wing work; this module provides the equivalent Lex builder surface.
The wire format for spec values is JSON (opaque to user code,
constructed via cli.flag / cli.option / cli.positional /
cli.spec). Internal records carry a kind discriminator so
parse can identify what each entry is without relying on field
shape.
Functions§
- build_
spec - describe
- Machine-readable description of a spec — recurses through
subcommands. Useful for tools that want to discover a CLI’s
surface without invoking
--help. - envelope
{ "ok": true|false, "command": "<name>", "data": <data> }. The shape mirrorsacli’s output envelope so user programs can matchlex’s own--output jsonshape without each command rolling their own.- flag_
spec - help_
text - Human-readable help text. Layout matches
argparse/clapfor familiarity. Subcommands are listed below the args. - option_
spec - parse
- Parse
argvagainstspec. Returns aCliParsed-shaped JSON value on success, an error message on failure. - positional_
spec