Merge pull request #50 from michaelmior/print0
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Add --print0 option
authored by David Peter · committed by GitHub · parents 1586d65, 1b0c8f3 · Browse files · 2 files·+23 added−3 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+23 added−3 removed
- tests:+4 added−1 removed
- other:+19 added−2 removed
Provenance
- Commit
10ea476- Tree
3aa2baa- Author
David Peter <sharkdp@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent 1
1586d65- Parent 2
1b0c8f3
2 files changed+23 added−3 removed
modified:src/main.rs+19 added-2 removed
51 unmodified lines52 53 /// Whether to follow symlinks or not.54 follow_links: bool,55 56+ /// Whether elements of output should be separated by a null character57+ zero: bool,58+59 /// The maximum search depth, or `None` if no maximum search depth should be set.60 ///61 /// A depth of `1` includes all files under the current directory, a depth of `2` also includes62 /// all files under subdirectories of the current directory, etc.82 unmodified lines145 let sep = std::path::MAIN_SEPARATOR.to_string();146 print!("{}", style.paint(sep));147 }148 }149+ if config.zero {150+ print!("{}", '\0');151+ } else {146- println!();152+ println!();153+ }154 } else {155 // Uncolorized output156 157 let prefix = if config.path_display == PathDisplay::Absolute { ROOT_DIR } else { "" };158+ let separator = if config.zero {159+ "\0"160+ } else {161+ "\n"162+ };163 152- let r = writeln!(&mut std::io::stdout(), "{}{}", prefix, path_str);164+ let r = write!(&mut std::io::stdout(), "{}{}{}", prefix, path_str, separator);165 166 if r.is_err() {167 // Probably a broken pipe. Exit gracefully.168 process::exit(0);72 unmodified lines241 .arg(Arg::with_name("follow")242 .long("follow")243 .short("f")244 .help("Follow symlinks"))245+ .arg(Arg::with_name("zero")246+ .long("print0")247+ .short("0")248+ .help("Separate each path by the null character"))249 .arg(Arg::with_name("absolute-path")250 .long("absolute-path")251 .short("a")252 .help("Show absolute instead of relative paths"))68 unmodified lines321 search_full_path: matches.is_present("full-path"),322 ignore_hidden: !matches.is_present("hidden"),323 read_ignore: !matches.is_present("no-ignore"),324 follow_links: matches.is_present("follow"),325+ zero: matches.is_present("zero"),326 max_depth: matches.value_of("depth")327 .and_then(|ds| usize::from_str_radix(ds, 10).ok()),328 path_display: if matches.is_present("absolute-path") || root_dir_is_absolute {329 PathDisplay::Absolute19 unmodified linesmodified:tests/test.sh+4 added-1 removed
30 unmodified lines31 tmp_output="$(mktemp -t "$MKTEMP_TEMPLATE")"32 33 echo "$expected_output" > "$tmp_expected"34 35- "$fd" "$@" | sort -f > "$tmp_output"35+ "$fd" "$@" | xargs -0 echo -n | sort -f > "$tmp_output"36 37 echo -ne " ${bold}▶${reset} Testing 'fd $*' ... "38 39 if diff -q "$tmp_expected" "$tmp_output" > /dev/null; then140 unmodified lines180 one/two/C.Foo2181 symlink/c.foo182 symlink/C.Foo2" --follow c.foo183 184+suite "Null separator (--print0)"185+expect "one/two/C.Foo2 one/two/c.foo one/two/three/d.foo one/two/three/directory_foo one/b.foo a.foo" --print0 foo186 187+188 suite "Maximum depth (--max-depth)"189 expect "a.foo190 one191 one/b.foo39 unmodified lines