In short: clap's own help subcommand is turned off and replaced by this command. With
-k, it prints an embedded Markdown doc through the pager. Otherwise it re-parses the named
commands against the CLI definition, walks down to the subcommand, and prints its long help. It never
loads a repo.
The command is cmd_help. Its help text: "Print this message
or the help of the given subcommand(s)" (source). It is the
Help variant of the top-level Command enum
(source, dispatch), which also
sets disable_help_subcommand so clap doesn't add its own (source).
1. Command-line surface
| Argument | Type | Default | Meaning |
|---|---|---|---|
COMMAND… (positional) | strings | none | "Print help for the subcommand(s)", for example jj help workspace root (source). |
-k, --keyword KEYWORD | one of seven names | none | "Show help for keywords instead of commands". Conflicts with COMMAND. The values are bookmarks, config, filesets, glossary, revsets, templates and tutorial (source, KEYWORDS). |
HelpArgs. The top-level long help ends with a hint pointing
at jj help -k (source). 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()) | Cloned and parsed so global arguments propagate to subcommands before help is rendered (source). That is why jj help log prints exactly what jj log --help does (test). |
KEYWORDS | Seven Markdown files from docs/, embedded with include_str!, so the binary carries its own copy. jj help -k revsets prints docs/revsets.md byte for byte (test). |
Ui | Both paths call request_pager, so output goes through ui.pager on a terminal; keyword docs are printed as raw Markdown (source, TODO). |
| Repo, working copy, operation log | Not touched: cmd_help never asks for a workspace. |
Errors and edge cases
| Input | Result |
|---|---|
jj help unknown | clap's unrecognized subcommand 'unknown' with a "similar subcommand" tip, exit 2 (test). |
jj help log -- -r | Error: Unknown command: log -r, exit 2 (test). |
jj workspace help root | help is only top-level: unrecognized subcommand 'help' (test). |
jj help -k rev | clap rejects the value, lists the seven keywords and suggests revsets (test). |
jj help revsets | Keywords need -k; without it this is an unknown subcommand (test). |