Implement cli's own wrapper handler
That will let us hook in watchexec-cli specific stuff
This commit is contained in:
parent
3208652ed8
commit
a3173194a1
|
@ -10,13 +10,11 @@ use std::{
|
|||
use clap::{crate_version, value_t, values_t, App, Arg};
|
||||
use color_eyre::eyre::{Context, Report, Result};
|
||||
use log::LevelFilter;
|
||||
use watchexec::{
|
||||
config::{Config, ConfigBuilder},
|
||||
run::OnBusyUpdate,
|
||||
Shell,
|
||||
};
|
||||
use watchexec::{config::ConfigBuilder, run::OnBusyUpdate, Shell};
|
||||
|
||||
pub fn get_args() -> Result<(Config, LevelFilter)> {
|
||||
use crate::handler::CliHandler;
|
||||
|
||||
pub fn get_args() -> Result<CliHandler> {
|
||||
let app = App::new("watchexec")
|
||||
.version(crate_version!())
|
||||
.about("Execute commands when watched files change")
|
||||
|
@ -281,7 +279,7 @@ pub fn get_args() -> Result<(Config, LevelFilter)> {
|
|||
LevelFilter::Warn
|
||||
};
|
||||
|
||||
Ok((config, loglevel))
|
||||
CliHandler::new(config, loglevel, false)
|
||||
}
|
||||
|
||||
// until 2.0
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
use color_eyre::eyre;
|
||||
use log::LevelFilter;
|
||||
use watchexec::{
|
||||
config::Config,
|
||||
error::Result,
|
||||
pathop::PathOp,
|
||||
run::{ExecHandler, Handler},
|
||||
};
|
||||
|
||||
pub struct CliHandler {
|
||||
pub inner: ExecHandler,
|
||||
pub log_level: LevelFilter,
|
||||
pub notify: bool,
|
||||
}
|
||||
|
||||
impl CliHandler {
|
||||
pub fn new(config: Config, log_level: LevelFilter, notify: bool) -> eyre::Result<Self> {
|
||||
Ok(Self {
|
||||
inner: ExecHandler::new(config)?,
|
||||
log_level,
|
||||
notify,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Handler for CliHandler {
|
||||
fn args(&self) -> Config {
|
||||
self.inner.args()
|
||||
}
|
||||
|
||||
fn on_manual(&self) -> Result<bool> {
|
||||
self.inner.on_manual()
|
||||
}
|
||||
fn on_update(&self, ops: &[PathOp]) -> Result<bool> {
|
||||
self.inner.on_update(ops)
|
||||
}
|
||||
}
|
|
@ -1,19 +1,20 @@
|
|||
use std::io::Write;
|
||||
|
||||
use color_eyre::eyre::Result;
|
||||
use watchexec::run;
|
||||
use watchexec::watch;
|
||||
|
||||
mod args;
|
||||
mod handler;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
color_eyre::install()?;
|
||||
let (args, loglevel) = args::get_args()?;
|
||||
let handler = args::get_args()?;
|
||||
|
||||
env_logger::Builder::new()
|
||||
.format(|buf, r| writeln!(buf, "*** {}", r.args()))
|
||||
.filter(None, loglevel)
|
||||
.filter(None, handler.log_level)
|
||||
.init();
|
||||
|
||||
run(args)?;
|
||||
watch(&handler)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue