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

od: accept shortcuts for stringly-enum arguments

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

View file

@ -43,6 +43,7 @@ use clap::{crate_version, parser::ValueSource, Arg, ArgMatches, Command};
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError}; use uucore::error::{UResult, USimpleError};
use uucore::parse_size::ParseSizeError; 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}; 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 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) Arg::new(options::ENDIAN)
.long(options::ENDIAN) .long(options::ENDIAN)
.help("byte order to use for multi-byte formats") .help("byte order to use for multi-byte formats")
.value_parser(["big", "little"]) .value_parser(ShortcutValueParser::new(["big", "little"]))
.value_name("big|little"), .value_name("big|little"),
) )
.arg( .arg(

View file

@ -53,6 +53,20 @@ fn test_file() {
.no_stderr() .no_stderr()
.stdout_is(unindent(ALPHA_OUT)); .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 // Ensure that default format matches `-t o2`, and that `-t` does not absorb file argument
new_ucmd!() new_ucmd!()
.arg("--endian=little") .arg("--endian=little")
@ -463,6 +477,16 @@ fn test_big_endian() {
.run_piped_stdin(&input[..]) .run_piped_stdin(&input[..])
.no_stderr() .no_stderr()
.success() .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); .stdout_is(expected_output);
} }