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

tail: accept shortcuts for stringly-enum arguments

This commit is contained in:
Ben Wiederhake 2024-04-01 08:06:18 +02:00
parent 872ec050e4
commit 88a2ea4f3b
2 changed files with 31 additions and 27 deletions

View file

@ -16,6 +16,7 @@ use std::io::IsTerminal;
use std::time::Duration; use std::time::Duration;
use uucore::error::{UResult, USimpleError, UUsageError}; use uucore::error::{UResult, USimpleError, UUsageError};
use uucore::parse_size::{parse_size_u64, ParseSizeError}; use uucore::parse_size::{parse_size_u64, ParseSizeError};
use uucore::shortcut_value_parser::ShortcutValueParser;
use uucore::{format_usage, help_about, help_usage, show_warning}; use uucore::{format_usage, help_about, help_usage, show_warning};
const ABOUT: &str = help_about!("tail.md"); const ABOUT: &str = help_about!("tail.md");
@ -494,7 +495,7 @@ pub fn uu_app() -> Command {
.default_missing_value("descriptor") .default_missing_value("descriptor")
.num_args(0..=1) .num_args(0..=1)
.require_equals(true) .require_equals(true)
.value_parser(["descriptor", "name"]) .value_parser(ShortcutValueParser::new(["descriptor", "name"]))
.overrides_with(options::FOLLOW) .overrides_with(options::FOLLOW)
.help("Print the file as it grows"), .help("Print the file as it grows"),
) )

View file

@ -533,37 +533,40 @@ fn test_follow_multiple() {
#[test] #[test]
#[cfg(not(target_os = "windows"))] // FIXME: test times out #[cfg(not(target_os = "windows"))] // FIXME: test times out
fn test_follow_name_multiple() { fn test_follow_name_multiple() {
let (at, mut ucmd) = at_and_ucmd!(); // spell-checker:disable-next-line
let mut child = ucmd for argument in ["--follow=name", "--follo=nam", "--f=n"] {
.arg("--follow=name") let (at, mut ucmd) = at_and_ucmd!();
.arg(FOOBAR_TXT) let mut child = ucmd
.arg(FOOBAR_2_TXT) .arg(argument)
.run_no_wait(); .arg(FOOBAR_TXT)
.arg(FOOBAR_2_TXT)
.run_no_wait();
child child
.make_assertion_with_delay(500) .make_assertion_with_delay(500)
.is_alive() .is_alive()
.with_current_output() .with_current_output()
.stdout_only_fixture("foobar_follow_multiple.expected"); .stdout_only_fixture("foobar_follow_multiple.expected");
let first_append = "trois\n"; let first_append = "trois\n";
at.append(FOOBAR_2_TXT, first_append); at.append(FOOBAR_2_TXT, first_append);
child child
.make_assertion_with_delay(DEFAULT_SLEEP_INTERVAL_MILLIS) .make_assertion_with_delay(DEFAULT_SLEEP_INTERVAL_MILLIS)
.with_current_output() .with_current_output()
.stdout_only(first_append); .stdout_only(first_append);
let second_append = "twenty\nthirty\n"; let second_append = "twenty\nthirty\n";
at.append(FOOBAR_TXT, second_append); at.append(FOOBAR_TXT, second_append);
child child
.make_assertion_with_delay(DEFAULT_SLEEP_INTERVAL_MILLIS) .make_assertion_with_delay(DEFAULT_SLEEP_INTERVAL_MILLIS)
.with_current_output() .with_current_output()
.stdout_only_fixture("foobar_follow_multiple_appended.expected"); .stdout_only_fixture("foobar_follow_multiple_appended.expected");
child.make_assertion().is_alive(); child.make_assertion().is_alive();
child.kill(); child.kill();
}
} }
#[test] #[test]
@ -844,7 +847,7 @@ fn test_follow_missing() {
// Ensure that --follow=name does not imply --retry. // Ensure that --follow=name does not imply --retry.
// Ensure that --follow={descriptor,name} (without --retry) does *not wait* for the // Ensure that --follow={descriptor,name} (without --retry) does *not wait* for the
// file to appear. // file to appear.
for follow_mode in &["--follow=descriptor", "--follow=name"] { for follow_mode in &["--follow=descriptor", "--follow=name", "--fo=d", "--fo=n"] {
new_ucmd!() new_ucmd!()
.arg(follow_mode) .arg(follow_mode)
.arg("missing") .arg("missing")