use std::path::PathBuf;
use clap::{Parser, Subcommand};
use crate::configs::app::AppConfig;
mod cli;
mod configs;
mod default;
mod engine;
mod models;
mod utils;
mod validate;
#[derive(Parser)]
#[command(name = utils::app::app_name())]
#[command(about = utils::app::app_about())]
#[command(styles = utils::app::app_styles())]
#[command(version = utils::app::app_version())]
struct App {
#[arg(long, global = true)]
config: Option<PathBuf>,
#[arg(long, global = true)]
debug: bool,
#[command(subcommand)]
command: Option<Commands>,
}
#[derive(Subcommand)]
enum Commands {
Action,
Prompt {
#[arg(required = true, num_args = 1..)]
text: Vec<String>,
},
}
#[tokio::main]
async fn main() {
let (config_path, debug) = utils::clap::parse_global_flags();
if let Err(e) = AppConfig::init(config_path, debug) {
exit_error!("{}", e);
}
let config = match AppConfig::instance() {
Ok(v) => v,
Err(e) => exit_error!("{}", e),
};
let mut app_builder = build_app!(&config);
let matches = app_builder.clone().get_matches();
match matches.subcommand() {
Some(("action", sub_matches)) => {
if let Some((cmd_name, action_matches)) = sub_matches.subcommand() {
cli::action::execute(cmd_name, action_matches, config).await;
} else {
utils::clap::print_subcommand_help(&mut app_builder, "action");
}
}
Some(("prompt", sub_matches)) => {
cli::prompt::execute(sub_matches).await;
}
_ => {
let _ = app_builder.print_help();
}
}
}