cargo-cmd
cargo-cmd copied to clipboard
double quotes do not work with watchexec
running watchexec --restart "cargo run"
directly in cmd.exe works
[package.metadata.commands]
dev = 'watchexec --restart "cargo run"'
but when I run (in cmd.exe)
cargo cmd dev
I get:
> watchexec --restart "cargo run"
'\"cargo run\"' is not recognized as an internal or external command,
operable program or batch file.
my understanding is that "
became \"
since it gives the exact output if I run \"cargo run\"
in cmd.exe
or
"cargo run"
was passed to watchexec instead of cargo run
(without quotes)
using this:
dev = 'watchexec --restart "cargo --quiet run"'
I get:
> watchexec --restart "cargo --quiet run""
error: Found argument '--quiet' which wasn't expected, or isn't valid in this context
USAGE:
watchexec <command>... --restart
For more information try --help
why doesn't double quotes work ? which shell is used to execute commands?
my current workaround:
[package.metadata.commands]
quietRun = 'cargo --quiet run'
dev = 'watchexec --restart cargo cmd quietRun'
cargo cmd dev
works but it prints
> cargo --quiet run
every time I edit or save files
can you provide a way to make specific commands quiet? (not print for example > cargo --quiet run
)
make anything that starts with quiet_
be quiet, so
this be quiet: quiet_quietRun = 'cargo --quiet run'
this not be quiet: quietRun = 'cargo --quiet run'
but this will be slower since cargo cmd quietRun
will be run every time. instead of directly cargo --quiet run
I am running into a problem related to this issue also.
Im using cargo-watch
and having trouble running things.
Examples
Cargo.toml
[package.metadata.commands]
build = "wasm-pack build --target web --out-name wasm --out-dir ./static/build"
start = "miniserve ./static --index index.html"
When adding this command and running it
dev = "cargo watch -s 'cargo cmd build && cargo cmd start'"
output:
> cargo watch -s 'cargo cmd build && cargo cmd start'
error: Found argument 'cmd' which wasn't expected, or isn't valid in this context
USAGE:
cargo watch [FLAGS] [OPTIONS]
For more information try --help
Same thing happens with:
dev = "cargo watch -s 'cargo cmd build'"
output:
> cargo watch -s 'cargo cmd build'
error: Found argument 'cmd' which wasn't expected, or isn't valid in this context
USAGE:
cargo watch [FLAGS] [OPTIONS]
For more information try --help
Or even using -x
dev = "cargo watch -x 'cargo cmd build'"
output:
> cargo watch -x 'cmd build'
> cargo watch -x 'cmd build'
error: Found argument 'build'' which wasn't expected, or isn't valid in this context
USAGE:
cargo watch [FLAGS] [OPTIONS]
For more information try --help
🤔 All mentioned commands work if they are run by hand in command line instead using cargo cmd dev
.
Workaround
The only way I can workaround this is to avoid commas completely. In my case i just had to run an arbitrary command:
[package.metadata.commands]
dev = "cargo watch -- cargo cmd build-and-start" # Solution
build-and-start = "cargo cmd build && cargo cmd start " # Simply needed because i cant use && in the command
build = "wasm-pack build --target web --out-name wasm --out-dir ./static/build"
start = "miniserve ./static --index index.html"