diff --git a/src/uu/tee/src/tee.rs b/src/uu/tee/src/tee.rs index b1443dbb9..2cf693af6 100644 --- a/src/uu/tee/src/tee.rs +++ b/src/uu/tee/src/tee.rs @@ -9,6 +9,7 @@ use std::io::{copy, stdin, stdout, Error, ErrorKind, Read, Result, Write}; use std::path::PathBuf; use uucore::display::Quotable; use uucore::error::UResult; +use uucore::shortcut_value_parser::ShortcutValueParser; use uucore::{format_usage, help_about, help_section, help_usage, show_error}; // spell-checker:ignore nopipe @@ -119,7 +120,7 @@ pub fn uu_app() -> Command { .long(options::OUTPUT_ERROR) .require_equals(true) .num_args(0..=1) - .value_parser([ + .value_parser(ShortcutValueParser::new([ PossibleValue::new("warn") .help("produce warnings for errors writing to any output"), PossibleValue::new("warn-nopipe") @@ -127,7 +128,7 @@ pub fn uu_app() -> Command { PossibleValue::new("exit").help("exit on write errors to any output"), PossibleValue::new("exit-nopipe") .help("exit on write errors to any output that are not pipe errors (equivalent to exit on non-unix platforms)"), - ]) + ])) .help("set write error behavior") .conflicts_with(options::IGNORE_PIPE_ERRORS), ) diff --git a/tests/by-util/test_tee.rs b/tests/by-util/test_tee.rs index 9ff4ea7dc..8b94fe77f 100644 --- a/tests/by-util/test_tee.rs +++ b/tests/by-util/test_tee.rs @@ -311,6 +311,23 @@ mod linux_only { expect_correct(file_out_a, &at, content.as_str()); } + #[test] + fn test_pipe_error_warn_nopipe_3_shortcut() { + let (at, mut ucmd) = at_and_ucmd!(); + + let file_out_a = "tee_file_out_a"; + + let proc = ucmd + .arg("--output-error=warn-") + .arg(file_out_a) + .set_stdout(make_broken_pipe()); + + let (content, output) = run_tee(proc); + + expect_success(&output); + expect_correct(file_out_a, &at, content.as_str()); + } + #[test] fn test_pipe_error_warn() { let (at, mut ucmd) = at_and_ucmd!(); @@ -362,6 +379,23 @@ mod linux_only { expect_correct(file_out_a, &at, content.as_str()); } + #[test] + fn test_pipe_error_exit_nopipe_shortcut() { + let (at, mut ucmd) = at_and_ucmd!(); + + let file_out_a = "tee_file_out_a"; + + let proc = ucmd + .arg("--output-error=exit-nop") + .arg(file_out_a) + .set_stdout(make_broken_pipe()); + + let (content, output) = run_tee(proc); + + expect_success(&output); + expect_correct(file_out_a, &at, content.as_str()); + } + #[test] fn test_space_error_default() { let (at, mut ucmd) = at_and_ucmd!();