Skip to content

Commit d943324

Browse files
authored
tee: allow multiple -a flags (#10293)
Fixes issue where tee rejected multiple append flags with error "the argument '--append' cannot be used multiple times". GNU tee accepts multiple -a flags, so this adds compatibility.
1 parent 0333fb5 commit d943324

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/uu/tee/src/tee.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ pub fn uu_app() -> Command {
115115
.long(options::APPEND)
116116
.short('a')
117117
.help(translate!("tee-help-append"))
118-
.action(ArgAction::SetTrue),
118+
.action(ArgAction::SetTrue)
119+
.overrides_with(options::APPEND),
119120
)
120121
.arg(
121122
Arg::new(options::IGNORE_INTERRUPTS)

tests/by-util/test_tee.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,30 @@ fn test_tee_append() {
9191
assert_eq!(at.read(file), content.repeat(2));
9292
}
9393

94+
#[test]
95+
fn test_tee_multiple_append_flags() {
96+
// Test for bug: https://bugs.launchpad.net/ubuntu/+source/rust-coreutils/+bug/2134578
97+
// The command should accept multiple -a flags for different files
98+
let (at, mut ucmd) = at_and_ucmd!();
99+
let content = "don't fail me now rust";
100+
let file1 = "log1";
101+
let file2 = "log2";
102+
103+
// Pre-populate files with some content to verify append behavior
104+
at.write(file1, "existing1\n");
105+
at.write(file2, "existing2\n");
106+
107+
ucmd.args(&["-a", file1, "-a", file2])
108+
.pipe_in(content)
109+
.succeeds()
110+
.stdout_is(content);
111+
112+
assert!(at.file_exists(file1));
113+
assert!(at.file_exists(file2));
114+
assert_eq!(at.read(file1), format!("existing1\n{content}"));
115+
assert_eq!(at.read(file2), format!("existing2\n{content}"));
116+
}
117+
94118
#[test]
95119
fn test_readonly() {
96120
let (at, mut ucmd) = at_and_ucmd!();

0 commit comments

Comments
 (0)