use clap::Parser;
use clap::builder::Styles;
use clap::builder::styling::{AnsiColor, Effects};
use std::path::PathBuf;
use crate::{config::Config, errors::GeneralError};
use crate::commands::Commands;
const STYLES: Styles = Styles::styled()
.header(AnsiColor::Green.on_default().effects(Effects::BOLD))
.usage(AnsiColor::Green.on_default().effects(Effects::BOLD))
.literal(AnsiColor::Cyan.on_default().effects(Effects::BOLD))
.placeholder(AnsiColor::Cyan.on_default());
#[derive(Parser, Debug)]
#[command(version, name = "n4n5", about = "n4n5 CLI", long_about = None, styles = STYLES)]
pub struct CliArgs {
#[arg(long, value_name = "FILE")]
pub config: Option<PathBuf>,
#[arg(short, long, action = clap::ArgAction::Count)]
pub debug: u8,
#[arg(long, action = clap::ArgAction::SetTrue)]
pub use_input: bool,
#[command(subcommand)]
pub command: Commands,
}
pub fn cli_main() -> Result<(), GeneralError> {
let cli_args = CliArgs::parse();
let CliArgs {
command,
use_input,
debug,
config,
} = cli_args;
let mut config = Config::try_new(config, debug, use_input)?;
command.invoke(&mut config)
}