diff --git a/Cargo.lock b/Cargo.lock index 81648db..798dcc3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2623,6 +2623,7 @@ dependencies = [ "assert_cmd", "clap", "console-subscriber", + "dirs 4.0.0", "dunce", "embed-resource", "futures", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 1b5e183..f3f0123 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -22,6 +22,7 @@ path = "src/main.rs" [dependencies] console-subscriber = { version = "0.1.0", optional = true } +dirs = "4.0.0" dunce = "1.0.2" futures = "0.3.17" miette = { version = "3.2.0", features = ["fancy"] } diff --git a/cli/src/filterer/common.rs b/cli/src/filterer/common.rs index b25c097..ac82c31 100644 --- a/cli/src/filterer/common.rs +++ b/cli/src/filterer/common.rs @@ -20,11 +20,23 @@ pub async fn dirs(args: &ArgMatches<'static>) -> Result<(PathBuf, PathBuf)> { .into_diagnostic()?; debug!(?curdir, "current directory"); + let homedir = dirs::home_dir() + .map(canonicalize) + .transpose() + .into_diagnostic()?; + debug!(?homedir, "home directory"); + let mut paths = HashSet::new(); for path in args.values_of("paths").unwrap_or_default() { paths.insert(canonicalize(path).into_diagnostic()?); } + let homedir_requested = homedir.as_ref().map_or(false, |home| paths.contains(home)); + debug!( + ?homedir_requested, + "resolved whether the homedir is explicitly requested" + ); + if paths.is_empty() { debug!("no paths, using current directory"); paths.insert(curdir.clone()); @@ -37,6 +49,14 @@ pub async fn dirs(args: &ArgMatches<'static>) -> Result<(PathBuf, PathBuf)> { origins.extend(project::origins(&path).await); } + match (homedir, homedir_requested) { + (Some(ref dir), false) if origins.contains(dir) => { + debug!("removing homedir from origins"); + origins.remove(dir); + } + _ => {} + } + if origins.is_empty() { debug!("no origins, using current directory"); origins.insert(curdir.clone());