From 2646944bee98fc65c9af16b67a5b312560c27867 Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Mon, 1 Apr 2024 08:06:18 +0200 Subject: [PATCH] numfmt: accept shortcuts for stringly-enum arguments --- src/uu/numfmt/src/numfmt.rs | 9 ++++++++- tests/by-util/test_numfmt.rs | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/uu/numfmt/src/numfmt.rs b/src/uu/numfmt/src/numfmt.rs index 80a2051bd..2b9932ee5 100644 --- a/src/uu/numfmt/src/numfmt.rs +++ b/src/uu/numfmt/src/numfmt.rs @@ -15,6 +15,7 @@ use units::{IEC_BASES, SI_BASES}; use uucore::display::Quotable; use uucore::error::UResult; use uucore::ranges::Range; +use uucore::shortcut_value_parser::ShortcutValueParser; use uucore::{format_usage, help_about, help_section, help_usage, show, show_error}; pub mod errors; @@ -340,7 +341,13 @@ pub fn uu_app() -> Command { .help("use METHOD for rounding when scaling") .value_name("METHOD") .default_value("from-zero") - .value_parser(["up", "down", "from-zero", "towards-zero", "nearest"]), + .value_parser(ShortcutValueParser::new([ + "up", + "down", + "from-zero", + "towards-zero", + "nearest", + ])), ) .arg( Arg::new(options::SUFFIX) diff --git a/tests/by-util/test_numfmt.rs b/tests/by-util/test_numfmt.rs index bb80502d5..1dddedfdd 100644 --- a/tests/by-util/test_numfmt.rs +++ b/tests/by-util/test_numfmt.rs @@ -550,10 +550,14 @@ fn test_delimiter_with_padding_and_fields() { fn test_round() { for (method, exp) in [ ("from-zero", ["9.1K", "-9.1K", "9.1K", "-9.1K"]), + ("from-zer", ["9.1K", "-9.1K", "9.1K", "-9.1K"]), // spell-checker:disable-line + ("f", ["9.1K", "-9.1K", "9.1K", "-9.1K"]), ("towards-zero", ["9.0K", "-9.0K", "9.0K", "-9.0K"]), ("up", ["9.1K", "-9.0K", "9.1K", "-9.0K"]), ("down", ["9.0K", "-9.1K", "9.0K", "-9.1K"]), ("nearest", ["9.0K", "-9.0K", "9.1K", "-9.1K"]), + ("near", ["9.0K", "-9.0K", "9.1K", "-9.1K"]), + ("n", ["9.0K", "-9.0K", "9.1K", "-9.1K"]), ] { new_ucmd!() .args(&[