captain is a comprehensive development automation tool for Rust workspaces. It integrates seamlessly as a pre-commit hook and handles repetitive project setup, code generation, and CI/CD configuration automatically.
This project was originally forked from facet-dev.
captain automates the following tasks:
- README Generation: Generates
README.mdfiles fromREADME.md.intemplates with customizable headers and footers - Code Formatting: Runs
cargo fmtto enforce consistent code style - Pre-push Verification: Validates code before pushing (via
captain pre-push):- Runs clippy for linting
- Executes tests
- Checks documentation compilation
- Verifies all crates in workspace
- MSRV Consistency: Ensures all crates have the same Minimum Supported Rust Version
- Rust Documentation: Auto-generates rustdoc configuration
On macOS and Linux:
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/bearcove/captain/releases/latest/download/captain-installer.sh | shOn Windows (PowerShell):
powershell -ExecutionPolicy ByPass -c "irm https://github.com/bearcove/captain/releases/latest/download/captain-installer.ps1 | iex"cargo install captaincargo install --git https://github.com/bearcove/captainInitialize captain in your project:
captain initThis interactively creates:
hooks/directory with pre-commit and pre-push hookshooks/install.shto install the hooksconductor.jsonfor Conductor setup (optional).config/captain/config.styxconfiguration file.config/captain/readme-templates/with empty header/footer templatesREADME.md.intemplate (if not present)
Run captain in your workspace root to generate/update all project files:
captainThis will:
- Generate
README.mdfor the workspace and all crates - Format code with
cargo fmt - Stage all changes with
git add
Before pushing to a remote repository, run:
captain pre-pushThis performs comprehensive checks:
- Runs
cargo clippyon all crates - Executes
cargo test - Validates documentation with
cargo doc - Ensures MSRV consistency
Specify a custom directory for looking up README.md.in templates:
captain --template-dir /path/to/templatesThis searches for {crate_name}.md.in files in the specified directory, falling back
to the crate's own template if not found.
View workspace metadata and package information:
captain debug-packagesEach crate should have a README.md.in file in its directory. The generated README.md
combines three parts:
- Header (with badges and links)
- Main Content (from
README.md.in) - Footer (with license information)
Captain looks for header and footer templates in .config/captain/readme-templates/:
.config/captain/readme-templates/
├── readme-header.md
└── readme-footer.mdThese are prepended/appended to every generated README.md. If not present, no header or footer is added.
Header Template Example (readme-header.md):
# {CRATE}
[](https://github.com/your-org/{CRATE}/actions)
[](https://crates.io/crates/{CRATE})The {CRATE} placeholder will be replaced with the actual crate name.
Footer Template Example (readme-footer.md):
## License
Licensed under the MIT License.Run captain init to create empty templates that you can customize.
For README.md.in templates (main content):
- Custom directory specified via
--template-dir(if provided) - Crate's own
README.md.infile (in the crate directory) - Workspace-level
README.md.in(for the workspace README)
After running captain init, install the git hooks:
./hooks/install.shThis installs hooks that:
- pre-commit: Runs
captainto auto-generate and stage files - pre-push: Runs
captain pre-pushfor comprehensive validation
The hooks are installed to the main repo and all worktrees.
Captain is configured via .config/captain/config.styx:
@schema {source crate:captain-cli@1, cli captain}
// Captain configuration
// All options default to true. Set to false to disable.
pre-commit {
generate-readmes false
rustfmt false
cargo-lock false
}
pre-push {
clippy false
nextest false
doc-tests false
docs false
cargo-shear false
// Feature configuration
clippy-features (feature1 feature2)
doc-test-features (feature1)
docs-features (feature1)
}
All options default to true. Set to false to disable.
| Option | Description |
|---|---|
generate-readmes |
Generate README.md files from templates |
rustfmt |
Run cargo fmt to format code |
cargo-lock |
Stage Cargo.lock changes |
arborium |
Set up arborium syntax highlighting for docs |
rust-version |
Enforce consistent MSRV across crates |
edition-2024 |
Require Rust edition 2024 |
| Option | Description |
|---|---|
clippy |
Run cargo clippy with warnings as errors |
nextest |
Run tests via cargo nextest |
doc-tests |
Run documentation tests |
docs |
Build documentation with warnings as errors |
cargo-shear |
Check for unused dependencies |
clippy-features |
Features to pass to clippy (child node with args) |
doc-test-features |
Features to pass to doc tests (child node with args) |
docs-features |
Features to pass to rustdoc (child node with args) |
When captain runs, it automatically stages all generated files with git add.
If captain is updated mid-development, the new changes might appear in an unrelated PR.
This is by design—keep captain stable during active work.
Your project should:
- Be a Rust workspace or single crate with
Cargo.toml - Have git initialized
- Have
README.md.intemplate files for any crates you want documented
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.