use clap::{command, Parser, Subcommand};
use super::{auth, completion, config, generate};
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
pub struct Cli {
#[command(subcommand)]
command: Option<Commands>,
#[arg(short, long)]
dry_run: bool,
#[arg(short = 'A', long)]
amend: bool,
#[arg(short, long)]
add_all: bool,
}
impl Cli {
pub async fn execute(&self) -> anyhow::Result<()> {
match &self.command {
Some(command) => command.execute().await?,
None => {
let dry_run = self.dry_run;
let amend = self.amend;
let add_all = self.add_all;
generate::generate_commit(dry_run, amend, add_all).await?
}
}
Ok(())
}
}
#[derive(Subcommand)]
pub enum Commands {
Auth(auth::AuthCommand),
Completion(completion::CompletionCommand),
Config(config::ConfigCommand),
}
impl Commands {
pub async fn execute(&self) -> anyhow::Result<()> {
match self {
Commands::Auth(cmd) => cmd.execute().await,
Commands::Completion(cmd) => cmd.execute().await,
Commands::Config(cmd) => cmd.execute().await,
}
}
}