From 1dd7d8e0dbf6739ffd0b9c39c31cb6bf6311c08e Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Mon, 1 Apr 2024 08:06:18 +0200 Subject: [PATCH] od: accept shortcuts for stringly-enum arguments --- src/uu/od/src/od.rs | 3 ++- tests/by-util/test_od.rs | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/uu/od/src/od.rs b/src/uu/od/src/od.rs index 769dae98e..1c9548f50 100644 --- a/src/uu/od/src/od.rs +++ b/src/uu/od/src/od.rs @@ -43,6 +43,7 @@ use clap::{crate_version, parser::ValueSource, Arg, ArgMatches, Command}; use uucore::display::Quotable; use uucore::error::{UResult, USimpleError}; use uucore::parse_size::ParseSizeError; +use uucore::shortcut_value_parser::ShortcutValueParser; use uucore::{format_usage, help_about, help_section, help_usage, show_error, show_warning}; const PEEK_BUFFER_SIZE: usize = 4; // utf-8 can be 4 bytes @@ -287,7 +288,7 @@ pub fn uu_app() -> Command { Arg::new(options::ENDIAN) .long(options::ENDIAN) .help("byte order to use for multi-byte formats") - .value_parser(["big", "little"]) + .value_parser(ShortcutValueParser::new(["big", "little"])) .value_name("big|little"), ) .arg( diff --git a/tests/by-util/test_od.rs b/tests/by-util/test_od.rs index 78c4e1b04..569d096c1 100644 --- a/tests/by-util/test_od.rs +++ b/tests/by-util/test_od.rs @@ -53,6 +53,20 @@ fn test_file() { .no_stderr() .stdout_is(unindent(ALPHA_OUT)); + new_ucmd!() + .arg("--endian=littl") // spell-checker:disable-line + .arg(file.as_os_str()) + .succeeds() + .no_stderr() + .stdout_is(unindent(ALPHA_OUT)); + + new_ucmd!() + .arg("--endian=l") + .arg(file.as_os_str()) + .succeeds() + .no_stderr() + .stdout_is(unindent(ALPHA_OUT)); + // Ensure that default format matches `-t o2`, and that `-t` does not absorb file argument new_ucmd!() .arg("--endian=little") @@ -463,6 +477,16 @@ fn test_big_endian() { .run_piped_stdin(&input[..]) .no_stderr() .success() + .stdout_is(&expected_output); + new_ucmd!() + .arg("--endian=b") + .arg("-F") + .arg("-f") + .arg("-X") + .arg("-x") + .run_piped_stdin(&input[..]) + .no_stderr() + .success() .stdout_is(expected_output); }