ok/jj
1
0
Fork 0
forked from mirrors/jj

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.
This commit is contained in:
Martin von Zweigbergk 2022-04-02 14:10:52 -07:00 committed by Martin von Zweigbergk
parent f21a069a47
commit 28916ceb19
2 changed files with 38 additions and 4 deletions

View file

@ -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 <martinvonz@google.com>", 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<String>,
/// 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,
}

View file

@ -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 <REVISION> The revision to edit [default: @]
GLOBAL OPTIONS:
--at-operation <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 <REPOSITORY> Path to repository to operate on
"###);
}