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

View File

@ -9,7 +9,7 @@ use dunce::canonicalize;
use miette::{IntoDiagnostic, Result}; use miette::{IntoDiagnostic, Result};
use tracing::{debug, warn}; use tracing::{debug, warn};
use watchexec::{ use watchexec::{
ignore_files::{self, IgnoreFile}, ignore::{self, files::IgnoreFile},
paths::common_prefix, paths::common_prefix,
project::{self, ProjectType}, project::{self, ProjectType},
}; };
@ -42,7 +42,7 @@ pub async fn ignores(args: &ArgMatches<'static>, origin: &Path) -> Result<Vec<Ig
.collect::<Vec<_>>(); .collect::<Vec<_>>();
debug!(?vcs_types, "resolved vcs types"); 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 // TODO: handle errors
debug!(?ignores, "discovered ignore files from project origin"); 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"); 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 // TODO: handle errors
debug!(?global_ignores, "discovered ignore files from environment"); debug!(?global_ignores, "discovered ignore files from environment");

View File

@ -9,7 +9,7 @@ use watchexec::{
files::{self, FilterFile}, files::{self, FilterFile},
Filter, Matcher, Op, Pattern, TaggedFilterer, Filter, Matcher, Op, Pattern, TaggedFilterer,
}, },
ignore_files::IgnoreFile, ignore::files::IgnoreFile,
}; };
pub async fn tagged(args: &ArgMatches<'static>) -> Result<Arc<TaggedFilterer>> { 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::error::RuntimeError;
use crate::event::{Event, FileType}; use crate::event::{Event, FileType};
use crate::filter::Filterer; use crate::filter::Filterer;
use crate::ignore_files::IgnoreFile; use crate::ignore::files::IgnoreFile;
/// A path-only filterer based on globsets. /// 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::event::{Event, FileType, ProcessEnd, Tag};
use crate::filter::tagged::error::TaggedFiltererError; use crate::filter::tagged::error::TaggedFiltererError;
use crate::filter::Filterer; use crate::filter::Filterer;
use crate::ignore_files::IgnoreFile; use crate::ignore::files::IgnoreFile;
use crate::signal::process::SubSignal; use crate::signal::process::SubSignal;
use crate::signal::source::MainSignal; use crate::signal::source::MainSignal;

View File

@ -9,7 +9,7 @@ use std::{
use tokio::fs::read_to_string; 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}; 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) => { Ok(None) => {
trace!("found nothing"); trace!("found nothing");
false false
}, }
Ok(Some(path)) => { Ok(Some(path)) => {
trace!(?path, "found a file"); trace!(?path, "found a file");
files.push(IgnoreFile { files.push(IgnoreFile {

View File

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

View File

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