guardy 0.2.4

Fast, secure git hooks in Rust with secret scanning and protected file synchronization
Documentation
use anyhow::Result;
use clap::{Args, Subcommand};

#[derive(Args, Clone)]
pub struct ConfigArgs {
    #[command(subcommand)]
    pub command: ConfigCommand,
}

#[derive(Subcommand, Clone)]
pub enum ConfigCommand {
    /// Display current merged configuration
    Show {
        /// Output format: json, toml, yaml
        #[arg(short, long, default_value = "yaml")]
        format: String,
    },
}

pub async fn execute(
    args: ConfigArgs,
    _custom_config: Option<&str>,
    _verbosity_level: u8,
) -> Result<()> {
    use crate::{
        cli::banner,
        cli::output::*,
        config::{CONFIG, ConfigFormat},
    };

    match args.command {
        ConfigCommand::Show { format } => {
            // Print banner without context
            banner::print_banner(None);

            styled!(
                "Displaying current configuration in {} format...",
                (&format, "property")
            );

            let config_format = match format.to_lowercase().as_str() {
                "json" => ConfigFormat::Json,
                "yaml" | "yml" => ConfigFormat::Yaml,
                "toml" => ConfigFormat::Toml,
                _ => {
                    return Err(anyhow::anyhow!(
                        "Unsupported format: {}. Use json, toml, or yaml",
                        format
                    ));
                }
            };

            // Use the highlighted export if terminal supports it, otherwise plain
            let output = if is_terminal::IsTerminal::is_terminal(&std::io::stdout()) {
                CONFIG.export_config_highlighted(config_format)?
            } else {
                CONFIG.export_config(config_format)?
            };

            println!("{output}");
        }
    }

    Ok(())
}