The thing I said should never fail does in fact fail

Fixes #271
This commit is contained in:
Félix Saparelli 2022-03-28 10:06:20 +13:00
parent 57e2ddf9fa
commit 386e01b06f
1 changed files with 20 additions and 11 deletions

View File

@ -6,7 +6,7 @@ use std::{
use clap::ArgMatches;
use dunce::canonicalize;
use miette::{IntoDiagnostic, Result, miette};
use miette::{miette, IntoDiagnostic, Result};
use tracing::{debug, warn};
use watchexec::{
ignore::{self, IgnoreFile},
@ -15,16 +15,19 @@ use watchexec::{
};
pub async fn dirs(args: &ArgMatches<'static>) -> Result<(PathBuf, PathBuf)> {
let curdir = env::current_dir()
.and_then(canonicalize)
.into_diagnostic()?;
debug!(?curdir, "current directory");
let mut paths = HashSet::new();
for path in args.values_of("paths").unwrap_or_default() {
paths.insert(
canonicalize(path).into_diagnostic()?
);
paths.insert(canonicalize(path).into_diagnostic()?);
}
if paths.is_empty() {
debug!("no paths, using current directory");
paths.insert(canonicalize(".").into_diagnostic()?);
paths.insert(curdir.clone());
}
debug!(?paths, "resolved all watched paths");
@ -34,16 +37,22 @@ pub async fn dirs(args: &ArgMatches<'static>) -> Result<(PathBuf, PathBuf)> {
origins.extend(project::origins(&path).await);
}
if origins.is_empty() {
debug!("no origins, using current directory");
origins.insert(curdir.clone());
}
debug!(?origins, "resolved all project origins");
let project_origin =
canonicalize(common_prefix(&origins).ok_or_else(|| miette!("no common prefix, but this should never fail"))?)
.into_diagnostic()?;
// 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!(?project_origin, "resolved common/project origin");
let workdir = env::current_dir()
.and_then(canonicalize)
.into_diagnostic()?;
let workdir = curdir;
debug!(?workdir, "resolved working directory");
Ok((project_origin, workdir))