1 unstable release
| new 0.1.0 | Oct 14, 2025 |
|---|
#329 in Cargo plugins
38KB
778 lines
๐ cargo-setupx
Automate Rust project setup with modular configuration packs
A Rust-based CLI and library that automates the initial setup of new Rust projects. Provides modular configuration packs that can be selectively applied to standardize development environments.
๐ฏ Features
-
Quality Pack - Code quality configuration files
rustfmt.toml- Code formatting rulesclippy.toml- Linting configuration_typos.toml- Spell checking setupMakefile- Common development commands
-
Hooks Pack - Git hooks for automated quality checks
.githooks/pre-push- Pre-push quality gate.githooks/setup.sh- Hooks installation script- Configures
core.hooksPathautomatically
-
Architecture Pack - Project structure scaffolding
- Clean Architecture (domain, application, infrastructure, presentation)
- Additional patterns planned (hexagonal, onion - see Roadmap)
๐ฆ Installation
cargo install cargo-setupx
Or install from source:
git clone https://github.com/ricardoferreirades/cargo-setupx.git
cd cargo-setupx
cargo install --path .
๐ Quick Start
Apply All Packs
# In your Rust project directory
cargo setupx --all
Apply Specific Packs
# Quality pack only
cargo setupx --quality
# Hooks pack only
cargo setupx --hooks
# Architecture pack (clean)
cargo setupx --arch=clean
# Quality + Hooks
cargo setupx --quality --hooks
Force Overwrite
# Overwrite existing files
cargo setupx --all --force
# Skip confirmation prompt
cargo setupx --all --yes
๐ Usage
As a Cargo Subcommand
# Show help
cargo setupx --help
# Apply to current directory
cargo setupx --quality --hooks
# Apply to specific directory
cargo setupx --all /path/to/project
# Force overwrite with no prompts
cargo setupx --all --force --yes
As a Library
use cargo_setupx::{Config, apply_packs};
use std::path::Path;
let config = Config {
quality: true,
hooks: true,
arch: Some("clean".to_string()),
force: false,
yes: false,
};
apply_packs(&config, Path::new(".")).expect("Failed to apply packs");
๐ What Gets Created
Quality Pack (--quality)
Creates the following files in your project root:
clippy.toml # Clippy linter configuration
rustfmt.toml # Rustfmt formatter settings
_typos.toml # Typos spell checker config
Makefile # Development commands
Makefile commands:
make fmt- Format code (cargo fmt + taplo)make lint- Run clippy lintermake lint-fix- Auto-fix linting issuesmake check- Type check without buildingmake spell- Check spellingmake spell-fix- Auto-fix spelling errorsmake quality- Run all quality checksmake test- Run testsmake run- Run the application
Hooks Pack (--hooks)
Creates Git hooks for automated quality checks:
.githooks/
โโโ pre-push # Pre-push quality gate (executable)
โโโ setup.sh # Hook installation script (executable)
โโโ README.md # Hooks documentation
The pre-push hook runs:
- โ
Code formatting check (
cargo fmt --check) - โ
TOML formatting check (
taplo format --check) - โ
Linting (
cargo clippy -- -D warnings) - โ
Spell check (
typos) - โ
Type check (
cargo check) - โ
Tests (
cargo test)
Push is blocked if any check fails!
Architecture Pack (--arch=clean)
Note: Currently only Clean Architecture is supported. Other patterns (hexagonal, onion) are planned.
Creates Clean Architecture folder structure:
src/
โโโ domain/
โ โโโ entities/
โ โโโ repositories/
โ โโโ services/
โโโ application/
โ โโโ dto/
โ โโโ use_cases/
โโโ infrastructure/
โ โโโ database/
โ โโโ config/
โ โโโ http/
โโโ presentation/
โโโ handlers/
Each directory includes:
mod.rswith documentation- Stub files for quick start
๐ง Prerequisites
For full functionality, install these tools:
# Taplo (TOML formatter)
cargo install taplo-cli
# Typos (spell checker)
cargo install typos-cli
๐ ๏ธ Development Workflow
After running cargo setupx --all, use these commands:
# Initial setup
make setup-hooks # Configure git hooks
# Daily development
make quality # Run all checks
make fmt # Format code
make lint-fix # Fix linting issues
make spell-fix # Fix spelling
# Testing
make test # Run tests
make check # Quick type check
# Building
make build # Build release
make clean # Clean artifacts
โ๏ธ Configuration
Idempotent Setup
Running cargo setupx multiple times is safe. It will:
- Skip existing files (unless
--forceis used) - Show clear status messages (Created, Skipped, Overwrote)
- Never corrupt existing files
Force Overwrite
Use --force to overwrite existing files:
cargo setupx --all --force
Skip Confirmation
Use --yes to skip confirmation prompts:
cargo setupx --all --yes
๐จ Examples
New Project Setup
# Create new Rust project
cargo new my-awesome-project
cd my-awesome-project
# Apply all packs
cargo setupx --all
# Setup git hooks
make setup-hooks
# Verify everything works
make quality
Existing Project Setup
# In your existing project
cd my-existing-project
# Apply quality + hooks (no architecture changes)
cargo setupx --quality --hooks --yes
# Setup hooks
make setup-hooks
Library Project
# Create library
cargo new --lib my-library
cd my-library
# Apply quality pack + clean architecture
cargo setupx --quality --arch=clean
# Verify
make quality
๐งช Testing
Run the test suite:
cargo test
Run specific tests:
cargo test quality
cargo test hooks
cargo test architecture
๐ Documentation
Generate and open documentation:
cargo doc --open
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feat/amazing-feature) - Make your changes
- Run quality checks (
make quality) - Commit your changes (
git commit -m 'feat: add amazing feature') - Push to the branch (
git push origin feat/amazing-feature) - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Inspired by the need for consistent Rust project setups
- Built with Clap for CLI parsing
- Quality tools: Clippy, Rustfmt, Typos
๐ Links
๐ง Roadmap
- Support for hexagonal architecture
- Support for onion architecture
- Custom pack definitions via
.setupx.toml - CI/CD configuration packs (GitHub Actions, GitLab CI)
- Docker configuration pack
- Plugin system for community packs
- Interactive mode for pack selection
Made with โค๏ธ by Ricardo Ferreira
Dependencies
~1.6โ2.5MB
~48K SLoC