From 27a81f3d32f5f7a1da0f50b851cf384917b05dac Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Mon, 1 Apr 2024 06:00:15 +0200 Subject: [PATCH] du: accept shortcuts for stringly-enum arguments --- src/uu/du/src/du.rs | 9 +++++++-- 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()