mirror of
https://github.com/watchexec/watchexec.git
synced 2024-09-29 22:51:33 +02:00
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 clap::{crate_version, value_t, values_t, App, Arg};
|
||||||
use color_eyre::eyre::{Context, Report, Result};
|
use color_eyre::eyre::{Context, Report, Result};
|
||||||
use log::LevelFilter;
|
use log::LevelFilter;
|
||||||
use watchexec::{
|
use watchexec::{config::ConfigBuilder, run::OnBusyUpdate, Shell};
|
||||||
config::{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")
|
let app = App::new("watchexec")
|
||||||
.version(crate_version!())
|
.version(crate_version!())
|
||||||
.about("Execute commands when watched files change")
|
.about("Execute commands when watched files change")
|
||||||
@ -281,7 +279,7 @@ pub fn get_args() -> Result<(Config, LevelFilter)> {
|
|||||||
LevelFilter::Warn
|
LevelFilter::Warn
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok((config, loglevel))
|
CliHandler::new(config, loglevel, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// until 2.0
|
// until 2.0
|
||||||
|
37
cli/src/handler.rs
Normal file
37
cli/src/handler.rs
Normal file
@ -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 std::io::Write;
|
||||||
|
|
||||||
use color_eyre::eyre::Result;
|
use color_eyre::eyre::Result;
|
||||||
use watchexec::run;
|
use watchexec::watch;
|
||||||
|
|
||||||
mod args;
|
mod args;
|
||||||
|
mod handler;
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
color_eyre::install()?;
|
color_eyre::install()?;
|
||||||
let (args, loglevel) = args::get_args()?;
|
let handler = args::get_args()?;
|
||||||
|
|
||||||
env_logger::Builder::new()
|
env_logger::Builder::new()
|
||||||
.format(|buf, r| writeln!(buf, "*** {}", r.args()))
|
.format(|buf, r| writeln!(buf, "*** {}", r.args()))
|
||||||
.filter(None, loglevel)
|
.filter(None, handler.log_level)
|
||||||
.init();
|
.init();
|
||||||
|
|
||||||
run(args)?;
|
watch(&handler)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user