Skip to main content

Module cli

Module cli 

Source
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 mirrors acli’s output envelope so user programs can match lex’s own --output json shape without each command rolling their own.
flag_spec
help_text
Human-readable help text. Layout matches argparse/clap for familiarity. Subcommands are listed below the args.
option_spec
parse
Parse argv against spec. Returns a CliParsed-shaped JSON value on success, an error message on failure.
positional_spec