Repository navigation
0.0.6: completion is built in: one engine answers from the command tree, and a shell's adapter only asks it - #13
Merged
Conversation
…ee, and a shell's adapter only asks it
This was referenced Nov 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Completion is built into the library: one engine answers from the command tree, and a shell's script only asks it. Closes #9.
Change
app.completion()turns it on (off by default; an application that does not call it parses as before).app.completion({.command = "", .entry = "__complete"})leaves out the visible command.myapp completions <bash|zsh|fish|powershell>prints the adapter for a shell. An adapter is a few lines that pass the words before the cursor tomyapp __complete …and list the answer; nothing of the command tree is in it, so a program that gains a command completes it without its users installing anything again.myapp __complete <words…>answers with one candidate per line (value<TAB>description) and a last line:<directive>(0nothing,1files,2directories). Both are answered where--helpis: the parse returnsParseErrorof kindcompletion, whichis_error()reports false.completions::complete(cmd, words), is a pure function of the tree and the words. It reads each word bycompletions::classify, the reader the parse uses:--,--k,--k=v,-k, a subcommand, a positional..values({...})(a closed set the parse checks, which help and completion list),.value_hint(ValueHint::file|directory),.complete(fn)(the program's candidates, called only while completing),Arg::repeatable(),App::hidden()(not listed in help or completions; parses and runs as any other).snapshot(app): each command has its own-h/--help, and--versionis the command's that has a version, as the parse answers them. Hidden commands are not in it.generate_completions(...)andApp::completions(Shell)keep their signatures and return the adapter.Shell::powershellis added.Tests
tests/completions_test.cpp: nested subcommands, global options under a subcommand,--k=v, a value taken by an option,--, closed sets, callbacks, file hints, a repeatable positional, the entry's text, adapters that hold no tree, completion off by default, the parse refusing a value outside a set, a hidden command, and the shared classifier. The bash and fish adapters were exercised againstexamples/completions.Documents
docs/api.md(Shell completion, the new builders), README, version 0.0.6.