Good idea but let's keep compat for now

This commit is contained in:
Félix Saparelli 2021-08-24 23:20:21 +12:00
parent 6df6d6fd5a
commit 1fd5c85317
2 changed files with 13 additions and 29 deletions

View File

@ -4,14 +4,7 @@ use std::{
use clap::ArgMatches;
use color_eyre::eyre::{eyre, Result};
use watchexec::{
action::{Action, Outcome, Signal},
command::Shell,
config::{InitConfig, RuntimeConfig},
fs::Watcher,
handler::PrintDisplay,
signal::Signal as InputSignal,
};
use watchexec::{action::{Action, Outcome, Signal}, command::Shell, config::{InitConfig, RuntimeConfig}, event::Event, fs::Watcher, handler::PrintDisplay, signal::Signal as InputSignal};
pub fn new(args: &ArgMatches<'static>) -> Result<(InitConfig, RuntimeConfig)> {
Ok((init(args)?, runtime(args)?))
@ -94,13 +87,17 @@ fn runtime(args: &ArgMatches<'static>) -> Result<RuntimeConfig> {
let fut = async { Ok::<(), Infallible>(()) };
if print_events {
for event in &action.events {
for (n, event) in action.events.iter().enumerate() {
for path in event.paths() {
eprintln!("[EVENT] Path: {}", path.display());
eprintln!("[EVENT {}] Path: {} -- {:?}", n, path.display(), event.metadata);
}
for signal in event.signals() {
eprintln!("[EVENT] Signal: {:?}", signal);
eprintln!("[EVENT {}] Signal: {:?} -- {:?}", n, signal, event.metadata);
}
if event == &Event::default() {
eprintln!("[EVENT {}] Empty -- {:?}", n, event.metadata);
}
}
}
@ -125,19 +122,7 @@ fn runtime(args: &ArgMatches<'static>) -> Result<RuntimeConfig> {
}
if signals.contains(&InputSignal::Interrupt) {
let out = if signals
.iter()
.filter(|s| **s == InputSignal::Interrupt)
.count() >= 2
{
Outcome::both(Outcome::Stop, Outcome::Exit)
} else if cfg!(windows) {
Outcome::if_running(Outcome::Stop, Outcome::Exit)
} else {
Outcome::if_running(Outcome::Signal(Signal::SIGINT), Outcome::Exit)
};
action.outcome(out);
action.outcome(Outcome::both(Outcome::Stop, Outcome::Exit));
return fut;
}

View File

@ -1,7 +1,6 @@
use std::env::var;
use color_eyre::eyre::Result;
use tracing_subscriber::filter::LevelFilter;
use watchexec::{event::Event, Watchexec};
mod args;
@ -19,11 +18,11 @@ async fn main() -> Result<()> {
if args.is_present("verbose") {
tracing_subscriber::fmt()
.with_max_level(match args.occurrences_of("verbose") {
.with_env_filter(match args.occurrences_of("verbose") {
0 => unreachable!(),
1 => LevelFilter::INFO,
2 => LevelFilter::DEBUG,
_ => LevelFilter::TRACE,
1 => "watchexec=debug",
2 => "watchexec=trace",
_ => "trace",
})
.try_init()
.ok();