Added watch subcommand#123
Added watch subcommand#123jeparlefrancais merged 7 commits intoseaofvoices:mainfrom Stefanuk12:watch-patch
Conversation
src/cli/mod.rs
Outdated
| /// `.darklua.json` or `darklua.json5` from the working directory. | ||
| Process(process::Options), | ||
| /// Automatically processes files when they change | ||
| Watch(process::Options), |
There was a problem hiding this comment.
Instead of using a new command, could you add a flag to the process command instead? If you are unfamiliar with clap, add something to the Options struct in the src/cli/process.rs file:
/// Watch files and directories for changes and automatically re-run
#[arg(long, short)]
watch: bool,
Then you can use this bool to branch the process function logic.
Feel free to reach out on discord too and ping me if you don't get a review within 2 days 🙂
There was a problem hiding this comment.
Hey, sorry for the late reply. Been trying to get this to work and I'm getting the following error: (dyn Rule + 'static)` cannot be shared between threads safely the trait `Sync` is not implemented for `(dyn Rule + 'static)
I mostly copy pasted the code from the watch file.
let mut watcher = notify::recommended_watcher(move |res: Result<notify::Event, notify::Error>| {
match res {
Ok(event) => {
if event.kind.is_create() || event.kind.is_modify() {
// this line is causing the problem
let Err(e) = process(*(resources.clone()), *(process_options.clone())) else { return };
log::error!("there was an process error while attempting to bundle: {:?}", e);
}
}
Err(err) => {
log::error!("there was an watcher error while attempting to bundle: {:?}", err);
}
}
}).expect("failed to create watcher");There was a problem hiding this comment.
I sent you an invite on discord, we could work on this together if you want some help 🙂
This adds a simple watch command that automatically runs the process command whenever a file change / creation is found. It can be optimised by getting the
process_optionswithin the watch subcommand and passing it into the process command but I did not do this. Let me know if you would like that implemented.Closes #98