watchexec/lib
2021-08-21 22:30:19 +12:00
..
examples Split signal and fs examples 2021-08-19 20:31:29 +12:00
src Add docs for error_handler as it's a bit tricky 2021-08-21 22:30:19 +12:00
tests Add docs for error_handler as it's a bit tricky 2021-08-21 22:30:19 +12:00
.rustfmt.toml Start on watchexec v2 2021-08-16 21:49:12 +12:00
Cargo.toml Upgrade to notify pre.12 2021-08-20 02:59:39 +12:00
CITATION.cff Add citation.cff 2021-07-29 00:45:13 +12:00
README.md Link to website for downloads 2021-07-10 03:48:12 +12:00

Crates.io page API Docs Crate license: Apache 2.0 MSRV: 1.43.0 (breaking) CI status

Watchexec library

The library which powers Watchexec CLI and other tools.

Quick start

use watchexec::{
    config::ConfigBuilder,
    error::Result,
    pathop::PathOp,
    run::{
        ExecHandler,
        Handler,
        watch,
    },
};

fn main() -> Result<()> {
    let config = ConfigBuilder::default()
        .clear_screen(true)
        .run_initially(true)
        .paths(vec![ "/path/to/dir".into() ])
        .cmd(vec![ "date; seq 1 10".into() ])
        .build()?;

    let handler = MyHandler(ExecHandler::new(options)?);
    watch(&handler)
}

struct MyHandler(ExecHandler);

impl Handler for MyHandler {
    fn args(&self) -> Config {
        self.0.args()
    }

    fn on_manual(&self) -> Result<bool> {
        println!("Running manually!");
        self.0.on_manual()
    }

    fn on_update(&self, ops: &[PathOp]) -> Result<bool> {
        println!("Running manually {:?}", ops);
        self.0.on_update(ops)
    }
}