1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

numfmt: accept shortcuts for stringly-enum arguments

This commit is contained in:
Ben Wiederhake 2024-04-01 08:06:18 +02:00
parent 3877d14504
commit 2646944bee
2 changed files with 12 additions and 1 deletions

View file

@ -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)

View file

@ -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(&[