cargo-setupx 0.1.0

Rust-based CLI and library that automates the initial setup of new Rust projects with modular configuration packs
Documentation
# ๐Ÿ“˜ 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.

[![Crates.io](https://img.shields.io/crates/v/cargo-setupx.svg)](https://crates.io/crates/cargo-setupx)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

## ๐ŸŽฏ Features

- **Quality Pack** - Code quality configuration files
  - `rustfmt.toml` - Code formatting rules
  - `clippy.toml` - Linting configuration
  - `_typos.toml` - Spell checking setup
  - `Makefile` - 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.hooksPath` automatically

- **Architecture Pack** - Project structure scaffolding
  - Clean Architecture (domain, application, infrastructure, presentation)
  - Additional patterns planned (hexagonal, onion - see Roadmap)

## ๐Ÿ“ฆ Installation

```bash
cargo install cargo-setupx
```

Or install from source:

```bash
git clone https://github.com/ricardoferreirades/cargo-setupx.git
cd cargo-setupx
cargo install --path .
```

## ๐Ÿš€ Quick Start

### Apply All Packs

```bash
# In your Rust project directory
cargo setupx --all
```

### Apply Specific Packs

```bash
# 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

```bash
# Overwrite existing files
cargo setupx --all --force

# Skip confirmation prompt
cargo setupx --all --yes
```

## ๐Ÿ“– Usage

### As a Cargo Subcommand

```bash
# 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

```rust
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 linter
- `make lint-fix` - Auto-fix linting issues
- `make check` - Type check without building
- `make spell` - Check spelling
- `make spell-fix` - Auto-fix spelling errors
- `make quality` - Run all quality checks
- `make test` - Run tests
- `make 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:
1. โœ… Code formatting check (`cargo fmt --check`)
2. โœ… TOML formatting check (`taplo format --check`)
3. โœ… Linting (`cargo clippy -- -D warnings`)
4. โœ… Spell check (`typos`)
5. โœ… Type check (`cargo check`)
6. โœ… 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.rs` with documentation
- Stub files for quick start

## ๐Ÿ”ง Prerequisites

For full functionality, install these tools:

```bash
# Taplo (TOML formatter)
cargo install taplo-cli

# Typos (spell checker)
cargo install typos-cli
```

## ๐Ÿ› ๏ธ Development Workflow

After running `cargo setupx --all`, use these commands:

```bash
# 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 `--force` is used)
- Show clear status messages (Created, Skipped, Overwrote)
- Never corrupt existing files

### Force Overwrite

Use `--force` to overwrite existing files:

```bash
cargo setupx --all --force
```

### Skip Confirmation

Use `--yes` to skip confirmation prompts:

```bash
cargo setupx --all --yes
```

## ๐ŸŽจ Examples

### New Project Setup

```bash
# 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

```bash
# 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

```bash
# 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:

```bash
cargo test
```

Run specific tests:

```bash
cargo test quality
cargo test hooks
cargo test architecture
```

## ๐Ÿ“š Documentation

Generate and open documentation:

```bash
cargo doc --open
```

## ๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

1. Fork the repository
2. Create your feature branch (`git checkout -b feat/amazing-feature`)
3. Make your changes
4. Run quality checks (`make quality`)
5. Commit your changes (`git commit -m 'feat: add amazing feature'`)
6. Push to the branch (`git push origin feat/amazing-feature`)
7. Open a Pull Request

## ๐Ÿ“„ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## ๐Ÿ™ Acknowledgments

- Inspired by the need for consistent Rust project setups
- Built with [Clap]https://github.com/clap-rs/clap for CLI parsing
- Quality tools: [Clippy]https://github.com/rust-lang/rust-clippy, [Rustfmt]https://github.com/rust-lang/rustfmt, [Typos]https://github.com/crate-ci/typos

## ๐Ÿ”— Links

- [Repository]https://github.com/ricardoferreirades/cargo-setupx
- [Issue Tracker]https://github.com/ricardoferreirades/cargo-setupx/issues
- [Documentation]https://docs.rs/cargo-setupx

## ๐Ÿšง 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**