From 28916ceb19ea2da4418f3cac08c32e46900e3335 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 2 Apr 2022 14:10:52 -0700 Subject: [PATCH] cli: in help output, list global options under separate heading I've found it hard to read the `jj help` output because command options are mixed with global options. This patch fixes that by putting global options under a separate heading. --- src/commands.rs | 18 ++++++++++++++---- tests/test_global_opts.rs | 24 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index 7dbc964fa..ef8442088 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -868,7 +868,11 @@ fn update_working_copy( /// To get started, see the tutorial at https://github.com/martinvonz/jj/blob/main/docs/tutorial.md. #[derive(clap::Parser, Clone, Debug)] #[clap(author = "Martin von Zweigbergk ", version)] -#[clap(mut_arg("help", |arg| { arg.help("Print help information, more help with --help than with -h")}))] +#[clap(mut_arg("help", |arg| { + arg + .help("Print help information, more help with --help than with -h") + .help_heading("GLOBAL OPTIONS") + }))] struct Args { #[clap(subcommand)] command: Commands, @@ -876,7 +880,7 @@ struct Args { /// /// By default, Jujutsu searches for the closest .jj/ directory in an /// ancestor of the current working directory. - #[clap(long, short = 'R', global = true)] + #[clap(long, short = 'R', global = true, help_heading = "GLOBAL OPTIONS")] repository: Option, /// Don't commit the working copy /// @@ -886,7 +890,7 @@ struct Args { /// stale working copy commit, you can use `--no-commit-working-copy`. /// This may be useful e.g. in a command prompt, especially if you have /// another process that commits the working copy. - #[clap(long, global = true)] + #[clap(long, global = true, help_heading = "GLOBAL OPTIONS")] no_commit_working_copy: bool, /// Operation to load the repo at /// @@ -907,7 +911,13 @@ struct Args { /// operation. Doing that is equivalent to having run concurrent commands /// starting at the earlier operation. There's rarely a reason to do that, /// but it is possible. - #[clap(long, alias = "at-op", global = true, default_value = "@")] + #[clap( + long, + alias = "at-op", + global = true, + help_heading = "GLOBAL OPTIONS", + default_value = "@" + )] at_operation: String, } diff --git a/tests/test_global_opts.rs b/tests/test_global_opts.rs index 2e12eaded..952bed471 100644 --- a/tests/test_global_opts.rs +++ b/tests/test_global_opts.rs @@ -104,3 +104,27 @@ fn test_invalid_config() { insta::assert_snapshot!(stdout, @"Invalid config: expected newline, found an identifier at line 1 column 10 in config.toml "); } + +#[test] +fn test_help() { + // Test that global options are separated out in the help output + let test_env = TestEnvironment::default(); + + let stdout = test_env.jj_cmd_success(test_env.env_root(), &["edit", "-h"]); + insta::assert_snapshot!(stdout.replace(".exe", ""), @r###" + jj-edit + Edit the content changes in a revision + + USAGE: + jj edit [OPTIONS] + + OPTIONS: + -r, --revision The revision to edit [default: @] + + GLOBAL OPTIONS: + --at-operation Operation to load the repo at [default: @] + -h, --help Print help information, more help with --help than with -h + --no-commit-working-copy Don't commit the working copy + -R, --repository Path to repository to operate on + "###); +}