cargo-q: Run Multiple Cargo Commands with One Entry Point
Rust developers often run several Cargo commands in a row:
cargo fmt && cargo check && cargo test
# or run them one at a time
cargo fmt
cargo check
cargo test
Both approaches work, but they become tedious as the list grows.
cargo-q lets you run multiple Cargo commands through a single entry point. Commands run sequentially by default; parallel execution is experimental. Its parsing rules are strict, and its errors are clear.
Next time, try cargo q fmt check test.
Installation
Requires Rust 1.78.0 or later (MSRV).
cargo install cargo-q --locked
Sequential Commands
Each bare token is a Cargo subcommand, run in order:
cargo q check
cargo q check test
# cargo check, then cargo test if check succeeds
Arguments
- A token starting with
-is an argument to the current command. - Any other bare token starts a new Cargo subcommand.
cargo q build -r test --no-run
# 1. cargo build -r
# 2. cargo test --no-run
Values that do not start with - (features, packages, …) must be quoted or attached with =:
cargo q "test --features feature1"
cargo q build --features=feature1
Unknown bare tokens are not guessed:
cargo q build --features feature1
# error: 'feature1' is not a cargo subcommand
# help: quote the whole command: cargo q "build --features feature1"
# help: or attach the value: cargo q build --features=feature1
Same for packages: cargo q run -p oven errors; use "run -p oven" or -p=oven.
If a bare token is a valid subcommand, cargo-q always starts a new command:
cargo q build --features test # cargo build --features, then cargo test
cargo q "build --features test" # feature = test
cargo q build --features=test # same
Dry Run
-n / --dry-run prints the parsed commands without running them:
cargo q -n build -r test --no-run
# 2 command(s), sequentially:
# cargo build -r
# cargo test --no-run
Failures
Stops at the first failure (like && in shell). -k / --keep-going runs the rest and still returns the first failure's exit code:
cargo q clippy test # skip test if clippy fails
cargo q -k fmt clippy test # run all; exit with first failure
In parallel mode, already-started commands can finish; unstarted ones are skipped.
Parallel (Experimental)
cargo q -p check test
Not always faster: check, build, and test often share a target directory and wait on the same lock. Use it for workflows that do not compete for the same resources.
Verbose
-v / --verbose shows each command's output as it runs:
cargo q -v check test
Source: guuzaa/cargo-q.