use clap::{Parser, Subcommand};
pub mod args;
pub mod commands;
pub use args::{BatchCommands, PresetCommands};
pub use commands::{AgentCommands, BackupCommands, CryptoCommands, ModelCommands};
pub use commands::{CompletionCommands, DoctorCommands, SyncCommands, WizardCommands};
#[derive(Parser, Debug)]
#[command(name = "asw")]
#[command(about = "代码终端代理工具配置切换器", long_about = None)]
#[command(version)]
pub struct Cli {
#[command(subcommand)]
pub command: Command,
}
#[derive(Subcommand, Debug)]
pub enum Command {
#[command(subcommand)]
Model(ModelCommands),
#[command(subcommand)]
Agent(AgentCommands),
#[command(subcommand)]
Backup(BackupCommands),
#[command(subcommand)]
Preset(PresetCommands),
#[command(subcommand)]
Batch(BatchCommands),
Status {
#[arg(long, short)]
detailed: bool,
},
Switch {
agent: String,
model: String,
},
#[command(subcommand)]
Wizard(WizardCommands),
#[command(subcommand)]
Doctor(DoctorCommands),
#[command(subcommand)]
Completion(CompletionCommands),
#[command(subcommand)]
Sync(SyncCommands),
#[command(subcommand)]
Crypto(CryptoCommands),
}
impl Command {
pub fn run(&self) -> anyhow::Result<()> {
match self {
Command::Model(cmd) => cmd.run(),
Command::Agent(cmd) => cmd.run(),
Command::Backup(cmd) => cmd.run(),
Command::Preset(cmd) => cmd.run(),
Command::Batch(cmd) => cmd.run(),
Command::Status { detailed: _ } => commands::execute_show_status(),
Command::Switch { agent, model } => commands::execute_switch(agent, model),
Command::Wizard(cmd) => cmd.run(),
Command::Doctor(cmd) => cmd.run(),
Command::Completion(cmd) => cmd.run(),
Command::Sync(cmd) => cmd.run(),
Command::Crypto(cmd) => cmd.run(),
}
}
}
impl Cli {
pub fn command() -> clap::Command {
<Self as clap::CommandFactory>::command()
}
}