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

tee: accept shortcuts for stringly-enum arguments

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

View file

@ -9,6 +9,7 @@ use std::io::{copy, stdin, stdout, Error, ErrorKind, Read, Result, Write};
use std::path::PathBuf; use std::path::PathBuf;
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::UResult; use uucore::error::UResult;
use uucore::shortcut_value_parser::ShortcutValueParser;
use uucore::{format_usage, help_about, help_section, help_usage, show_error}; use uucore::{format_usage, help_about, help_section, help_usage, show_error};
// spell-checker:ignore nopipe // spell-checker:ignore nopipe
@ -119,7 +120,7 @@ pub fn uu_app() -> Command {
.long(options::OUTPUT_ERROR) .long(options::OUTPUT_ERROR)
.require_equals(true) .require_equals(true)
.num_args(0..=1) .num_args(0..=1)
.value_parser([ .value_parser(ShortcutValueParser::new([
PossibleValue::new("warn") PossibleValue::new("warn")
.help("produce warnings for errors writing to any output"), .help("produce warnings for errors writing to any output"),
PossibleValue::new("warn-nopipe") 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").help("exit on write errors to any output"),
PossibleValue::new("exit-nopipe") 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("exit on write errors to any output that are not pipe errors (equivalent to exit on non-unix platforms)"),
]) ]))
.help("set write error behavior") .help("set write error behavior")
.conflicts_with(options::IGNORE_PIPE_ERRORS), .conflicts_with(options::IGNORE_PIPE_ERRORS),
) )

View file

@ -311,6 +311,23 @@ mod linux_only {
expect_correct(file_out_a, &at, content.as_str()); 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] #[test]
fn test_pipe_error_warn() { fn test_pipe_error_warn() {
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
@ -362,6 +379,23 @@ mod linux_only {
expect_correct(file_out_a, &at, content.as_str()); 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] #[test]
fn test_space_error_default() { fn test_space_error_default() {
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();