Skip to content

Commit

Permalink
help: add more keyword topics (for jj help -k)
Browse files Browse the repository at this point in the history
We have the keyword-help feature now so let's use it a bit more. I'm
not sure how we should advertise it better, but that's a different
topic anyway.
  • Loading branch information
martinvonz committed Dec 16, 2024
1 parent c82483b commit 8907e69
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
25 changes: 25 additions & 0 deletions cli/src/commands/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,36 @@ struct Keyword {
//
// Maybe we can steal some ideas from https://github.com/martinvonz/jj/pull/3130
const KEYWORDS: &[Keyword] = &[
Keyword {
name: "bookmarks",
description: "Named pointers to revisions (similar to Git's branches)",
content: include_str!(concat!("../../", env!("JJ_DOCS_DIR"), "bookmarks.md")),
},
Keyword {
name: "config",
description: "How and where to set configuration options",
content: include_str!(concat!("../../", env!("JJ_DOCS_DIR"), "config.md")),
},
Keyword {
name: "filesets",
description: "A functional language for selecting a set of files",
content: include_str!(concat!("../../", env!("JJ_DOCS_DIR"), "filesets.md")),
},
Keyword {
name: "glossary",
description: "Definitions of various terms",
content: include_str!(concat!("../../", env!("JJ_DOCS_DIR"), "glossary.md")),
},
Keyword {
name: "revsets",
description: "A functional language for selecting a set of revision",
content: include_str!(concat!("../../", env!("JJ_DOCS_DIR"), "revsets.md")),
},
Keyword {
name: "templates",
description: "A functional language to customize command output",
content: include_str!(concat!("../../", env!("JJ_DOCS_DIR"), "templates.md")),
},
Keyword {
name: "tutorial",
description: "Show a tutorial to get started with jj",
Expand Down
11 changes: 10 additions & 1 deletion cli/tests/[email protected]
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
source: cli/tests/test_generate_md_cli_help.rs
description: "AUTO-GENERATED FILE, DO NOT EDIT. This cli reference is generated by a test as an `insta` snapshot. MkDocs includes this snapshot from docs/cli-reference.md."
snapshot_kind: text
---
<!-- BEGIN MARKDOWN-->

Expand Down Expand Up @@ -1278,8 +1277,18 @@ Print this message or the help of the given subcommand(s)
* `-k`, `--keyword <KEYWORD>` — Show help for keywords instead of commands
Possible values:
- `bookmarks`:
Named pointers to revisions (similar to Git's branches)
- `config`:
How and where to set configuration options
- `filesets`:
A functional language for selecting a set of files
- `glossary`:
Definitions of various terms
- `revsets`:
A functional language for selecting a set of revision
- `templates`:
A functional language to customize command output
- `tutorial`:
Show a tutorial to get started with jj
Expand Down
18 changes: 9 additions & 9 deletions cli/tests/test_help_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,33 +102,33 @@ fn test_help_keyword() {

// It should give hints if a similar keyword is present
let help_cmd_stderr = test_env.jj_cmd_cli_error(test_env.env_root(), &["help", "-k", "rev"]);
insta::assert_snapshot!(help_cmd_stderr, @r#"
insta::assert_snapshot!(help_cmd_stderr, @r###"
error: invalid value 'rev' for '--keyword <KEYWORD>'
[possible values: revsets, tutorial]
[possible values: bookmarks, config, filesets, glossary, revsets, templates, tutorial]
tip: a similar value exists: 'revsets'
For more information, try '--help'.
"#);
"###);

// It should give error with a hint if no similar keyword is found
let help_cmd_stderr =
test_env.jj_cmd_cli_error(test_env.env_root(), &["help", "-k", "<no-similar-keyword>"]);
insta::assert_snapshot!(help_cmd_stderr, @r#"
insta::assert_snapshot!(help_cmd_stderr, @r###"
error: invalid value '<no-similar-keyword>' for '--keyword <KEYWORD>'
[possible values: revsets, tutorial]
[possible values: bookmarks, config, filesets, glossary, revsets, templates, tutorial]
For more information, try '--help'.
"#);
"###);

// The keyword flag with no argument should error with a hint
let help_cmd_stderr = test_env.jj_cmd_cli_error(test_env.env_root(), &["help", "-k"]);
insta::assert_snapshot!(help_cmd_stderr, @r#"
insta::assert_snapshot!(help_cmd_stderr, @r###"
error: a value is required for '--keyword <KEYWORD>' but none was supplied
[possible values: revsets, tutorial]
[possible values: bookmarks, config, filesets, glossary, revsets, templates, tutorial]
For more information, try '--help'.
"#);
"###);

// It shouldn't show help for a certain keyword if the `--keyword` is not
// present
Expand Down

0 comments on commit 8907e69

Please sign in to comment.