diff options
author | Ben Wiederhake <BenWiederhake.GitHub@gmx.de> | 2024-04-01 06:00:15 +0200 |
---|---|---|
committer | Ben Wiederhake <BenWiederhake.GitHub@gmx.de> | 2024-04-14 15:39:46 +0200 |
commit | 27a81f3d32f5f7a1da0f50b851cf384917b05dac (patch) | |
tree | 04e5d3d45b0705d72f239bc9ef14397aebc3b164 | |
parent | d4546ced26e2c75931ab630f8488c9cee86d46ff (diff) |
du: accept shortcuts for stringly-enum arguments
-rw-r--r-- | src/uu/du/src/du.rs | 9 | ||||
-rw-r--r-- | tests/by-util/test_du.rs | 18 |
2 files changed, 17 insertions, 10 deletions
diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index 0de16121a..1935248da 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -4,7 +4,7 @@ // file that was distributed with this source code. use chrono::{DateTime, Local}; -use clap::{crate_version, Arg, ArgAction, ArgMatches, Command}; +use clap::{builder::PossibleValue, crate_version, Arg, ArgAction, ArgMatches, Command}; use glob::Pattern; use std::collections::HashSet; use std::env; @@ -30,6 +30,7 @@ use uucore::error::{set_exit_code, FromIo, UError, UResult, USimpleError}; use uucore::line_ending::LineEnding; use uucore::parse_glob; use uucore::parse_size::{parse_size_u64, ParseSizeError}; +use uucore::shortcut_value_parser::ShortcutValueParser; use uucore::{format_usage, help_about, help_section, help_usage, show, show_error, show_warning}; #[cfg(windows)] use windows_sys::Win32::Foundation::HANDLE; @@ -1040,7 +1041,11 @@ pub fn uu_app() -> Command { .value_name("WORD") .require_equals(true) .num_args(0..) - .value_parser(["atime", "access", "use", "ctime", "status", "birth", "creation"]) + .value_parser(ShortcutValueParser::new([ + PossibleValue::new("atime").alias("access").alias("use"), + PossibleValue::new("ctime").alias("status"), + PossibleValue::new("creation").alias("birth"), + ])) .help( "show time of the last modification of any file in the \ directory, or any of its subdirectories. If WORD is given, show time as WORD instead \ diff --git a/tests/by-util/test_du.rs b/tests/by-util/test_du.rs index dbd2c9c94..2bc694acb 100644 --- a/tests/by-util/test_du.rs +++ b/tests/by-util/test_du.rs @@ -3,7 +3,7 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -// spell-checker:ignore (paths) sublink subwords azerty azeaze xcwww azeaz amaz azea qzerty tazerty tsublink testfile1 testfile2 filelist testdir testfile +// spell-checker:ignore (paths) atim sublink subwords azerty azeaze xcwww azeaz amaz azea qzerty tazerty tsublink testfile1 testfile2 filelist testdir testfile #[cfg(not(windows))] use regex::Regex; @@ -576,13 +576,15 @@ fn test_du_time() { .succeeds(); result.stdout_only("0\t2016-06-16 00:00\tdate_test\n"); - let result = ts - .ucmd() - .env("TZ", "UTC") - .arg("--time=atime") - .arg("date_test") - .succeeds(); - result.stdout_only("0\t2015-05-15 00:00\tdate_test\n"); + for argument in ["--time=atime", "--time=atim", "--time=a"] { + let result = ts + .ucmd() + .env("TZ", "UTC") + .arg(argument) + .arg("date_test") + .succeeds(); + result.stdout_only("0\t2015-05-15 00:00\tdate_test\n"); + } let result = ts .ucmd() |