Skip to content
This repository has been archived by the owner on Jan 18, 2025. It is now read-only.

Commit

Permalink
Make “watch when idle” the default, instead of restarting
Browse files Browse the repository at this point in the history
  • Loading branch information
passcod committed Jul 9, 2022
1 parent 60b221f commit 68221f0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
9 changes: 5 additions & 4 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ const OPTSET_OUTPUT: &str = "OUTPUT";
const OPTSET_BEHAVIOUR: &str = "BEHAVIOUR";
const OPTSET_WORKSPACES: &str = "WORKSPACES";

// --watch-when-idle is now default

#[derive(Debug, Clone, clap::Parser)]
#[clap(name = "cargo-watch", about, version)]
pub struct Args {
Expand Down Expand Up @@ -72,12 +70,15 @@ pub struct Args {
)]
pub no_dot_ignores: bool,

/// Don’t restart command while it’s still running
/// Restart the command set when events come in while it’s still running
///
/// Note that this can lead to loops when the command set causes a watched file to change. In
/// that case, you should restrict what is watched with --watch and/or --ignore.
#[clap(
long,
help_heading = OPTSET_BEHAVIOUR,
)]
pub no_restart: bool,
pub restart: bool,

/// Reserved for workspace support
#[clap(
Expand Down
7 changes: 3 additions & 4 deletions src/config/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ pub fn runtime(args: &Args, command_order: Vec<&'static str>) -> Result<RuntimeC
let quiet = args.quiet;
let clear = args.clear;
let notif = args.notif;
let on_busy = if args.no_restart {
"do-nothing"
} else {
let on_busy = if args.restart {
"restart"
} else {
"do-nothing"
};

// TODO: add using SubSignal in Args directly
Expand Down Expand Up @@ -262,7 +262,6 @@ pub fn runtime(args: &Args, command_order: Vec<&'static str>) -> Result<RuntimeC
"do-nothing" => Outcome::DoNothing,
"restart" => Outcome::both(Outcome::Stop, start),
// "signal" => Outcome::Signal(signal),
// "queue" => Outcome::wait(start),
_ => Outcome::DoNothing,
};

Expand Down
17 changes: 9 additions & 8 deletions tests/trycmd/unix/restart.trycmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This first one tests that test-cw behaves correctly:
This first one tests that test-cw behaves correctly on a single run:

```
$ test-cw --
Expand All @@ -13,15 +13,16 @@ out
```


This one uses `--quit-after-n`. As the default is to restart the command on
event, we're looking for the second command to start in the middle of the
first. We ignore the output after the second start because the order of the
`ForceStop` message and the `in` message can vary. But we're looking for the
`quit-after-n` signalling message afterwards to check that Cargo Watch stopped.
This one uses `--quit-after-n`. With `--restart`, we restart the command on
event without waiting for it to stop, so we're looking for the second command
to start in the middle of the first. We ignore the output after the second
start because the order of the `ForceStop` message and the `in` message can
vary. But we're looking for the `quit-after-n` signalling message afterwards to
check that Cargo Watch stopped.

```
$ test-cw --touch File --touch Other --between 500 --
> --quit-after-n 2 --postpone -S sh -s 'echo in; sleep 1; echo out'
> --restart --quit-after-n 2 --postpone -S sh -s 'echo in; sleep 1; echo out'
? 0
[[Running `echo in; sleep 1; echo out`]]
in
Expand All @@ -39,7 +40,7 @@ signalling from the tester.

```
$ test-cw --touch File --touch Other --between 500 --expect-timeout --
> --postpone -S sh -s 'echo in; sleep 1; echo out'
> --restart --postpone -S sh -s 'echo in; sleep 1; echo out'
? 0
[[Running `echo in; sleep 1; echo out`]]
in
Expand Down

0 comments on commit 68221f0

Please sign in to comment.