diff --git a/src/uu/numfmt/src/numfmt.rs b/src/uu/numfmt/src/numfmt.rs index ef7bc2cbde7..304727c2a7e 100644 --- a/src/uu/numfmt/src/numfmt.rs +++ b/src/uu/numfmt/src/numfmt.rs @@ -577,6 +577,7 @@ pub fn uu_app() -> Command { .long(DELIMITER) .value_name("X") .value_parser(ValueParser::os_string()) + .allow_hyphen_values(true) .help(translate!("numfmt-help-delimiter")), ) .arg( @@ -626,7 +627,8 @@ pub fn uu_app() -> Command { Arg::new(PADDING) .long(PADDING) .help(translate!("numfmt-help-padding")) - .value_name("N"), + .value_name("N") + .allow_hyphen_values(true), ) .arg( Arg::new(HEADER) @@ -656,7 +658,8 @@ pub fn uu_app() -> Command { Arg::new(SUFFIX) .long(SUFFIX) .help(translate!("numfmt-help-suffix")) - .value_name("SUFFIX"), + .value_name("SUFFIX") + .allow_hyphen_values(true), ) .arg( Arg::new(UNIT_SEPARATOR) diff --git a/tests/by-util/test_numfmt.rs b/tests/by-util/test_numfmt.rs index 4db86944771..a17e634bd25 100644 --- a/tests/by-util/test_numfmt.rs +++ b/tests/by-util/test_numfmt.rs @@ -143,6 +143,41 @@ fn test_negative_padding() { .stdout_is("1000 \n1100000 \n100000000"); } +#[test] +fn test_negative_padding_as_separate_arg() { + // A negative padding value passed as its own argument (not attached + // with `=`) must not be mistaken for a new, unrecognized flag. + new_ucmd!() + .args(&["--from=si", "--padding", "-8"]) + .pipe_in("1K\n1.1M\n0.1G") + .succeeds() + .stdout_is("1000 \n1100000 \n100000000"); +} + +#[test] +fn test_suffix_hyphen_leading_as_separate_arg() { + // A hyphen-leading suffix value passed as its own argument (not + // attached with `=`) must not be mistaken for a new, unrecognized + // flag. + new_ucmd!() + .args(&["--suffix", "-x"]) + .pipe_in("5\n") + .succeeds() + .stdout_is("5-x\n"); +} + +#[test] +fn test_delimiter_hyphen_leading_as_separate_arg() { + // A hyphen-leading delimiter value passed as its own argument (not + // attached with `-d-x`/`=`) must not be mistaken for a new, + // unrecognized flag. + new_ucmd!() + .args(&["-d", "-x", "--field=1"]) + .pipe_in("5-x6") + .fails() + .stderr_contains("the delimiter must be a single character"); +} + #[test] fn test_header() { new_ucmd!()