Skip to content

Commit 3691a7a

Browse files
du: accept --exclude, --exclude-from and --files0-from values starting with '-'
1 parent cff9485 commit 3691a7a

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

‎src/uu/du/src/du.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,7 @@ pub fn uu_app() -> Command {
16391639
Arg::new(options::EXCLUDE)
16401640
.long(options::EXCLUDE)
16411641
.value_name("PATTERN")
1642+
.allow_hyphen_values(true)
16421643
.help(translate!("du-help-exclude"))
16431644
.action(ArgAction::Append),
16441645
)
@@ -1648,6 +1649,7 @@ pub fn uu_app() -> Command {
16481649
.long("exclude-from")
16491650
.value_name("FILE")
16501651
.value_hint(clap::ValueHint::FilePath)
1652+
.allow_hyphen_values(true)
16511653
.help(translate!("du-help-exclude-from"))
16521654
.action(ArgAction::Append),
16531655
)
@@ -1657,6 +1659,7 @@ pub fn uu_app() -> Command {
16571659
.value_name("FILE")
16581660
.value_hint(clap::ValueHint::FilePath)
16591661
.value_parser(clap::value_parser!(OsString))
1662+
.allow_hyphen_values(true)
16601663
.help(translate!("du-help-files0-from"))
16611664
.action(ArgAction::Append),
16621665
)

‎tests/by-util/test_du.rs‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,6 +2104,40 @@ fn test_du_exclude_invalid_syntax() {
21042104
.stderr_contains("du: Invalid exclude syntax");
21052105
}
21062106

2107+
#[test]
2108+
fn test_du_option_values_starting_with_hyphen() {
2109+
let ts = TestScenario::new(util_name!());
2110+
let at = &ts.fixtures;
2111+
2112+
at.mkdir("dir");
2113+
at.write("dir/-skip", "content");
2114+
at.write("dir/keep", "content");
2115+
at.write("-patterns", "-skip\n");
2116+
at.write("-list", "dir/keep\0");
2117+
2118+
ts.ucmd()
2119+
.args(&["-a", "--exclude", "-skip", "dir"])
2120+
.succeeds()
2121+
.stdout_contains("keep")
2122+
.stdout_does_not_contain("-skip");
2123+
2124+
ts.ucmd()
2125+
.args(&["-a", "-X", "-patterns", "dir"])
2126+
.succeeds()
2127+
.stdout_contains("keep")
2128+
.stdout_does_not_contain("-skip");
2129+
2130+
ts.ucmd()
2131+
.args(&["-a", "--exclude-from", "-patterns", "dir"])
2132+
.succeeds()
2133+
.stdout_does_not_contain("-skip");
2134+
2135+
ts.ucmd()
2136+
.args(&["--files0-from", "-list"])
2137+
.succeeds()
2138+
.stdout_contains("keep");
2139+
}
2140+
21072141
#[test]
21082142
fn test_du_exclude_from_nonexistent_file() {
21092143
new_ucmd!()

0 commit comments

Comments
 (0)