cargo-watch icon indicating copy to clipboard operation
cargo-watch copied to clipboard

Feature Request: Run shell commands on cargo command failures

Open roboteng opened this issue 2 years ago • 1 comments

Currently, shell commands only run after cargo commands run successfully. I'd also like to be able to run a different shell command on cargo command failures. My use case is that I'd like to run a command that plays a success sound on a cargo command success, and a different sound on cargo command failure.

This is what I have right now:

cargo watch -x check -s "afplay ~/bin/success-chime.mp3 & echo ''"

This is what I'd like to see. I'm not sure that this would be the right syntax, but I think it gets the point across:

cargo watch -x check -s "afplay ~/bin/success-chime.mp3 & echo ''" --cargo-failure "afplay ~/bin/error-chime.mp3 & echo ''"

The -s arg gets run after the previous cargo commands pass, and the --cargo-failure arg gets run if cargo doesn't complete successfully.

What should the syntax here be?

roboteng avatar Sep 13 '23 18:09 roboteng

Right now what you should do is

cargo watch -s 'cargo check && success || failure'

where success and failure are the chimes commands you've defined

passcod avatar Sep 13 '23 22:09 passcod