use clap::Subcommand;
use color_eyre::eyre::Result;
use std::path::PathBuf;
#[derive(Debug, Subcommand)]
pub enum GitCommands {
Status {
#[arg(default_value = ".")]
path: PathBuf,
},
Branch {
#[arg(default_value = ".")]
path: PathBuf,
},
Clone {
url: String,
target: Option<PathBuf>,
},
Init {
#[arg(default_value = ".")]
path: PathBuf,
},
}
#[derive(Debug, Subcommand)]
pub enum HookCommands {
Install {
#[arg(default_value = ".")]
root: PathBuf,
},
Uninstall {
#[arg(default_value = ".")]
root: PathBuf,
},
Run {
name: String,
args: Vec<String>,
},
}
pub async fn execute_git(subcommand: &GitCommands) -> Result<()> {
match subcommand {
GitCommands::Status { path } => {
let status = nargo_git::get_status(path).map_err(|e| color_eyre::eyre::eyre!(e))?;
println!("📊 Git Status for {}:", path.display());
if status.is_empty() {
println!(" Clean");
}
else {
for (file, stat) in status {
println!(" {} -> {}", file, stat);
}
}
}
GitCommands::Branch { path } => {
let branch = nargo_git::get_current_branch(path).map_err(|e| color_eyre::eyre::eyre!(e))?;
println!("🌿 Current branch: {}", branch);
}
GitCommands::Clone { url, target } => {
println!("📥 Cloning {}...", url);
nargo_git::clone(url, target.as_ref().map(|v| &**v)).map_err(|e| color_eyre::eyre::eyre!(e))?;
println!("✅ Clone completed!");
}
GitCommands::Init { path } => {
nargo_git::init(path).map_err(|e| color_eyre::eyre::eyre!(e))?;
println!("✅ Git repository initialized at {}", path.display());
}
}
Ok(())
}
pub async fn execute_hooks(subcommand: &HookCommands) -> Result<()> {
match subcommand {
HookCommands::Install { root } => {
nargo_hooks::NargoHooks::install(root).map_err(|e| color_eyre::eyre::eyre!(e))?;
println!("✅ Git hooks installed successfully.");
}
HookCommands::Uninstall { root } => {
nargo_hooks::NargoHooks::uninstall(root).map_err(|e| color_eyre::eyre::eyre!(e))?;
println!("✅ Git hooks uninstalled successfully.");
}
HookCommands::Run { name, args } => {
nargo_hooks::NargoHooks::run(name, args.clone(), None).await.map_err(|e| color_eyre::eyre::eyre!(e))?;
}
}
Ok(())
}