From 2d0b6560e82b0e9df39b5536917d3b5066d888fa Mon Sep 17 00:00:00 2001 From: Austin Seipp Date: Sat, 23 Mar 2024 12:35:27 -0500 Subject: [PATCH] cli: allow multiple `-r` options for `duplicate`/`abandon` Commands like `new`, `duplicate`, and `abandon` can take multiple revset arguments which results in their collective union. They take the revisions directly as arguments. But for consistency with many other commands, they can also take the `-r` argument, which is a no-op. However, due to the flag being specified as a `bool`, the `-r` option can only be specified once, so e.g. `abandon -r x -r y` often fails. I normally use `-r` for consistency and muscle memory, so this bites me often. Instead, use `clap::ArgAction::Count` in order to allow `-r` to be specified multiple times. It remains unused, of course. With this change, all the following invocations are equivalent. Before this change, the second example would fail due to giving `-r` multiple times. jj abandon x y jj abandon -r x -r y jj abandon -r 'x | y' Note: `jj new` already supported this exact case actually, but it used an awkward trick where it used `.overrides_with()` in order to override *itself* so it could be specified multiple times. I believe this is a bit clearer. Signed-off-by: Austin Seipp Change-Id: Ib36cf81d46dae4f698f06d0a32e8fd3120bfb4a4 --- CHANGELOG.md | 3 +++ cli/src/commands/abandon.rs | 4 ++-- cli/src/commands/duplicate.rs | 4 ++-- cli/src/commands/new.rs | 4 ++-- cli/tests/cli-reference@.md.snap | 9 --------- 5 files changed, 9 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 173297b186..1ec18c0bf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * `jj branch list` now supports a `--conflicted/-c` option to show only conflicted branches. +* `jj duplicate` and `jj abandon` can now take more than a single `-r` argument, + for consistency with other commands. + ### Fixed bugs ## [0.15.1] - 2024-03-06 diff --git a/cli/src/commands/abandon.rs b/cli/src/commands/abandon.rs index 06e15369b9..3b00e2853a 100644 --- a/cli/src/commands/abandon.rs +++ b/cli/src/commands/abandon.rs @@ -41,8 +41,8 @@ pub(crate) struct AbandonArgs { #[arg(long, short)] summary: bool, /// Ignored (but lets you pass `-r` for consistency with other commands) - #[arg(short = 'r', hide = true)] - unused_revision: bool, + #[arg(short = 'r', hide = true, action = clap::ArgAction::Count)] + unused_revision: u8, } #[instrument(skip_all)] diff --git a/cli/src/commands/duplicate.rs b/cli/src/commands/duplicate.rs index 44fd309574..58efcd2866 100644 --- a/cli/src/commands/duplicate.rs +++ b/cli/src/commands/duplicate.rs @@ -31,8 +31,8 @@ pub(crate) struct DuplicateArgs { #[arg(default_value = "@")] revisions: Vec, /// Ignored (but lets you pass `-r` for consistency with other commands) - #[arg(short = 'r', hide = true)] - unused_revision: bool, + #[arg(short = 'r', hide = true, action = clap::ArgAction::Count)] + unused_revision: u8, } #[instrument(skip_all)] diff --git a/cli/src/commands/new.rs b/cli/src/commands/new.rs index a94d80769e..54b5ee8a29 100644 --- a/cli/src/commands/new.rs +++ b/cli/src/commands/new.rs @@ -45,8 +45,8 @@ pub(crate) struct NewArgs { #[arg(default_value = "@")] pub(crate) revisions: Vec, /// Ignored (but lets you pass `-r` for consistency with other commands) - #[arg(short = 'r', hide = true, overrides_with = "unused_revision")] - unused_revision: bool, + #[arg(short = 'r', hide = true, action = clap::ArgAction::Count)] + unused_revision: u8, /// The change description to use #[arg(long = "message", short, value_name = "MESSAGE")] message_paragraphs: Vec, diff --git a/cli/tests/cli-reference@.md.snap b/cli/tests/cli-reference@.md.snap index 420f3a616d..52f2194292 100644 --- a/cli/tests/cli-reference@.md.snap +++ b/cli/tests/cli-reference@.md.snap @@ -189,9 +189,6 @@ If a working-copy commit gets abandoned, it will be given a new, empty commit. T * `-r` — Ignored (but lets you pass `-r` for consistency with other commands) - Possible values: `true`, `false` - - ## `jj backout` @@ -703,9 +700,6 @@ Create a new change with the same content as an existing one * `-r` — Ignored (but lets you pass `-r` for consistency with other commands) - Possible values: `true`, `false` - - ## `jj edit` @@ -1118,9 +1112,6 @@ For more information, see https://github.com/martinvonz/jj/blob/main/docs/workin ###### **Options:** * `-r` — Ignored (but lets you pass `-r` for consistency with other commands) - - Possible values: `true`, `false` - * `-m`, `--message ` — The change description to use * `-L`, `--allow-large-revsets` — Deprecated. Please prefix the revset with `all:` instead