feat: support --files-from/--files0-from

Read NUL- or newline-terminated paths from FILE or stdin.

Wire options through `config` and `main`. Add tests and update the
man page, README, and completion scripts.
This commit is contained in:
Junghyeon Park
2025-08-30 10:38:17 +00:00
committed by andy.boot
parent 14efddfd05
commit 7974e2eaf0
15 changed files with 137 additions and 39 deletions
View File
Binary file not shown.
+2
View File
@@ -0,0 +1,2 @@
tests/test_dir_files_from/a_file
tests/test_dir_files_from/hello_file
+1
View File
@@ -0,0 +1 @@
hello
+42
View File
@@ -104,6 +104,48 @@ pub fn test_ignore_all_in_file() {
assert!(!output.contains(".secret"));
}
#[test]
pub fn test_files_from_flag_file() {
let output = build_command(vec!["--files-from", "tests/test_dir_files_from/files_from.txt"]);
assert!(output.contains("a_file"));
assert!(output.contains("hello_file"));
}
#[test]
pub fn test_files0_from_flag_file() {
let output = build_command(vec!["--files0-from", "tests/test_dir_files_from/files0_from.txt"]);
assert!(output.contains("a_file"));
assert!(output.contains("hello_file"));
}
#[test]
pub fn test_files_from_flag_stdin() {
let mut cmd = Command::cargo_bin("dust").unwrap();
cmd.arg("-P").arg("--files-from").arg("-");
let input = b"tests/test_dir_files_from/a_file\ntests/test_dir_files_from/hello_file\n";
cmd.write_stdin(input.as_ref());
let finished = &cmd.unwrap();
let stderr = std::str::from_utf8(&finished.stderr).unwrap();
assert_eq!(stderr, "");
let output = std::str::from_utf8(&finished.stdout).unwrap();
assert!(output.contains("a_file"));
assert!(output.contains("hello_file"));
}
#[test]
pub fn test_files0_from_flag_stdin() {
let mut cmd = Command::cargo_bin("dust").unwrap();
cmd.arg("-P").arg("--files0-from").arg("-");
let input = b"tests/test_dir_files_from/a_file\0tests/test_dir_files_from/hello_file\0";
cmd.write_stdin(input.as_ref());
let finished = &cmd.unwrap();
let stderr = std::str::from_utf8(&finished.stderr).unwrap();
assert_eq!(stderr, "");
let output = std::str::from_utf8(&finished.stdout).unwrap();
assert!(output.contains("a_file"));
assert!(output.contains("hello_file"));
}
#[test]
pub fn test_with_bad_param() {
let mut cmd = Command::cargo_bin("dust").unwrap();