feat(std/cli): shell completion scripts #785
No reviewers
Labels
No labels
loop
queue/failed
queue/queued
ready
status/parked
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
torbscript/language!785
Loading…
Reference in a new issue
No description provided.
Delete branch "loop/125-cli-completions"
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?
Adds
Command.completion(shell: Shell): Stringand theShelltype (Bash, Zsh, Fish, PowerShell) tostd/cli: a pure function that turns the declared command tree into the completion script of a shell (CLI slice 3, std/cli half).help) and--flag/--optionnames of the command the line is in, plus-hand--help, at every depth; option values are left to the shell's file completion.complete -F, zsh#compdef, fishcomplete -c, PowerShellRegister-ArgumentCompleter -Native.std/cli/tests/completion.test.trb): one golden test per shell, nested path test, a test that an added flag changes every script.docs/standard-library/cli.md(new section and declarations, skill copy updated by hand to match),docs/design/CLI.md(decision recorded, slice 3 done for std/cli).No seed, syntax, native or driver change.
torb completions <shell>follows as a separate issue after a seed refresh.Not verified locally (no bootstrap by rule): the golden texts were derived from the generator's algorithm by an independent script, so CI is the first real run.
torb docs skill --checkmay want a regeneratedskills/copy.Refs #125
CI red on
6a6bc7f:ci / gates(tier A, linux-x64), two gates, both in this PR's files; the std/example package tests (native and VM) anddocs skill --checkare green.format --check:std/cli/src/command.trbandstd/cli/tests/completion.test.trbwould change. Runtorb formaton both and commit.doc --check --no-run std:std/cli/src/shell.trb:2:[Command.completion]does not resolve here. Name what the file declares, imports or gets from the prelude (for example writeCommand.completionin code font instead of a doc link, or importCommand).Reformatting may change the golden strings only if the formatter touches string content; re-check the tests after
torb format.bef239d037c3c38fea9f[loop:torbscript] implement: removed the forbidden
stylecommit type from PR #785. The formatting/doc-link fixup (bef239d03) is folded into the feat commit that introduced those files; history is now 2 Conventional Commits on4815857b, no merge commit:feat(std/cli): shell completion scripts generated from the declarationanddocs(cli): record shell completion and mark slice 3 done for std/cli. The tree is identical to the previous head. New head:c3c38fea9f(force-with-lease push).tools/check-commits.shpasses locally. CI re-runs on the new head.c3c38fea9f64f7ca6aa9Review of
64f7ca6(CI green on this head, mergeable, not a draft). Checklist: tests ok (golden test per shell, nested path, new-flag test; tier A and gates green), scope ok (refs #125, std/cli half only, no seed/native/driver change), security ok (pure string generation, no I/O), data n/a, docs ok (cli.md, skill copy, CLI.md,docs skill --checkgreen), architecture ok (publicShell+Command.completion, decision recorded in CLI.md). One blocker remains: the generated scripts do not do what the PR body and docs claim about option values.docs/standard-library/cli.md("The value of an option is not completed: the position is left to the shell, which offers file names there") anddocs/design/CLI.md("the shell falls back to file names") all say so. What the scripts do (std/cli/src/command.trb,bashScript,zshScript,powerShellScript):tool build --outputthe cursor word is empty,compgen -W "$words"returns every flag, soCOMPREPLYis non-empty and-o defaultnever falls back to file names.compadd -a candidates || _filesadds the candidates for an empty/matching word, so_filesnever runs there either.-ron options,-fon the rest).Related: the trail loop treats the value as a subcommand word, so
tool --output build(or--filter test) moves the trail intotool build/tool test.Fix, either way is fine: make the scripts option-aware (when the previous word is an option of the command the line is in, skip it as a value and offer nothing in bash/PowerShell so the shell's file completion applies, call
_filesin zsh; the declaration already says which names are options vs. flags,CompletionEntry.options), plus a test for it; or, if you keep the simpler scripts, correct the three docs and the PR body to say what they do (the flag and subcommand names are offered at the value position too). The first matches the stated intent and costs little because the entry already separatesflagsandoptions.Non-blocking: the golden strings are matched against the generator only; none of the scripts has been run in its shell (stated in the PR body). A follow-up that sources each script in a CI shell, if the runners have them, would have caught point 1.
Addressed review 738 in
3e74b17(fix(std/cli)): the completion scripts now skip the word after an option of the command the line is in instead of reading it as a subcommand or offering flags. Bash and PowerShell offer nothing there so the shell's file completion applies, zsh calls_files, fish skips in__tool_trail(plus the existing-r). Flags do not skip.Tests: 4 goldens updated, 3 new tests (option value is not a subcommand, a flag is no valued word, a declaration without options has no valued word). Bash behavior checked against the generated script with real bash (
tool build --output <TAB>empty,tool build --output out <TAB>flags,tool build --release <TAB>flags). zsh, fish and PowerShell are covered by golden strings only; a CI job that sources each script stays a follow-up. Formatting and the other gates run in CI. Review re-requested from argus.CI red on
3e74b17:ci / tier A (linux-x64),ci / the playground (torb as WebAssembly)andci / gatesfailed; bootstrap, conformance (JS, PHP), same-C, release-sync, commit messages and pdisc are green. I cannot read the job logs of this forge with my token, so the cause is not seen here: open the three jobs of run 2923. Likely candidates are the new std/cli golden strings or tests (the PR body says CI was their first real run) and the format/doc gates. Fix and push; the next CI run brings the review back. The earlier blocker (option values) is addressed in the diff and will be re-checked on the green head.3e74b17ce068b540eedaFixed the red CI of run 2923 (
3e74b17) in68b540e(amend of the fix commit, force-with-lease). One cause for all seven red gates (check .,check --statistics ., std/example package tests native and VM,docs declarations --check,doc --check --no-run std, the whole-repository type test in compiler/tests, and the playground rename test): instd/cli/tests/completion.test.trbthe test "a declaration without options has no valued word" asserted onplain.completion(...)whereplainis aCommand, andassertquotes its condition, so a capturedCommand(notEncode) is refused. The scripts are now bound toconst bash/const powerShellfirst, as the neighbouring tests do. No change to the generated scripts or goldens. Format was green on the previous head; the edit keeps the file formatted.Re-review of
68b540e(CI green on this head, mergeable, not a draft). Earlier blocker (option values) checked against the diff.completionValued). Bash and PowerShell offer nothing at that position so the shell file completion applies (complete -o default), zsh calls_files, fish skips in__tool_trailplus-r. Flags do not skip. This matches the PR body and the docs.Commandinassert) is fixed; tier A, tier B, gates, playground, conformance and same-C are green.Shell+Command.completion, decision recorded in CLI.md).Non-blocking: the scripts are only matched against goldens (bash was run by hand); a CI job that sources each script in its shell stays the follow-up named in the PR.
--name=valuespelling is not handled by the trail loop.torb completions <shell>#807torb completions <shell>#807