In short: it hands a copy of the CLI definition to clap_complete (or clap_complete_nushell)
and writes the script to stdout. That script knows subcommands and flags only. jj's other completion mode, the
"dynamic" one, doesn't use this command: the shell runs jj itself with COMPLETE set,
which can also complete bookmarks, revisions, operations and files (docs).
The command is cmd_util_completion. Its help text: "Print a
command-line-completion script", followed by how to load it in each shell (source).
It is the Completion variant of UtilCommand (source,
dispatch).
1. Command-line surface
| Argument | Type | Default | Meaning |
|---|---|---|---|
SHELL (positional, required) | one of six names | none | bash, elvish, fish, nushell, power-shell or zsh (source, ShellCompletion). |
For example source <(jj util completion bash); the dynamic equivalent is
source <(COMPLETE=bash jj) (docs). The global flags are on the
CLI page.
3. End-to-end flow
4. Core architecture touchpoints
| Piece | Role here |
|---|---|
The clap command tree (command.app()) | The only input. Because it is the same tree jj parses with, the script lists every subcommand and flag of this build, including ones a custom binary adds. |
clap_complete, clap_complete_nushell | The generators, declared in the workspace Cargo.toml; clap_complete is built with its unstable-dynamic feature for the dynamic mode (source). |
cli/src/complete.rs | The candidate functions (bookmarks, revisions, operations, files and so on) that only dynamic completion uses. |
| Repo, working copy, operation log | Not touched: cmd_util_completion never asks for a workspace. Upstream's test checks each of the six shells prints to stdout only (test). |