mirror of
https://github.com/sharkdp/fd.git
synced 2024-09-29 21:41:30 +02:00
Rename config parameter for print0 and fix sorting in tests
This commit is contained in:
parent
10ea476e31
commit
2d1d24c38c
16
src/main.rs
16
src/main.rs
@ -54,7 +54,7 @@ struct FdOptions {
|
|||||||
follow_links: bool,
|
follow_links: bool,
|
||||||
|
|
||||||
/// Whether elements of output should be separated by a null character
|
/// Whether elements of output should be separated by a null character
|
||||||
zero: bool,
|
null_separator: bool,
|
||||||
|
|
||||||
/// The maximum search depth, or `None` if no maximum search depth should be set.
|
/// The maximum search depth, or `None` if no maximum search depth should be set.
|
||||||
///
|
///
|
||||||
@ -146,7 +146,7 @@ fn print_entry(base: &Path, entry: &Path, config: &FdOptions) {
|
|||||||
print!("{}", style.paint(sep));
|
print!("{}", style.paint(sep));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if config.zero {
|
if config.null_separator {
|
||||||
print!("{}", '\0');
|
print!("{}", '\0');
|
||||||
} else {
|
} else {
|
||||||
println!();
|
println!();
|
||||||
@ -155,11 +155,7 @@ fn print_entry(base: &Path, entry: &Path, config: &FdOptions) {
|
|||||||
// Uncolorized output
|
// Uncolorized output
|
||||||
|
|
||||||
let prefix = if config.path_display == PathDisplay::Absolute { ROOT_DIR } else { "" };
|
let prefix = if config.path_display == PathDisplay::Absolute { ROOT_DIR } else { "" };
|
||||||
let separator = if config.zero {
|
let separator = if config.null_separator { "\0" } else { "\n" };
|
||||||
"\0"
|
|
||||||
} else {
|
|
||||||
"\n"
|
|
||||||
};
|
|
||||||
|
|
||||||
let r = write!(&mut std::io::stdout(), "{}{}{}", prefix, path_str, separator);
|
let r = write!(&mut std::io::stdout(), "{}{}{}", prefix, path_str, separator);
|
||||||
|
|
||||||
@ -242,10 +238,10 @@ fn main() {
|
|||||||
.long("follow")
|
.long("follow")
|
||||||
.short("f")
|
.short("f")
|
||||||
.help("Follow symlinks"))
|
.help("Follow symlinks"))
|
||||||
.arg(Arg::with_name("zero")
|
.arg(Arg::with_name("null_separator")
|
||||||
.long("print0")
|
.long("print0")
|
||||||
.short("0")
|
.short("0")
|
||||||
.help("Separate each path by the null character"))
|
.help("Separate results by the null character"))
|
||||||
.arg(Arg::with_name("absolute-path")
|
.arg(Arg::with_name("absolute-path")
|
||||||
.long("absolute-path")
|
.long("absolute-path")
|
||||||
.short("a")
|
.short("a")
|
||||||
@ -322,7 +318,7 @@ fn main() {
|
|||||||
ignore_hidden: !matches.is_present("hidden"),
|
ignore_hidden: !matches.is_present("hidden"),
|
||||||
read_ignore: !matches.is_present("no-ignore"),
|
read_ignore: !matches.is_present("no-ignore"),
|
||||||
follow_links: matches.is_present("follow"),
|
follow_links: matches.is_present("follow"),
|
||||||
zero: matches.is_present("zero"),
|
null_separator: matches.is_present("null_separator"),
|
||||||
max_depth: matches.value_of("depth")
|
max_depth: matches.value_of("depth")
|
||||||
.and_then(|ds| usize::from_str_radix(ds, 10).ok()),
|
.and_then(|ds| usize::from_str_radix(ds, 10).ok()),
|
||||||
path_display: if matches.is_present("absolute-path") || root_dir_is_absolute {
|
path_display: if matches.is_present("absolute-path") || root_dir_is_absolute {
|
||||||
|
@ -32,7 +32,7 @@ expect() {
|
|||||||
|
|
||||||
echo "$expected_output" > "$tmp_expected"
|
echo "$expected_output" > "$tmp_expected"
|
||||||
|
|
||||||
"$fd" "$@" | xargs -0 echo -n | sort -f > "$tmp_output"
|
"$fd" "$@" | sed -e 's/\x0/NULL\n/g' | sort -f > "$tmp_output"
|
||||||
|
|
||||||
echo -ne " ${bold}▶${reset} Testing 'fd $*' ... "
|
echo -ne " ${bold}▶${reset} Testing 'fd $*' ... "
|
||||||
|
|
||||||
@ -182,7 +182,12 @@ symlink/c.foo
|
|||||||
symlink/C.Foo2" --follow c.foo
|
symlink/C.Foo2" --follow c.foo
|
||||||
|
|
||||||
suite "Null separator (--print0)"
|
suite "Null separator (--print0)"
|
||||||
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 foo
|
expect "a.fooNULL
|
||||||
|
one/b.fooNULL
|
||||||
|
one/two/C.Foo2NULL
|
||||||
|
one/two/c.fooNULL
|
||||||
|
one/two/three/d.fooNULL
|
||||||
|
one/two/three/directory_fooNULL" --print0 foo
|
||||||
|
|
||||||
|
|
||||||
suite "Maximum depth (--max-depth)"
|
suite "Maximum depth (--max-depth)"
|
||||||
|
Loading…
Reference in New Issue
Block a user