Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions src/uu/numfmt/src/numfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
35 changes: 35 additions & 0 deletions tests/by-util/test_numfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!()
Expand Down
Loading