A program built with mcpplibs.cmdline that calls App::completion() answers its own completions. A
shell never holds the program's command tree: its script is an adapter of a few lines that passes the
words to the program and lists what comes back. This page is the contract between the two, so that
anything -- a shell, an editor, a package manager writing the adapter at install time -- can rely on it.
<program> <entry> <word>...
entry is __complete unless the program chose another (CompletionOptions::entry). The words are the
words of the command line after the program's name, up to the cursor; the last is the word being typed,
empty when the cursor stands after a space. The program answers without touching its home, a project or
the network: the answer comes from the command tree and from the candidate callbacks the program
declared.
One candidate per line, value<TAB>description (no tab when there is no description), then one line
:<directive>:
| directive | the shell adds |
|---|---|
:0 |
nothing: the candidates are the whole answer |
:1 |
file names |
:2 |
directory names |
For a program tool with the subcommands build ("Build the project", whose --manifest names a file)
and bench ("Run the benchmarks"), tool __complete b answers
build Build the project
bench Run the benchmarks
:0
and tool __complete build --manifest "" answers
:1
completions::adapter(shell, program, entry) returns the adapter for bash, zsh, fish or
powershell; <program> completions <shell> prints it when the program enables the command. The bash
one starts
# bash completion for tool: the program answers (`tool __complete <words>`).
An adapter depends only on the program's name and the entry: a program that gains a command completes it with the adapter already installed, and a package manager can write the adapter for a program that declares this protocol without running the program.
Version 1 is the protocol of cmdline 0.0.6 and later. An incompatible change to the request, the answer or
the directives is made under a new entry name; __complete keeps answering version 1. The tests run the
examples on this page (tests/capabilities_test.cpp).