Start working on watcher

This commit is contained in:
Austen Adler 2024-09-02 15:00:25 -04:00
parent 39b89a1ab8
commit 29dfd4b007

View File

@ -18,18 +18,22 @@ struct Cli {
#[derive(Subcommand, Debug)] #[derive(Subcommand, Debug)]
enum Command { enum Command {
Fmt(FmtArgs), Fmt(FmtArgs),
// Watch(WatchArgs), Watch(WatchArgs),
} }
// #[derive(Args, Debug)] #[derive(Args, Debug)]
// struct WatchArgs { struct WatchArgs {
// dir: PathBuf path: PathBuf,
// }
#[clap(short = 'I', long = "inplace")]
inplace: bool,
}
#[derive(Args, Debug)] #[derive(Args, Debug)]
struct FmtArgs { struct FmtArgs {
#[clap(short = 'i', long = "input")] // #[clap(short = 'i', long = "input")]
input: PathBuf, input: PathBuf,
#[clap(short = 'o', long = "output")] #[clap(short = 'o', long = "output")]
output: Option<PathBuf>, output: Option<PathBuf>,
@ -81,6 +85,7 @@ fn main() -> Result<()> {
} }
format_single_file(&a)?; format_single_file(&a)?;
} }
Command::Watch(a) => watch(&a)?,
} }
Ok(()) Ok(())
@ -117,28 +122,30 @@ fn format_single_file(args: &FmtArgs) -> Result<()> {
Ok(()) Ok(())
} }
// fn x() { fn watch(args: &WatchArgs) -> Result<()> {
// // Select recommended watcher for debouncer. // Select recommended watcher for debouncer.
// // Using a callback here, could also be a channel. // Using a callback here, could also be a channel.
// let mut debouncer = let mut debouncer =
// new_debouncer( new_debouncer(
// Duration::from_millis(50), Duration::from_millis(50),
// |res: DebounceEventResult| match res { |res: DebounceEventResult| match res {
// Ok(events) => events Ok(events) => events
// .iter() .iter()
// .for_each(|e| println!("Event {:?} for {:?}", e.kind, e.path)), .for_each(|e| println!("Event {:?} for {:?}", e.kind, e.path)),
// Err(e) => println!("Error {:?}", e), Err(e) => println!("Error {:?}", e),
// }, },
// ) )
// .unwrap(); .context("Creating debouncer")?;
// // Add a path to be watched. All files and directories at that path and // Add a path to be watched. All files and directories at that path and
// // below will be monitored for changes. // below will be monitored for changes.
// debouncer debouncer
// .watcher() .watcher()
// .watch(Path::new("."), RecursiveMode::Recursive) .watch(Path::new("."), RecursiveMode::Recursive)
// .unwrap(); .context("Adding watch to debouncer")?;
// // note that dropping the debouncer (as will happen here) also ends the debouncer // note that dropping the debouncer (as will happen here) also ends the debouncer
// // thus this demo would need an endless loop to keep running // thus this demo would need an endless loop to keep running
// }
Ok(())
}