diff --git a/src/commands/init.rs b/src/commands/init.rs new file mode 100644 index 0000000..ad22b08 --- /dev/null +++ b/src/commands/init.rs @@ -0,0 +1,69 @@ +use crate::config::Config; +use anyhow::{Context, Result}; +use std::fs; +use std::path::PathBuf; + +pub fn run(config: &Config) -> Result<()> { + let config_path = Config::config_path()?; + + if config_path.exists() { + println!("Configuration file already exists at: {}", config_path.display()); + println!("Use 'gitpulse show-config' to view current configuration."); + return Ok(()); + } + + if let Some(parent) = config_path.parent() { + fs::create_dir_all(parent) + .with_context(|| format!("Failed to create config directory: {}", parent.display()))?; + } + + let config_content = format!( + r#"# GitPulse Configuration +# Generated by `gitpulse init` + +[analysis] +# Default time period for analysis (e.g., "30 days", "2 weeks", "1 month") +default_time_period = "30 days" +# Maximum number of contributors to show +max_contributors = 50 +# Include merge commits in analysis +include_merges = false +# Enable refactoring detection +refactoring_detection = true + +[display] +# Dashboard theme: "dark", "light", or custom +theme = "dark" +# Height of charts in dashboard +chart_height = 10 +# Use compact table layout +compact_tables = false +# Show sparkline charts +show_sparklines = true + +[export] +# Default export format +default_format = "json" +# Include timestamps in export +include_timestamps = true +# Indent JSON output +indent_json = true + +[colors] +# Color scheme for dashboard +primary = "blue" +secondary = "green" +accent = "yellow" +error = "red" +background = "black" +"#, + ); + + fs::write(&config_path, config_content) + .with_context(|| format!("Failed to write config to: {}", config_path.display()))?; + + println!("Configuration file created at: {}", config_path.display()); + println!("Edit this file to customize gitpulse behavior."); + + Ok(()) +}