use crate::error::Result;
use crate::templates;
use crate::utils::write_file;
use std::path::Path;
pub fn apply(project_path: &Path, force: bool) -> Result<()> {
println!("📦 Applying Quality Pack...");
let clippy_path = project_path.join("clippy.toml");
write_file(&clippy_path, templates::CLIPPY_TOML, force)?;
let rustfmt_path = project_path.join("rustfmt.toml");
write_file(&rustfmt_path, templates::RUSTFMT_TOML, force)?;
let typos_path = project_path.join("_typos.toml");
write_file(&typos_path, templates::TYPOS_TOML, force)?;
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();
apply(project_path, false).unwrap();
let result = apply(project_path, false);
assert!(result.is_err());
let result = apply(project_path, true);
assert!(result.is_ok());
}
}