Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions src/options/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ pub fn get_command() -> clap::Command {
.default_missing_value("auto")
.default_value("auto"))
.arg(arg!(--"color-scale" <FIELDS> "highlight value of FIELDS distinctly")
.alias("colour-scale")
.num_args(0..)
.value_parser(value_parser!(ColorScaleArgs))
.default_missing_value("all")
.value_delimiter(','))
.arg(arg!(--"color-scale-mode" <MODE> "mode for --color-scale")
.alias("colour-scale-mode")
.num_args(1)
.value_parser(value_parser!(ColorScaleModeArgs))
.default_value("gradient"))
Expand Down Expand Up @@ -180,14 +182,11 @@ impl ValueEnum for ShowWhen {
}

fn to_possible_value(&self) -> Option<clap::builder::PossibleValue> {
Some(
match self {
Self::Always => "always",
Self::Auto => "auto",
Self::Never => "never",
}
.into(),
)
Some(match self {
Self::Always => PossibleValue::new("always"),
Self::Auto => PossibleValue::new("auto").alias("automatic"),
Self::Never => PossibleValue::new("never"),
})
}

fn from_str(s: &str, _ignore_case: bool) -> Result<Self, String> {
Expand Down Expand Up @@ -357,6 +356,27 @@ pub mod test {
get_command().no_binary_name(true).try_get_matches_from(itr)
}

#[test]
fn accepts_automatic_color_value() {
let cli = mock_cli_try(["--color=automatic"]).unwrap();
assert_eq!(cli.get_one::<ShowWhen>("color"), Some(&ShowWhen::Auto));
}

#[test]
fn accepts_colour_scale_aliases() {
let cli = mock_cli_try(["--colour-scale=size", "--colour-scale-mode=fixed"]).unwrap();
assert_eq!(
cli.get_many::<ColorScaleArgs>("color-scale")
.unwrap()
.collect::<Vec<_>>(),
[&ColorScaleArgs::Size]
);
assert_eq!(
cli.get_one::<ColorScaleModeArgs>("color-scale-mode"),
Some(&ColorScaleModeArgs::Fixed)
);
}

#[test]
fn deduce_files() {
let cli = mock_cli(vec!["file1", "file2"]);
Expand Down
Loading