use anyhow::Result;
use clap::Args;
#[derive(Args, Clone, Default)]
pub struct StatusArgs {
#[arg(short, long, action = clap::ArgAction::Count)]
pub verbose: u8,
#[arg(long)]
pub show_config: Option<bool>,
#[arg(long, value_enum)]
pub format: Option<String>,
#[arg(long)]
pub compact: Option<bool>,
}
pub async fn execute(_args: StatusArgs) -> Result<()> {
use crate::{
cli::banner, cli::output::*, config::CONFIG, git::GitRepo,
scan::static_data::patterns::get_pattern_library,
};
banner::print_banner(None);
let repo = match GitRepo::discover() {
Ok(repo) => {
styled!("{} Git repository detected", ("✅", "success_symbol"));
let branch = repo.current_branch()?;
styled!(" Current branch: {}", (branch, "branch"));
repo
}
Err(_) => {
styled!("{} Not in a git repository", ("❌", "error_symbol"));
return Ok(());
}
};
styled!("{} Configuration loaded", ("✅", "success_symbol"));
styled!(
" Max file size: {}MB",
(CONFIG.scanner.max_file_size_mb.to_string(), "number")
);
styled!(
" Include binary files: {}",
(CONFIG.scanner.include_binary.to_string(), "property")
);
styled!(
" Entropy analysis: {}",
(
CONFIG.scanner.enable_entropy_analysis.to_string(),
"property"
)
);
let pattern_lib = get_pattern_library();
styled!(
"{} Scanner ready with {} patterns",
("✅", "success_symbol"),
(pattern_lib.count().to_string(), "number")
);
let hooks_dir = repo.git_dir().join("hooks");
let hook_names = ["pre-commit", "commit-msg", "post-checkout", "pre-push"];
let mut installed_hooks = Vec::new();
let mut missing_hooks = Vec::new();
for hook_name in &hook_names {
let hook_path = hooks_dir.join(hook_name);
if hook_path.exists() {
if let Ok(content) = std::fs::read_to_string(&hook_path) {
if content.contains("guardy hooks run") || content.contains("# Guardy hook") {
installed_hooks.push(*hook_name);
} else {
styled!(
" {} {} exists but not managed by guardy",
("⚠️", "warning_symbol"),
(hook_name, "property")
);
}
}
} else {
missing_hooks.push(*hook_name);
}
}
if !installed_hooks.is_empty() {
styled!(
"{} Installed hooks: {}",
("✅", "success_symbol"),
(installed_hooks.join(", "), "property")
);
}
if !missing_hooks.is_empty() {
styled!(
"{} Missing hooks: {}",
("❌", "error_symbol"),
(missing_hooks.join(", "), "property")
);
styled!(
"Run {} to install missing hooks",
("'guardy install'", "command")
);
}
if installed_hooks.len() == hook_names.len() {
styled!(
"{} Guardy is fully configured and ready!",
("🎉", "success_symbol")
);
} else {
styled!("Status: {}", ("Partially configured", "warning"));
}
Ok(())
}