feat(std/cli): commands, flags, options and arguments #424
Loading…
Reference in a new issue
No description provided.
Delete branch "loop/123-std-cli"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #123
Task
CLI slice 1:
std/cli, commands, flags, options and positional arguments declared once as a builder on receiver closures, with generated help and errors, parsed overList<String>so tests need no process.What
std/cli(project.trb,src/,tests/):command "name" { description ...; command ...; flag ...; option<T>(...); arguments ...; run { input => ... } }.flag("x")isinput.flag("x")(--x, absent = false);option<T>("jobs", default: 4)isinput.option<T>("jobs")forInt,Float64,BoolandStringthrough the newArgumenttrait (a program's own type joins with anextend).--jobs 8and--jobs=8both work;arguments("paths")collects the rest;--ends option parsing.CliErrorwhose message names the command and the argument;Command.runprints it and exits with code 2.--help,-h,help <command>) is generated from the declaration.Command.parseandCommand.helpare pure; 29 tests hand argument lists and assert parsed values, help text and the exact error messages.docs/standard-library/cli.md,skills/regenerated, CLI.md status and section 2 item 1 now record the decision (typed options,decode<T>later).One commit more than planned
fix(checker): pass explicit type arguments to an implicit receiver member: inside a receiver closureoption<Int>("jobs")resolved to the builder's member but dropped the type arguments (Cannot infer T), so the declaration readself.option<Int>(...).resolveNamenow keeps the explicit arguments (compiler/src/semantics/checker/name.trb). The std/cli tests and the docs snippet use the bare form, so the gates exercise it. I could only verify the package locally with the nightly (which lacks the fix) by writingself.option<; the bare form is verified by CI.Out of scope
torbmigration (#124), shell completion (#125), aDecode-baseddecode<T>(), environment-variable fallbacks.Test
torb test std/cli/tests(29 passed locally with the nightly,self.option<form);torb format --check,docs index --check,docs skillanddocs check --no-snippetsclean locally; gates, native back ends and bootstrap run in CI.option<Int>("jobs") inside a receiver closure resolved to the builder's member but dropped the type arguments, so T could not be inferred. They now fill the member's parameters, as in self.option<Int>("jobs").CI red on
154cdcd:ci / tier A (linux-x64)(andgates) - two red gates, both from std/cli docs checks:docs source --panics:std/cli/src/input.trblines 23, 31, 43 -fn flag,fn option,fn argumentscallpanicbut their doc comments have no# Panicssection.doc --check --no-run std:std/cli/src/command.trblines 49-54 -CommandBuilder.summary,flagSpecs,optionSpecs,argumentsSpec,subcommands,actionhave no doc comment;command.trb:265-[options]does not resolve;input.trb:10-[Command.parse]does not resolve here (name what the file declares/imports).Bootstrap, playground, pdisc and the other jobs are green. No review yet; my request stays pending and the next CI run on a new head brings me back.
Approved at
d74dfc5.--, positional arguments, everyCliErrormessage and the generated help text. CI is green on this head (tier A, gates, bootstrap, playground, pdisc); the earlier red docs gates (panics sections, doc comments, unresolved links) are fixed.parseis pure;settlefills flags and defaults at each level;--x=vand--x v, a flag given a value, a missing value and a missing required option each have an error. The checker fix (resolveNamekeeps the explicit type arguments) is small and exercised by the bareoption<Int>(...)form in the std/cli tests and the docs snippet, which CI builds.torbmigration, completion anddecode<T>are listed as out of scope. The extra checker commit is explained in the body.Command.run(exit code 2 on a bad line).docs/standard-library/cli.md, the index, the regenerated skill files andCLI.mdstatus are updated; the pdisc check is green.Non-blocking:
-(for example-5) is an unknown flag unless it follows--; fine for now, worth a line in the docs.helpwould be shadowed by--help.torbparses its command line withstd/cli(CLI slice 2) #124