From a699bfd1fb186b48962436f4b46e09829f28de53 Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Mon, 1 Apr 2024 08:06:18 +0200 Subject: [PATCH] uniq: accept shortcuts for stringly-enum arguments --- src/uu/uniq/src/uniq.rs | 9 +++--- tests/by-util/test_uniq.rs | 60 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/src/uu/uniq/src/uniq.rs b/src/uu/uniq/src/uniq.rs index 2c4f9b781..4084a7b3f 100644 --- a/src/uu/uniq/src/uniq.rs +++ b/src/uu/uniq/src/uniq.rs @@ -14,6 +14,7 @@ use std::num::IntErrorKind; use uucore::display::Quotable; use uucore::error::{FromIo, UError, UResult, USimpleError}; use uucore::posix::{posix_version, OBSOLETE}; +use uucore::shortcut_value_parser::ShortcutValueParser; use uucore::{format_usage, help_about, help_section, help_usage}; const ABOUT: &str = help_about!("uniq.md"); @@ -609,11 +610,11 @@ pub fn uu_app() -> Command { Arg::new(options::ALL_REPEATED) .short('D') .long(options::ALL_REPEATED) - .value_parser([ + .value_parser(ShortcutValueParser::new([ "none", "prepend", "separate" - ]) + ])) .help("print all duplicate lines. Delimiting is done with blank lines. [default: none]") .value_name("delimit-method") .num_args(0..=1) @@ -623,12 +624,12 @@ pub fn uu_app() -> Command { .arg( Arg::new(options::GROUP) .long(options::GROUP) - .value_parser([ + .value_parser(ShortcutValueParser::new([ "separate", "prepend", "append", "both", - ]) + ])) .help("show all items, separating groups with an empty line. [default: separate]") .value_name("group-method") .num_args(0..=1) diff --git a/tests/by-util/test_uniq.rs b/tests/by-util/test_uniq.rs index 911f14490..8585ebd83 100644 --- a/tests/by-util/test_uniq.rs +++ b/tests/by-util/test_uniq.rs @@ -145,6 +145,21 @@ fn test_stdin_all_repeated() { .pipe_in_fixture(INPUT) .run() .stdout_is_fixture("sorted-all-repeated.expected"); + new_ucmd!() + .args(&["--all-repeated=none"]) + .pipe_in_fixture(INPUT) + .run() + .stdout_is_fixture("sorted-all-repeated.expected"); + new_ucmd!() + .args(&["--all-repeated=non"]) + .pipe_in_fixture(INPUT) + .run() + .stdout_is_fixture("sorted-all-repeated.expected"); + new_ucmd!() + .args(&["--all-repeated=n"]) + .pipe_in_fixture(INPUT) + .run() + .stdout_is_fixture("sorted-all-repeated.expected"); } #[test] @@ -167,6 +182,16 @@ fn test_stdin_all_repeated_separate() { .pipe_in_fixture(INPUT) .run() .stdout_is_fixture("sorted-all-repeated-separate.expected"); + new_ucmd!() + .args(&["--all-repeated=separat"]) // spell-checker:disable-line + .pipe_in_fixture(INPUT) + .run() + .stdout_is_fixture("sorted-all-repeated-separate.expected"); + new_ucmd!() + .args(&["--all-repeated=s"]) + .pipe_in_fixture(INPUT) + .run() + .stdout_is_fixture("sorted-all-repeated-separate.expected"); } #[test] @@ -176,6 +201,16 @@ fn test_stdin_all_repeated_prepend() { .pipe_in_fixture(INPUT) .run() .stdout_is_fixture("sorted-all-repeated-prepend.expected"); + new_ucmd!() + .args(&["--all-repeated=prepen"]) // spell-checker:disable-line + .pipe_in_fixture(INPUT) + .run() + .stdout_is_fixture("sorted-all-repeated-prepend.expected"); + new_ucmd!() + .args(&["--all-repeated=p"]) + .pipe_in_fixture(INPUT) + .run() + .stdout_is_fixture("sorted-all-repeated-prepend.expected"); } #[test] @@ -253,6 +288,11 @@ fn test_group_prepend() { .pipe_in_fixture(INPUT) .run() .stdout_is_fixture("group-prepend.expected"); + new_ucmd!() + .args(&["--group=p"]) + .pipe_in_fixture(INPUT) + .run() + .stdout_is_fixture("group-prepend.expected"); } #[test] @@ -262,6 +302,11 @@ fn test_group_append() { .pipe_in_fixture(INPUT) .run() .stdout_is_fixture("group-append.expected"); + new_ucmd!() + .args(&["--group=a"]) + .pipe_in_fixture(INPUT) + .run() + .stdout_is_fixture("group-append.expected"); } #[test] @@ -271,6 +316,16 @@ fn test_group_both() { .pipe_in_fixture(INPUT) .run() .stdout_is_fixture("group-both.expected"); + new_ucmd!() + .args(&["--group=bot"]) + .pipe_in_fixture(INPUT) + .run() + .stdout_is_fixture("group-both.expected"); + new_ucmd!() + .args(&["--group=b"]) + .pipe_in_fixture(INPUT) + .run() + .stdout_is_fixture("group-both.expected"); } #[test] @@ -280,6 +335,11 @@ fn test_group_separate() { .pipe_in_fixture(INPUT) .run() .stdout_is_fixture("group.expected"); + new_ucmd!() + .args(&["--group=s"]) + .pipe_in_fixture(INPUT) + .run() + .stdout_is_fixture("group.expected"); } #[test]