From 172030598520a33f069c907da62038dd5aab6fbe Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Wed, 4 Feb 2026 15:45:22 +0000 Subject: [PATCH] Initial upload: GitPulse - Developer Productivity Analyzer CLI tool --- src/cli/mod.rs | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/cli/mod.rs diff --git a/src/cli/mod.rs b/src/cli/mod.rs new file mode 100644 index 0000000..b174765 --- /dev/null +++ b/src/cli/mod.rs @@ -0,0 +1,84 @@ +pub mod analyze; +pub mod dashboard; +pub mod export; +pub mod init; + +use anyhow::{Context, Result}; +use clap::{Parser, Subcommand}; +use std::path::PathBuf; + +use crate::commands::analyze::AnalyzeArgs; +use crate::commands::export::ExportArgs; +use crate::config::Config; + +#[derive(Parser, Debug)] +#[command(name = "gitpulse")] +#[command(author, version, about, long_about = None)] +#[command(after_help = "For more information, visit https://github.com/gitpulse/gitpulse")] +pub struct Cli { + #[command(subcommand)] + pub command: Commands, + + #[arg(short, long, global = true, value_name = "PATH")] + #[arg(help = "Path to git repository (defaults to current directory)")] + pub repo: Option, + + #[arg(short, long, global = true)] + #[arg(help = "Enable verbose output")] + pub verbose: bool, + + #[arg(short, long, global = true, value_name = "FILE")] + #[arg(help = "Path to configuration file")] + pub config: Option, +} + +#[derive(Subcommand, Debug)] +pub enum Commands { + #[command(name = "analyze", alias = "a")] + #[command(about = "Analyze git repository and display statistics")] + #[command(long_about = "Analyze git repository and display commit frequency, code churn, contributor statistics, and more.")] + Analyze(AnalyzeArgs), + + #[command(name = "dashboard", alias = "d")] + #[command(about = "Launch interactive terminal dashboard")] + #[command(long_about = "Launch an interactive terminal dashboard showing project health, commit trends, and contributor metrics.")] + Dashboard {}, + + #[command(name = "export", alias = "e")] + #[command(about = "Export analysis results to JSON or CSV")] + #[command(long_about = "Export analysis results to JSON or CSV format for external processing.")] + Export(ExportArgs), + + #[command(name = "init")] + #[command(about = "Initialize gitpulse configuration")] + #[command(long_about = "Create a default configuration file in the appropriate location.")] + Init {}, + + #[command(name = "show-config")] + #[command(about = "Show current configuration")] + #[command(long_about = "Display the current configuration with all effective values.")] + ShowConfig {}, +} + +impl Cli { + pub fn run(self) -> Result<()> { + let config = Config::load(self.config.as_ref())?; + + match self.command { + Commands::Analyze(args) => { + commands::analyze::run(self.repo, args, &config, self.verbose) + } + Commands::Dashboard {} => { + commands::dashboard::run(self.repo, &config, self.verbose) + } + Commands::Export(args) => { + commands::export::run(self.repo, args, &config, self.verbose) + } + Commands::Init {} => commands::init::run(&config), + Commands::ShowConfig {} => { + println!("{:#?}", config); + Ok(()) + } + } + } +}