diff --git a/src/uu/numfmt/src/numfmt.rs b/src/uu/numfmt/src/numfmt.rs index f6a1f2739..d490d3fee 100644 --- a/src/uu/numfmt/src/numfmt.rs +++ b/src/uu/numfmt/src/numfmt.rs @@ -158,12 +158,15 @@ fn parse_options(args: &ArgMatches) -> Result { Ok(0) }?; - let fields = match args.get_one::(options::FIELD).unwrap().as_str() { - "-" => vec![Range { + let fields = args.get_one::(options::FIELD).unwrap().as_str(); + // a lone "-" means "all fields", even as part of a list of fields + let fields = if fields.split(',').any(|x| x == "-") { + vec![Range { low: 1, high: std::usize::MAX, - }], - v => Range::from_list(v)?, + }] + } else { + Range::from_list(fields)? }; let format = match args.get_one::(options::FORMAT) { diff --git a/tests/by-util/test_numfmt.rs b/tests/by-util/test_numfmt.rs index bcae09aa3..f4fa94298 100644 --- a/tests/by-util/test_numfmt.rs +++ b/tests/by-util/test_numfmt.rs @@ -401,10 +401,14 @@ fn test_format_selected_field_range() { #[test] fn test_format_all_fields() { - new_ucmd!() - .args(&["--from=auto", "--field", "-", "1K 2K 3K 4K 5K 6K"]) - .succeeds() - .stdout_only("1000 2000 3000 4000 5000 6000\n"); + let all_fields_patterns = vec!["-", "-,3", "3,-", "1,-,3"]; + + for pattern in all_fields_patterns { + new_ucmd!() + .args(&["--from=auto", "--field", pattern, "1K 2K 3K 4K 5K 6K"]) + .succeeds() + .stdout_only("1000 2000 3000 4000 5000 6000\n"); + } } #[test]