cli module
Declare your CLI shape (flags, options, positionals), then parse argv into a map. Auto-generates a --help-style usage string.
import "cli" as cli;
var p = cli.parser("greet");
p.description = "Print a greeting.";
cli.flag (p, {name: "shout", short: "s", help: "Use upper case"});
cli.option (p, {name: "lang", short: "l", help: "en or bn", default: "en"});
cli.positional(p, {name: "name", help: "Who to greet"});
var args = cli.parse(p);
print(args.lang, args.name, args.shout);
API
| Function | Description |
|---|---|
cli.parser(name) → parser | Start a new parser. Set parser.description for the help blurb. |
cli.flag(p, spec) | Add a boolean flag. spec: {name, short?, help?}. |
cli.option(p, spec) | Add an option that takes a value. spec: {name, short?, help?, default?}. |
cli.positional(p, spec) | Add a positional arg. spec: {name, help?, default?}. |
cli.parse(p) → map | Read real sys.arg(*) and produce the args map. |
cli.parse_argv(p, argv) → map | Same, but parses a synthetic list (useful in tests). |
cli.usage(p) → string | Build a --help-style usage string. |
Output shape
The returned map has one entry per declared name:
- Flags:
bool(defaultfalse). - Options:
string(default per spec). - Positionals:
string(default per spec). _rest— extra positionals past the declared ones.
See also
sys— the low-levelsys.argc()/sys.arg(i)accessorsclisits on top of.