cargo_setupx/
lib.rs

1//! # cargo-setupx
2//!
3//! A Rust-based CLI and library that automates the initial setup of new Rust projects.
4//! Provides modular configuration packs that can be selectively applied to standardize
5//! development environments.
6//!
7//! ## Features
8//!
9//! - **Quality Pack**: Generates code quality configuration files
10//! - **Hooks Pack**: Sets up Git hooks for automated quality checks
11//! - **Architecture Pack**: Scaffolds project structure based on patterns
12//!
13//! ## Usage as a Library
14//!
15//! ```no_run
16//! use cargo_setupx::{Config, apply_packs};
17//! use std::path::Path;
18//!
19//! let config = Config {
20//!     quality: true,
21//!     hooks: true,
22//!     arch: Some("clean".to_string()),
23//!     force: false,
24//!     yes: false,
25//! };
26//!
27//! apply_packs(&config, Path::new(".")).expect("Failed to apply packs");
28//! ```
29
30pub mod error;
31pub mod packs;
32pub mod templates;
33pub mod utils;
34
35use error::Result;
36use std::path::Path;
37
38/// Configuration for cargo-setupx
39#[derive(Debug, Clone)]
40pub struct Config {
41    /// Enable quality pack (rustfmt.toml, clippy.toml, _typos.toml, Makefile)
42    pub quality: bool,
43    /// Enable hooks pack (.githooks)
44    pub hooks: bool,
45    /// Architecture pack name (e.g., "clean")
46    pub arch: Option<String>,
47    /// Force overwrite existing files
48    pub force: bool,
49    /// Skip confirmation prompts
50    pub yes: bool,
51}
52
53/// Apply selected packs to the project
54pub fn apply_packs(config: &Config, project_path: &Path) -> Result<()> {
55    println!("🚀 Setting up project at: {}", project_path.display());
56    println!();
57
58    if config.quality {
59        packs::quality::apply(project_path, config.force)?;
60    }
61
62    if config.hooks {
63        packs::hooks::apply(project_path, config.force)?;
64    }
65
66    if let Some(arch_type) = &config.arch {
67        packs::architecture::apply(project_path, arch_type, config.force)?;
68    }
69
70    println!();
71    println!("✅ Setup complete!");
72    Ok(())
73}