use anyhow::Result;
use clap::{Args, Subcommand};
#[derive(Args, Clone)]
pub struct ConfigArgs {
#[command(subcommand)]
pub command: ConfigCommand,
}
#[derive(Subcommand, Clone)]
pub enum ConfigCommand {
Show {
#[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 } => {
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
));
}
};
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(())
}