1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use watchexec::{
    cli::Args,
    pathop::PathOp,
    error::Error,
    run::{Handler, ExecHandler}
};
use clap::{App, Arg};

pub mod repo;

pub struct WatchHandler {
    inner: ExecHandler,
}

impl Handler for WatchHandler {
    fn new(args: Args) -> Result<Self, Error> {
        Ok(WatchHandler {
            inner: ExecHandler::new(args.clone())?,
        })
    }

    fn on_update(&mut self, ops: &[PathOp]) -> Result<bool, Error> {
        self.start();

        self.inner.on_update(ops)?;

        Ok(true)
    }

    fn on_manual(&mut self) -> Result<bool, Error> {
        self.start();

        Ok(true)
    }
}

impl WatchHandler {
    fn start(&self) {
        println!("Handling changes...");
    }
}

pub fn get_matches<'a>() -> clap::ArgMatches<'a> {
    App::new("My Super Program")
        .version("1.0")
        .author("Jannik Keye <jannik.keye@gmail.com>")
        .about("Does awesome things")
        .arg(Arg::with_name("path")
            .help("Path to watch")
            .index(1)
            .required(true)
        )
        .get_matches()
}