2021-10-09 07:45:32 +02:00
|
|
|
use std::{env::var};
|
2020-06-24 16:17:59 +02:00
|
|
|
|
2021-10-09 07:43:51 +02:00
|
|
|
use miette::{IntoDiagnostic, Result};
|
2021-10-09 07:45:32 +02:00
|
|
|
use watchexec::{Watchexec, event::Event, filter::tagged::{Filter, Matcher, Op, TaggedFilterer}};
|
2021-05-10 12:44:35 +02:00
|
|
|
|
2021-04-10 15:33:40 +02:00
|
|
|
mod args;
|
2021-08-24 10:23:37 +02:00
|
|
|
mod config;
|
2016-09-14 15:30:59 +02:00
|
|
|
|
2021-08-24 10:23:37 +02:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> Result<()> {
|
2021-09-28 14:47:18 +02:00
|
|
|
#[cfg(feature = "dev-console")]
|
|
|
|
console_subscriber::init();
|
|
|
|
|
|
|
|
if var("RUST_LOG").is_ok() && cfg!(not(feature = "dev-console")) {
|
2021-08-24 10:23:37 +02:00
|
|
|
tracing_subscriber::fmt::init();
|
|
|
|
}
|
2021-05-10 12:44:35 +02:00
|
|
|
|
2021-08-24 10:23:37 +02:00
|
|
|
let args = args::get_args()?;
|
|
|
|
|
|
|
|
if args.is_present("verbose") {
|
|
|
|
tracing_subscriber::fmt()
|
2021-08-24 13:20:21 +02:00
|
|
|
.with_env_filter(match args.occurrences_of("verbose") {
|
2021-08-24 12:45:31 +02:00
|
|
|
0 => unreachable!(),
|
2021-08-24 13:20:21 +02:00
|
|
|
1 => "watchexec=debug",
|
|
|
|
2 => "watchexec=trace",
|
|
|
|
_ => "trace",
|
2021-08-24 12:45:31 +02:00
|
|
|
})
|
2021-08-24 10:23:37 +02:00
|
|
|
.try_init()
|
|
|
|
.ok();
|
|
|
|
}
|
|
|
|
|
2021-10-12 13:48:42 +02:00
|
|
|
let mut filters = Vec::new();
|
2021-09-28 11:24:06 +02:00
|
|
|
|
2021-10-09 07:45:32 +02:00
|
|
|
// TODO: move into config?
|
2021-09-28 11:24:06 +02:00
|
|
|
for filter in args.values_of("filter").unwrap_or_default() {
|
2021-10-12 13:48:42 +02:00
|
|
|
filters.push(filter.parse()?);
|
2021-09-28 11:24:06 +02:00
|
|
|
}
|
2021-08-24 10:23:37 +02:00
|
|
|
|
2021-10-09 07:45:32 +02:00
|
|
|
for ext in args.values_of("extensions").unwrap_or_default().map(|s| s.split(',').map(|s| s.trim())).flatten() {
|
2021-10-12 13:48:42 +02:00
|
|
|
filters.push(Filter {
|
2021-10-09 07:45:32 +02:00
|
|
|
in_path: None,
|
|
|
|
on: Matcher::Path,
|
|
|
|
op: Op::Glob,
|
|
|
|
pat: TaggedFilterer::glob(&format!("**/*.{}", ext))?,
|
|
|
|
negate: false,
|
2021-10-12 13:48:42 +02:00
|
|
|
});
|
2021-10-09 07:45:32 +02:00
|
|
|
}
|
|
|
|
|
2021-10-12 13:48:42 +02:00
|
|
|
let (init, runtime, filterer) = config::new(&args)?;
|
|
|
|
filterer.add_filters(&filters).await?;
|
|
|
|
|
2021-08-24 10:23:37 +02:00
|
|
|
let wx = Watchexec::new(init, runtime)?;
|
|
|
|
|
2021-08-24 12:45:31 +02:00
|
|
|
if !args.is_present("postpone") {
|
|
|
|
wx.send_event(Event::default()).await?;
|
|
|
|
}
|
|
|
|
|
2021-10-09 07:43:51 +02:00
|
|
|
wx.main().await.into_diagnostic()??;
|
2021-08-24 10:23:37 +02:00
|
|
|
|
|
|
|
Ok(())
|
2020-06-24 16:17:59 +02:00
|
|
|
}
|