Skip to content

✨ feat(mq-run): add --watch mode for live query re-execution#1800

Open
harehare wants to merge 2 commits into
mainfrom
feat/add-watch-mode
Open

✨ feat(mq-run): add --watch mode for live query re-execution#1800
harehare wants to merge 2 commits into
mainfrom
feat/add-watch-mode

Conversation

@harehare
Copy link
Copy Markdown
Owner

Add --watch flag that monitors input files with notify and re-runs the query on each file change. Uses 50ms debounce to coalesce rapid save events.

Add `--watch` flag that monitors input files with `notify` and
re-runs the query on each file change. Uses 50ms debounce to
coalesce rapid save events.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an optional --watch flag to the mq CLI (behind a new default-on watch feature) that uses the notify crate to monitor input files and re-run the query on changes, with a 50ms debounce. Conflicts with --stream and requires at least one input file.

Changes:

  • New --watch CLI flag and process_watch() method dispatched from Cli::run() for non-streaming execution.
  • New watch feature in crates/mq-run/Cargo.toml (added to defaults) plus an optional notify dependency in the workspace.
  • One integration test for the --watch/--stream clap conflict and one unit test for the "requires file" error path.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
crates/mq-run/src/cli.rs Adds watch field, dispatch branch, process_watch() implementation, and unit test.
crates/mq-run/tests/integration_tests.rs Adds integration test asserting --watch --stream fails.
crates/mq-run/Cargo.toml Defines watch feature, adds it to defaults, declares optional notify dep.
Cargo.toml Adds notify = "8.0" workspace dependency.
Cargo.lock Resolves notify 8.2.0 and its transitive deps.

Comment thread crates/mq-run/Cargo.toml
Comment thread Cargo.toml
Comment thread crates/mq-run/src/cli.rs
Comment on lines +881 to +895
let _ = self.process_batch();

loop {
match rx.recv() {
Ok(Ok(event)) => {
if matches!(
event.kind,
EventKind::Modify(_) | EventKind::Create(_)
) {
// drain pending events to debounce rapid saves
std::thread::sleep(std::time::Duration::from_millis(50));
while rx.try_recv().is_ok() {}

eprintln!("\n---");
let _ = self.process_batch();
Comment thread crates/mq-run/src/cli.rs
Comment on lines +868 to +896
for file in files {
watcher
.watch(file.as_ref(), RecursiveMode::NonRecursive)
.into_diagnostic()?;
}

let file_list = files
.iter()
.map(|f| f.display().to_string())
.collect::<Vec<_>>()
.join(", ");
eprintln!("Watching {} ... (Ctrl+C to exit)", file_list);

let _ = self.process_batch();

loop {
match rx.recv() {
Ok(Ok(event)) => {
if matches!(
event.kind,
EventKind::Modify(_) | EventKind::Create(_)
) {
// drain pending events to debounce rapid saves
std::thread::sleep(std::time::Duration::from_millis(50));
while rx.try_recv().is_ok() {}

eprintln!("\n---");
let _ = self.process_batch();
}
Comment thread crates/mq-run/src/cli.rs
Comment on lines +855 to +860
let Some(files) = &self.files else {
return Err(miette!("--watch requires at least one input file"));
};
if files.is_empty() {
return Err(miette!("--watch requires at least one input file"));
}
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.

2 participants