fix -l and -L to be mutually exclusive so that last one wins (#30)

This commit is contained in:
rifatx
2026-06-04 22:14:12 +02:00
committed by GitHub
parent 4e6823a8b3
commit f4798cb6d0
2 changed files with 23 additions and 2 deletions
+4 -2
View File
@@ -707,14 +707,16 @@ pub fn uu_app() -> Command {
.short('L')
.long("files-without-match")
.help("print only names of FILEs with no selected lines")
.action(ArgAction::SetTrue),
.action(ArgAction::SetTrue)
.overrides_with("files_with_matches"),
)
.arg(
Arg::new("files_with_matches")
.short('l')
.long("files-with-matches")
.help("print only names of FILEs with selected lines")
.action(ArgAction::SetTrue),
.action(ArgAction::SetTrue)
.overrides_with("files_without_match"),
)
.arg(
Arg::new("count")
+19
View File
@@ -460,6 +460,25 @@ fn files_with_and_without_matches() {
.stdout_only("many\n");
}
#[test]
fn files_with_and_without_matches_mutually_exclusive() {
// Test that -l and -L are mutually exclusive with last-one-wins semantics
let (scene, mut c) = ucmd();
scene.fixtures.write("file", "match\n");
// -l -L: last flag (-L) wins, so no output (file has match, -L excludes it)
c.args(&["-l", "-L", "match", "file"])
.succeeds()
.stdout_only("");
// -L -l: last flag (-l) wins, so filename is printed
let (scene, mut c) = ucmd();
scene.fixtures.write("file", "match\n");
c.args(&["-L", "-l", "match", "file"])
.succeeds()
.stdout_only("file\n");
}
#[test]
fn count_combined_with_listing_flags() {
let (scene, _) = ucmd();