cargo-setupx 0.1.0

Rust-based CLI and library that automates the initial setup of new Rust projects with modular configuration packs
Documentation
//! Quality pack - generates code quality configuration files

use crate::error::Result;
use crate::templates;
use crate::utils::write_file;
use std::path::Path;

/// Apply the quality pack to the project
pub fn apply(project_path: &Path, force: bool) -> Result<()> {
    println!("📦 Applying Quality Pack...");

    // Create clippy.toml
    let clippy_path = project_path.join("clippy.toml");
    write_file(&clippy_path, templates::CLIPPY_TOML, force)?;

    // Create rustfmt.toml
    let rustfmt_path = project_path.join("rustfmt.toml");
    write_file(&rustfmt_path, templates::RUSTFMT_TOML, force)?;

    // Create _typos.toml
    let typos_path = project_path.join("_typos.toml");
    write_file(&typos_path, templates::TYPOS_TOML, force)?;

    // Create Makefile
    let makefile_path = project_path.join("Makefile");
    write_file(&makefile_path, templates::MAKEFILE, force)?;

    println!();
    Ok(())
}

#[cfg(test)]
mod tests {
    use super::*;
    use tempfile::tempdir;

    #[test]
    fn test_quality_pack_creates_files() {
        let temp_dir = tempdir().unwrap();
        let project_path = temp_dir.path();

        apply(project_path, false).unwrap();

        assert!(project_path.join("clippy.toml").exists());
        assert!(project_path.join("rustfmt.toml").exists());
        assert!(project_path.join("_typos.toml").exists());
        assert!(project_path.join("Makefile").exists());
    }

    #[test]
    fn test_quality_pack_respects_force_flag() {
        let temp_dir = tempdir().unwrap();
        let project_path = temp_dir.path();

        // First application
        apply(project_path, false).unwrap();

        // Second application without force should fail
        let result = apply(project_path, false);
        assert!(result.is_err());

        // Second application with force should succeed
        let result = apply(project_path, true);
        assert!(result.is_ok());
    }
}