Skip to content
Myr

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

2 files+23 added−3 removed

modified:src/main.rs+19 added-2 removed
51 unmodified lines
5253 /// Whether to follow symlinks or not.54 follow_links: bool,5556 /// Whether elements of output should be separated by a null character57 zero: bool,5859 /// 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 lines
145 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 output156157 let prefix = if config.path_display == PathDisplay::Absolute { ROOT_DIR } else { "" };158 let separator = if config.zero {159 "\0"160 } else {161 "\n"162 };163152 let r = writeln!(&mut std::io::stdout(), "{}{}", prefix, path_str);164 let r = write!(&mut std::io::stdout(), "{}{}{}", prefix, path_str, separator);165166 if r.is_err() {167 // Probably a broken pipe. Exit gracefully.168 process::exit(0);
72 unmodified lines
241 .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 lines
321 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::Absolute
19 unmodified lines
modified:tests/test.sh+4 added-1 removed
30 unmodified lines
31 tmp_output="$(mktemp -t "$MKTEMP_TEMPLATE")"3233 echo "$expected_output" > "$tmp_expected"3435 "$fd" "$@" | sort -f > "$tmp_output"35 "$fd" "$@" | xargs -0 echo -n | sort -f > "$tmp_output"3637 echo -ne " ${bold}▶${reset} Testing 'fd $*' ... "3839 if diff -q "$tmp_expected" "$tmp_output" > /dev/null; then
140 unmodified lines
180one/two/C.Foo2181symlink/c.foo182symlink/C.Foo2" --follow c.foo183184suite "Null separator (--print0)"185expect "one/two/C.Foo2 one/two/c.foo one/two/three/d.foo one/two/three/directory_foo one/b.foo a.foo" --print0 foo186187188suite "Maximum depth (--max-depth)"189expect "a.foo190one191one/b.foo
39 unmodified lines