Skip to content

Added watch subcommand#123

Merged
jeparlefrancais merged 7 commits intoseaofvoices:mainfrom
Stefanuk12:watch-patch
Oct 5, 2023
Merged

Added watch subcommand#123
jeparlefrancais merged 7 commits intoseaofvoices:mainfrom
Stefanuk12:watch-patch

Conversation

@Stefanuk12
Copy link
Contributor

@Stefanuk12 Stefanuk12 commented Aug 30, 2023

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_options within 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

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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 🙂

Copy link
Contributor Author

@Stefanuk12 Stefanuk12 Sep 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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");

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sent you an invite on discord, we could work on this together if you want some help 🙂

@jeparlefrancais jeparlefrancais merged commit d68b930 into seaofvoices:main Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Watch mode

2 participants