Add --project-origin override
This commit is contained in:
parent
4a6d4350c5
commit
84aac2243c
|
@ -153,7 +153,12 @@ pub fn get_args(tagged_filterer: bool) -> Result<ArgMatches<'static>> {
|
|||
.help_heading(Some(OPTSET_OUTPUT))
|
||||
.help("Send a desktop notification when the command ends")
|
||||
.short("N")
|
||||
.long("notify"));
|
||||
.long("notify"))
|
||||
.arg(Arg::with_name("project-origin")
|
||||
.help_heading(Some(OPTSET_FILTERING))
|
||||
.help("Override the project origin: the directory from which ignore files are detected")
|
||||
.value_name("path")
|
||||
.long("project-origin"));
|
||||
|
||||
let app = if tagged_filterer {
|
||||
app.arg(
|
||||
|
|
|
@ -20,56 +20,61 @@ 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 project_origin = if let Some(origin) = args.value_of("project-origin") {
|
||||
debug!(?origin, "project origin override");
|
||||
canonicalize(origin).into_diagnostic()?
|
||||
} else {
|
||||
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());
|
||||
}
|
||||
|
||||
debug!(?paths, "resolved all watched paths");
|
||||
|
||||
let mut origins = HashSet::new();
|
||||
for path in paths {
|
||||
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);
|
||||
let mut paths = HashSet::new();
|
||||
for path in args.values_of("paths").unwrap_or_default() {
|
||||
paths.insert(canonicalize(path).into_diagnostic()?);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
if origins.is_empty() {
|
||||
debug!("no origins, using current directory");
|
||||
origins.insert(curdir.clone());
|
||||
}
|
||||
let homedir_requested = homedir.as_ref().map_or(false, |home| paths.contains(home));
|
||||
debug!(
|
||||
?homedir_requested,
|
||||
"resolved whether the homedir is explicitly requested"
|
||||
);
|
||||
|
||||
debug!(?origins, "resolved all project origins");
|
||||
if paths.is_empty() {
|
||||
debug!("no paths, using current directory");
|
||||
paths.insert(curdir.clone());
|
||||
}
|
||||
|
||||
// This canonicalize is probably redundant
|
||||
let project_origin = canonicalize(
|
||||
common_prefix(&origins)
|
||||
.ok_or_else(|| miette!("no common prefix, but this should never fail"))?,
|
||||
)
|
||||
.into_diagnostic()?;
|
||||
debug!(?paths, "resolved all watched paths");
|
||||
|
||||
let mut origins = HashSet::new();
|
||||
for path in paths {
|
||||
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());
|
||||
}
|
||||
|
||||
debug!(?origins, "resolved all project origins");
|
||||
|
||||
// This canonicalize is probably redundant
|
||||
canonicalize(
|
||||
common_prefix(&origins)
|
||||
.ok_or_else(|| miette!("no common prefix, but this should never fail"))?,
|
||||
)
|
||||
.into_diagnostic()?
|
||||
};
|
||||
debug!(?project_origin, "resolved common/project origin");
|
||||
|
||||
let workdir = curdir;
|
||||
|
|
|
@ -39,6 +39,8 @@ OPTIONS:
|
|||
[possible values: do-nothing, queue, restart, signal]
|
||||
-w, --watch <path>... Watch a specific file or directory
|
||||
--force-poll <interval> Force polling mode (interval in milliseconds)
|
||||
--project-origin <path> Override the project origin: the directory from which ignore files are
|
||||
detected
|
||||
--shell <shell> Use a different shell, or `none`. Defaults to `sh` (until 2.0, where that
|
||||
will change to `$SHELL`). E.g. --shell=bash
|
||||
-s, --signal <signal> Specify the signal to send when using --on-busy-update=signal
|
||||
|
|
|
@ -38,6 +38,8 @@ OPTIONS:
|
|||
[possible values: do-nothing, queue, restart, signal]
|
||||
-w, --watch <path>... Watch a specific file or directory
|
||||
--force-poll <interval> Force polling mode (interval in milliseconds)
|
||||
--project-origin <path> Override the project origin: the directory from which ignore files are
|
||||
detected
|
||||
--shell <shell> Use a different shell, or `none`. Try --shell=powershell, which will become
|
||||
the default in 2.0.
|
||||
-s, --signal <signal> Specify the signal to send when using --on-busy-update=signal
|
||||
|
|
Loading…
Reference in New Issue