diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index 9ab26ab95..b5c1e1990 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -3128,7 +3128,7 @@ pub struct GlobalArgs { #[derive(clap::Args, Clone, Debug)] pub struct EarlyArgs { - /// When to colorize output (always, never, debug, auto) + /// When to colorize output #[arg(long, value_name = "WHEN", global = true)] pub color: Option, /// Silence non-primary command output diff --git a/cli/src/ui.rs b/cli/src/ui.rs index b35430591..98c26d5f1 100644 --- a/cli/src/ui.rs +++ b/cli/src/ui.rs @@ -27,7 +27,6 @@ use std::mem; use std::process::Child; use std::process::ChildStdin; use std::process::Stdio; -use std::str::FromStr; use std::thread; use std::thread::JoinHandle; @@ -35,8 +34,6 @@ use itertools::Itertools as _; use jj_lib::config::ConfigGetError; use jj_lib::config::StackedConfig; use os_pipe::PipeWriter; -use serde::de::Deserialize as _; -use serde::de::IntoDeserializer as _; use tracing::instrument; use crate::command_error::CommandError; @@ -206,7 +203,7 @@ pub struct Ui { output: UiOutput, } -#[derive(Clone, Copy, Debug, Eq, PartialEq, serde::Deserialize)] +#[derive(Clone, Copy, Debug, Eq, PartialEq, serde::Deserialize, clap::ValueEnum)] #[serde(rename_all = "kebab-case")] pub enum ColorChoice { Always, @@ -215,17 +212,6 @@ pub enum ColorChoice { Auto, } -impl FromStr for ColorChoice { - type Err = String; - - fn from_str(s: &str) -> Result { - // serde::de::value::Error is Box wrapper. Map it to String to hide - // the implementation detail. - Self::deserialize(s.into_deserializer()) - .map_err(|err: serde::de::value::Error| err.to_string()) - } -} - impl fmt::Display for ColorChoice { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let s = match self { diff --git a/cli/tests/cli-reference@.md.snap b/cli/tests/cli-reference@.md.snap index 53816e759..4103f8295 100644 --- a/cli/tests/cli-reference@.md.snap +++ b/cli/tests/cli-reference@.md.snap @@ -1,6 +1,7 @@ --- 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 --- @@ -187,7 +188,10 @@ To get started, see the tutorial at https://jj-vcs.github.io/jj/latest/tutorial/ It is possible to run mutating commands when loading the repo at an earlier 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. * `--debug` — Enable debug logging -* `--color ` — When to colorize output (always, never, debug, auto) +* `--color ` — When to colorize output + + Possible values: `always`, `never`, `debug`, `auto` + * `--quiet` — Silence non-primary command output For example, `jj file list` will still list files, but it won't tell you if the working copy was snapshotted or if descendants were rebased. diff --git a/cli/tests/test_completion.rs b/cli/tests/test_completion.rs index a940f084c..262a99fb0 100644 --- a/cli/tests/test_completion.rs +++ b/cli/tests/test_completion.rs @@ -79,7 +79,7 @@ fn test_bookmark_names() { --ignore-immutable Allow rewriting immutable commits --at-operation Operation to load the repo at --debug Enable debug logging - --color When to colorize output (always, never, debug, auto) + --color When to colorize output --quiet Silence non-primary command output --no-pager Disable the pager --config Additional configuration options (can be repeated) diff --git a/cli/tests/test_global_opts.rs b/cli/tests/test_global_opts.rs index 0301c4c94..0c0b85fe4 100644 --- a/cli/tests/test_global_opts.rs +++ b/cli/tests/test_global_opts.rs @@ -458,7 +458,8 @@ fn test_color_config() { // Invalid --color let stderr = test_env.jj_cmd_cli_error(&repo_path, &["log", "--color=foo"]); insta::assert_snapshot!(stderr, @r" - error: invalid value 'foo' for '--color ': unknown variant `foo`, expected one of `always`, `never`, `debug`, `auto` + error: invalid value 'foo' for '--color ' + [possible values: always, never, debug, auto] For more information, try '--help'. "); @@ -935,7 +936,7 @@ fn test_help() { let test_env = TestEnvironment::default(); let stdout = test_env.jj_cmd_success(test_env.env_root(), &["diffedit", "-h"]); - insta::assert_snapshot!(stdout, @r###" + insta::assert_snapshot!(stdout, @r" Touch up the content changes in a revision with a diff editor Usage: jj diffedit [OPTIONS] @@ -954,12 +955,13 @@ fn test_help() { --ignore-immutable Allow rewriting immutable commits --at-operation Operation to load the repo at [aliases: at-op] --debug Enable debug logging - --color When to colorize output (always, never, debug, auto) + --color When to colorize output [possible values: always, never, debug, + auto] --quiet Silence non-primary command output --no-pager Disable the pager --config Additional configuration options (can be repeated) --config-file Additional configuration files (can be repeated) - "###); + "); } #[test]