cargo-run
A powerful, fast, and developer-friendly CLI tool for managing project scripts in Rust.
Thinknpm scripts,make, orjust— but built specifically for the Rust ecosystem, workspace-aware, and ready for the upcomingcargo-script(RFC 3502) era.
What's new in 0.6
- Workspace orchestration —
workspace = "all" | "parallel"runs a script across every member crate. CLI override:--workspace=parallel(guide) - Cargo-script (RFC 3502) integration — invoke
.rssingle-file packages directly fromScripts.toml. Stable + nightly auto-detected. (guide) - CI/CD templates —
cargo script init --template github-actionsscaffoldsScripts.toml+ the matching workflow. (guide) - Lifecycle hooks —
pre,post,on_success,on_failureper script. - Parallel execution —
--parallelandworkspace = "parallel"(Tokio). - Watch mode —
cargo script test --watchre-runs on file changes. - Parameters —
args,defaults,{{name}}substitution. - JSON output —
--jsonfor pipeline-friendly results.
See docs/ADVANCED_FEATURES.md for the full reference and examples/ for runnable demos.
Why cargo-run?
Stop writing one-off shell scripts. cargo-run provides a unified, type-safe way to manage all your project automation:
- ✅ Workspace-aware — Run scripts across every member, sequentially or in parallel
- ✅ Cargo-script ready — First-class RFC 3502 (
.rs) script support - ✅ Zero runtime dependencies — Single binary, fast startup
- ✅ Cross-platform — Works on Windows, macOS, and Linux
- ✅ Modern CLI UX — Simplified syntax, interactive selection, shell completions
- ✅ Powerful features — Script chaining, hooks, parallel/watch, parameters, env vars, toolchains
- ✅ CI/CD ready — Templates, validation, JSON output
- ✅ Rust-native — Built with Rust, for Rust projects
Quick Comparison
| Feature | cargo-run |
make |
just |
cargo-make |
npm scripts |
|---|---|---|---|---|---|
| Zero runtime dependencies | ✅ | ✅ | ✅ | ✅ | ❌ (Node.js) |
| Cross-platform | ✅ | ⚠️ | ✅ | ✅ | ✅ |
| Workspace orchestration | ✅ | ❌ | ❌ | ✅ | ❌ |
| Parallel execution | ✅ | ⚠️ | ❌ | ✅ | ⚠️ |
| Watch mode (built-in) | ✅ | ❌ | ❌ | ❌ | ❌ |
| Cargo-script (RFC 3502) | ✅ | ❌ | ❌ | ❌ | ❌ |
| CI/CD templates | ✅ | ❌ | ❌ | ⚠️ | ❌ |
| Lifecycle hooks | ✅ | ❌ | ❌ | ✅ | ⚠️ |
| Parameters / substitution | ✅ | ⚠️ | ✅ | ✅ | ⚠️ |
| JSON output | ✅ | ❌ | ⚠️ | ❌ | ❌ |
| Shell completions | ✅ | ⚠️ | ✅ | ✅ | ✅ |
| Dry-run mode | ✅ | ❌ | ✅ | ✅ | ❌ |
| Validation | ✅ | ❌ | ⚠️ | ⚠️ | ❌ |
| Toolchain support | ✅ | ❌ | ❌ | ⚠️ | ❌ |
📦 Installation
After installation, you'll have multiple ways to invoke the tool:
cargo script— Recommended: Use as a Cargo subcommand (e.g.,cargo script run build)cargo-script— Direct binary invocationcgs— Short alias (used in examples below for brevity)
Note: When installed via cargo install, the cargo-script binary is automatically available in your PATH, enabling cargo script subcommand usage.
⚡ Quick Start
-
Initialize a
Scripts.tomlfile:# Using Cargo subcommand (recommended) # Or using direct binary -
Run a script:
# Direct script execution # Explicit form # Or using direct binary -
Discover scripts interactively:
# Interactive fuzzy selection # Show all scripts # Filter scripts -
Preview what would run (dry-run):
-
Validate your configuration:
That's it! You're ready to go. 🎉
💡 Tip: Using
cargo scriptintegrates seamlessly with Cargo's ecosystem and provides a familiar interface for Rust developers.
📚 Features
Core Features
- Script Execution — Run scripts defined in
Scripts.toml - Script Chaining — Compose complex workflows with
include - Environment Variables — Global, script-specific, and command-line overrides
- Multiple Interpreters — bash, zsh, PowerShell, cmd, or custom
- Toolchain Support — Rust toolchains via rustup, Python versions
- Requirements Checking — Validate tool versions before execution
v0.6 Highlights
- Workspace Mode —
workspace = "all" \| "parallel"per script (guide) - Cargo Script Integration — invoke
.rsfiles (RFC 3502) (guide) - CI/CD Templates —
init --template github-actions \| gitlab-ci \| rust-project \| workspace(guide) - Lifecycle Hooks —
pre,post,on_success,on_failure - Parallel Execution —
--parallel <SCRIPT>and workspace-parallel - Watch Mode —
--watch,--watch-path,--watch-exclude - Parameters —
args,defaults,{{name}}substitution - JSON Output —
--jsonfor machine-readable execution results - Workspace Subcommand —
cargo script workspace list / run
Developer Experience
- Simplified Syntax — Run scripts directly:
cargo script build - Interactive Selection — Fuzzy-find scripts with
--interactiveflag - Script Filtering — Filter scripts by name or description
- Shell Completions — Tab completion for bash, zsh, fish, and PowerShell
- Dry-Run Mode — Preview execution without side effects
- Verbosity Control —
--quietand--verboseflags for output control - Optional Metrics —
--no-metricsto suppress performance output - Helpful Errors — Actionable error messages with quick-fix suggestions
- Validation — Catch configuration errors early
- Performance Metrics — Track script execution times (optional)
v0.6 examples
# Scripts.toml — workspace + hooks + parameters + cargo-script
[]
= "1"
[]
= { = ["fmt-check", "lint", "test-parallel"], = "Full CI" }
= "cargo fmt --all -- --check"
= "cargo clippy --workspace --all-targets -- -D warnings"
# Run cargo test in every workspace member, in parallel.
= { = "cargo test", = "parallel" }
# Parameterised deploy with hooks.
[]
= "kubectl apply -f manifests/{{env}}.yaml"
= ["env"]
= { = "staging" }
= ["fmt-check", "lint"]
= ["rollback"]
# A cargo-script (RFC 3502) Rust file
[]
= "./scripts/audit.rs"
= "Run a Rust audit script"
📖 Usage Guide
Initialize Scripts.toml
Create a new Scripts.toml file with sensible defaults:
# Using Cargo subcommand (recommended)
# Or using direct binary
This creates a Scripts.toml file with:
[]
[]
= "cargo run"
= { = "cargo build", = { = "info" } }
= "cargo build --release"
= { = "cargo test", = { = "warn" } }
= "cargo doc --no-deps --open"
Run Scripts
# Direct script execution
# Explicit form
# With flags
# Interactive selection
# Quiet mode (minimal output)
# Verbose mode (detailed output)
Script Configuration
Simple Script
[]
= "cargo build"
Script with Metadata
[]
= {
command = "cargo build",
= "Build the project in release mode",
= { = "info" }
}
Script with Interpreter
[]
= {
interpreter = "bash",
= "./scripts/deploy.sh",
= "Deploy to production"
}
Script Chaining (Includes)
[]
= "cargo clean"
= "cargo doc --no-deps"
= "cargo publish --dry-run"
= "cargo package --list"
= {
include = ["prepublish_clean", "prepublish_doc", "prepublish_dry", "prepublish_check"],
= "Run all prepublish checks"
}
Script with Requirements
[]
= {
command = "./deploy.sh",
= ["docker >= 19.03", "kubectl >= 1.18"],
= "stable",
= "Deploy application"
}
CI/CD-like Format
[]
= "build"
= "cargo build"
= "Build the project"
[]
= "test"
= "cargo test"
= ["rustup >= 1.70"]
= "stable"
Environment Variables
Global Environment Variables
[]
= "1"
= "info"
Script-Specific Environment Variables
[]
= {
command = "cargo test",
= { = "debug" }
}
Command-Line Overrides
# Using Cargo subcommand
# Or using direct binary
Precedence Order:
- Command-line overrides (
--env) - Script-specific (
envin script) - Global (
[global_env])
Show All Scripts
# Show all scripts
# Filter scripts by name or description
# Default behavior - show scripts when no command provided
Output:
Script Description
-------- --------------------------------------
build Build the project
test Run tests
release Build release version
With filter:
)
Dry-Run Mode
Preview what would be executed without actually running it:
# Simplified syntax
# Explicit form
Interactive Script Selection
Use fuzzy selection to find and run scripts interactively:
# Interactive mode
# Or via run command
This opens an interactive fuzzy finder where you can:
- Type to search scripts
- See script descriptions
- Select and run scripts easily
Output:
DRY-RUN MODE: Preview of what would be executed
================================================================================
📋 Would run script: [ prepublish ]
Description: Run all prepublish checks
Would run include scripts:
📋 Would run script: [ prepublish_clean ]
Command: cargo clean
📋 Would run script: [ prepublish_doc ]
Command: cargo doc --no-deps
📋 Would run script: [ prepublish_dry ]
Command: cargo publish --dry-run
📋 Would run script: [ prepublish_check ]
Command: cargo package --list
No commands were actually executed.
Shell Completions
Enable tab completion for a better developer experience:
Bash:
# Using Cargo subcommand (recommended)
# Or system-wide:
|
# Or using direct binary
Zsh:
# Using Cargo subcommand (recommended)
# Or using direct binary
# Add to ~/.zshrc:
fpath=(/.zsh/completions )
&&
Fish:
# Using Cargo subcommand (recommended)
# Or using direct binary
PowerShell:
# Using Cargo subcommand (recommended)
cargo script completions power-shell > $PROFILE
# Or using direct binary
cgs completions power-shell > completions.ps1
. .\completions.ps1
After installation, restart your shell and enjoy tab completion! 🎉
Validation
Catch configuration errors before they cause problems:
# Using Cargo subcommand (recommended)
# Or using direct binary
What it checks:
- ✅ TOML syntax validity
- ✅ Script references in
includearrays - ✅ Tool requirements (checks if tools are installed)
- ✅ Toolchain requirements (checks if Rust/Python toolchains are installed)
Example output:
✓ All validations passed!
With errors:
❌ Validation Errors:
1. Script 'release': Script 'release' references non-existent script 'build'
2. Script 'deploy': Required tool 'docker' is not installed or not in PATH
✗ Found 2 error(s)
CI/CD Integration:
# .github/workflows/ci.yml
- name: Validate Scripts.toml
run: cargo script validate
Error Messages
cargo-run provides helpful, actionable error messages:
Script Not Found:
Invalid TOML:
Missing Tool:
Use Cases
Development Workflow
[]
= "cargo run"
= "cargo test"
= { = "cargo watch -x test", = ["cargo-watch"] }
= "cargo clippy -- -D warnings"
= "cargo fmt --check"
= { = ["fmt", "lint", "test"], = "Run all checks" }
CI/CD Pipeline
[]
= {
include = ["check", "test", "build"],
= "Run CI pipeline"
}
[]
= "cargo clippy -- -D warnings"
[]
= "cargo test --all-features"
[]
= "cargo build --release"
Multi-Language Projects
[]
= "cargo build"
= {
command = "python setup.py build",
= ["python >= 3.8"],
= "python:3.8"
}
= { = ["build-rust", "build-python"] }
Deployment Scripts
[]
= {
command = "./scripts/deploy.sh staging",
= ["docker >= 19.03", "kubectl >= 1.18"],
= { = "staging" }
}
= {
command = "./scripts/deploy.sh production",
= ["docker >= 19.03", "kubectl >= 1.18"],
= { = "production" }
}
🔧 Advanced Configuration
Custom Scripts Path
Use a different Scripts.toml file:
# Using Cargo subcommand
# Or using direct binary
Performance Metrics
Script execution times are automatically tracked and displayed (can be disabled):
# Show metrics (default)
# Hide metrics
Output:
Scripts Performance
--------------------------------------------------------------------------------
✔️ Script: prepublish_clean 🕒 Running time: 1.23s
✔️ Script: prepublish_doc 🕒 Running time: 3.45s
✔️ Script: prepublish_dry 🕒 Running time: 2.10s
🕒 Total running time: 6.78s
Verbosity Control
Control output verbosity with --quiet and --verbose flags:
# Quiet mode - minimal output
# Verbose mode - detailed output
# Normal mode (default)
📚 Documentation
- Workspace Guide — multi-crate orchestration
- Cargo-Script Integration —
.rsscript files (RFC 3502) - CI/CD Guide — templates + JSON output
- Advanced Features — hooks, parallel, watch, parameters
- Migration Guides — moving from
just/make/cargo-make/npm scripts - Examples — runnable demo projects
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📄 License
This project is licensed under the MIT License.
🙏 Acknowledgments
- Inspired by
npm scripts,make,just, andcargo-make - Designed to complement Rust RFC 3502 (
cargo-script) — single-file Rust scripts - Built with clap for excellent CLI experience
- Uses colored for beautiful terminal output
- Parallel execution powered by tokio; watch mode by notify
Made with ❤️ for the Rust community