Restrict --one-file-system to supported systems

Instead of having the option do nothing at runtime on unsupported
platforms, it is now only available on the systems that support it in
the first place.
This commit is contained in:
Simon Engmann 2019-12-30 22:05:42 +01:00 committed by David Peter
parent 94993ca6c2
commit dea1fbe722
2 changed files with 22 additions and 10 deletions

View file

@ -37,7 +37,7 @@ pub fn build_app() -> App<'static, 'static> {
.long_help(helps[name].long)
};
App::new("fd")
let app = App::new("fd")
.version(crate_version!())
.usage("fd [FLAGS/OPTIONS] [<pattern>] [<path>...]")
.setting(AppSettings::ColoredHelp)
@ -115,7 +115,6 @@ pub fn build_app() -> App<'static, 'static> {
.alias("dereference")
.overrides_with("follow"),
)
.arg(arg("one-file-system").long("one-file-system"))
.arg(
arg("full-path")
.long("full-path")
@ -283,7 +282,16 @@ pub fn build_app() -> App<'static, 'static> {
.multiple(true)
.hidden_short_help(true)
.number_of_values(1),
)
);
// Make `--one-file-system` available only on Unix and Windows platforms, as per the
// restrictions on the corresponding option in the `ignore` crate.
// It's not pretty, but I'm unaware of a way to make just part of a builder chain conditional
if cfg!(unix) || cfg!(windows) {
app.arg(arg("one-file-system").long("one-file-system"))
} else {
app
}
}
#[rustfmt::skip]
@ -330,11 +338,6 @@ fn usage() -> HashMap<&'static str, Help> {
, "Follow symbolic links"
, "By default, fd does not descend into symlinked directories. Using this flag, symbolic \
links are also traversed.");
doc!(h, "one-file-system"
, "Don't cross file system boundaries (only Unix/Windows)"
, "By default, fd will traverse the file system tree as far as other options dictate. \
With this flag, fd ensures that it does not descend into a different file system than \
the one it started in. Does nothing if not on Unix or Windows.");
doc!(h, "full-path"
, "Search full path (default: file-/dirname only)"
, "By default, the search pattern is only matched against the filename (or directory \
@ -463,5 +466,14 @@ fn usage() -> HashMap<&'static str, Help> {
results will be shown with respect to the given base path. Note that relative paths \
which are passed to fd via the positional <path> argument or the '--search-path' option \
will also be resolved relative to this directory.");
if cfg!(unix) || cfg!(windows) {
doc!(h, "one-file-system"
, "Don't cross file system boundaries"
, "By default, fd will traverse the file system tree as far as other options dictate. \
With this flag, fd ensures that it does not descend into a different file system \
than the one it started in.");
}
h
}

View file

@ -78,8 +78,8 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc<Regex>, config: Arc<FdOptions>) -
.git_exclude(config.read_vcsignore)
.overrides(overrides)
.follow_links(config.follow_links)
// Same file system is only supported on Unix and Windows platforms
.same_file_system(config.one_file_system && (cfg!(unix) || cfg!(windows)))
// No need to check for supported platforms, option is unavailable on unsupported ones
.same_file_system(config.one_file_system)
.max_depth(config.max_depth);
if config.read_fdignore {