Move ignore_files one level deeper

in preparation for new ignore functionality
This commit is contained in:
Félix Saparelli 2022-01-10 20:47:06 +13:00
parent 1c99546071
commit 6a541e5f27
No known key found for this signature in database
GPG Key ID: B948C4BAE44FC474
10 changed files with 29 additions and 24 deletions

View File

@ -3,25 +3,27 @@ use std::convert::Infallible;
use clap::ArgMatches;
use miette::Result;
use tracing::error;
use watchexec::{config::InitConfig, handler::SyncFnHandler, error::RuntimeError};
use watchexec::{config::InitConfig, error::RuntimeError, handler::SyncFnHandler};
pub fn init(_args: &ArgMatches<'static>) -> Result<InitConfig> {
let mut config = InitConfig::default();
config.on_error(SyncFnHandler::from(|data| -> std::result::Result<(), Infallible> {
if let RuntimeError::IoError(_) = data {
// these are often spurious, so condemn them to -v only
error!("{}", data);
return Ok(());
}
config.on_error(SyncFnHandler::from(
|data| -> std::result::Result<(), Infallible> {
if let RuntimeError::IoError(_) = data {
// these are often spurious, so condemn them to -v only
error!("{}", data);
return Ok(());
}
if cfg!(debug_assertions) {
eprintln!("[[{:?}]]", data);
} else {
eprintln!("[[{}]]", data);
}
if cfg!(debug_assertions) {
eprintln!("[[{:?}]]", data);
} else {
eprintln!("[[{}]]", data);
}
Ok(())
}));
Ok(())
},
));
Ok(config)
}

View File

@ -9,7 +9,7 @@ use dunce::canonicalize;
use miette::{IntoDiagnostic, Result};
use tracing::{debug, warn};
use watchexec::{
ignore_files::{self, IgnoreFile},
ignore::{self, files::IgnoreFile},
paths::common_prefix,
project::{self, ProjectType},
};
@ -42,7 +42,7 @@ pub async fn ignores(args: &ArgMatches<'static>, origin: &Path) -> Result<Vec<Ig
.collect::<Vec<_>>();
debug!(?vcs_types, "resolved vcs types");
let (mut ignores, _errors) = ignore_files::from_origin(origin).await;
let (mut ignores, _errors) = ignore::files::from_origin(origin).await;
// TODO: handle errors
debug!(?ignores, "discovered ignore files from project origin");
@ -71,7 +71,7 @@ pub async fn ignores(args: &ArgMatches<'static>, origin: &Path) -> Result<Vec<Ig
debug!(?ignores, "filtered ignores to only those for project vcs");
}
let (mut global_ignores, _errors) = ignore_files::from_environment().await;
let (mut global_ignores, _errors) = ignore::files::from_environment().await;
// TODO: handle errors
debug!(?global_ignores, "discovered ignore files from environment");

View File

@ -9,7 +9,7 @@ use watchexec::{
files::{self, FilterFile},
Filter, Matcher, Op, Pattern, TaggedFilterer,
},
ignore_files::IgnoreFile,
ignore::files::IgnoreFile,
};
pub async fn tagged(args: &ArgMatches<'static>) -> Result<Arc<TaggedFilterer>> {

View File

@ -10,7 +10,7 @@ use tracing::{debug, trace, trace_span};
use crate::error::RuntimeError;
use crate::event::{Event, FileType};
use crate::filter::Filterer;
use crate::ignore_files::IgnoreFile;
use crate::ignore::files::IgnoreFile;
/// A path-only filterer based on globsets.
///

View File

@ -16,7 +16,7 @@ use crate::error::RuntimeError;
use crate::event::{Event, FileType, ProcessEnd, Tag};
use crate::filter::tagged::error::TaggedFiltererError;
use crate::filter::Filterer;
use crate::ignore_files::IgnoreFile;
use crate::ignore::files::IgnoreFile;
use crate::signal::process::SubSignal;
use crate::signal::source::MainSignal;

View File

@ -9,7 +9,7 @@ use std::{
use tokio::fs::read_to_string;
use crate::ignore_files::{discover_file, IgnoreFile};
use crate::ignore::files::{discover_file, IgnoreFile};
use super::{error::TaggedFiltererError, Filter};

3
lib/src/ignore.rs Normal file
View File

@ -0,0 +1,3 @@
//! Ignore files: find them, parse them, interpret them.
pub mod files;

View File

@ -282,7 +282,7 @@ pub(crate) async fn discover_file(
Ok(None) => {
trace!("found nothing");
false
},
}
Ok(Some(path)) => {
trace!(?path, "found a file");
files.push(IgnoreFile {

View File

@ -104,7 +104,7 @@ pub mod error;
pub mod event;
pub mod filter;
pub mod fs;
pub mod ignore_files;
pub mod ignore;
pub mod paths;
pub mod project;
pub mod signal;

View File

@ -15,7 +15,7 @@ use watchexec::{
tagged::{files::FilterFile, Filter, Matcher, Op, Pattern, TaggedFilterer},
Filterer,
},
ignore_files::IgnoreFile,
ignore::files::IgnoreFile,
project::ProjectType,
signal::source::MainSignal,
};