use crate::exec::ExecActionEvent;
use clap::{Parser, Subcommand, command};
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
pub struct CliArgs {
#[command(subcommand)]
pub cmd: CliCommand,
}
#[derive(Subcommand, Debug)]
pub enum CliCommand {
Init(InitArgs),
#[command(name = "init-base", about = "Init the ~/.aipack-base only with force update")]
InitBase,
#[command(
about = "Executes the AIPack agent using `aip run demo@craft/code`, or an agent file `aip run path/to/agent.aip`.\n\n\
Example usage:\n\
```sh\n\
# Run the demo@craft/code AIP agent\n\
aip run demo@craft/code\n\
\n\
# Run the demo@proof main.aip agent and provide a file as input\n\
aip run demo@proof -f ./README.md\n\
\n\
# Run a direct agent file from the local directory\n\
aip run some/agent.aip\n\
```"
)]
Run(RunArgs),
List(ListArgs),
Pack(PackArgs),
Install(InstallArgs),
#[command(name = "check-keys", about = "Check available API keys in the environment")]
CheckKeys(CheckKeysArgs),
#[command(name = "self", about = "Manage the aip CLI itself")]
Xelf(XelfArgs),
}
impl CliCommand {
pub fn is_interactive(&self) -> bool {
match self {
CliCommand::Run(run_args) => !run_args.single_shot,
CliCommand::Init(_) => false,
CliCommand::InitBase => false,
CliCommand::List(_) => false,
CliCommand::Pack(_) => false,
CliCommand::Install(_) => false,
CliCommand::CheckKeys(_) => false, CliCommand::Xelf(_) => false, }
}
}
#[derive(Parser, Debug)]
pub struct RunArgs {
#[clap(help = "The name of the agent, which can be:\n\
- A AIP pack reference:\n\
`aip run demo@proof`\n\
- Or a direct file:\n\
`aip run path/to/agent.aip`")]
pub cmd_agent_name: String,
#[arg(short = 'i', long = "input")]
pub on_inputs: Option<Vec<String>>,
#[arg(short = 'f', long = "on-files")]
pub on_files: Option<Vec<String>>,
#[arg(short = 'w', long = "watch")]
pub watch: bool,
#[arg(short = 'v', long = "verbose")]
pub verbose: bool,
#[arg(short = 'o', long = "open")]
pub open: bool,
#[arg(long = "dry", value_parser = ["req", "res"])]
pub dry_mode: Option<String>,
#[arg(short = 's', long = "single-shot", alias = "ni")]
pub single_shot: bool,
}
#[derive(Parser, Debug)]
pub struct PackArgs {
pub dir_path: String,
#[arg(short = 'o', long = "output")]
pub output_dir: Option<String>,
}
#[derive(Parser, Debug)]
pub struct InstallArgs {
pub aipack_ref: String,
}
#[derive(Parser, Debug)]
pub struct ListArgs {
pub pack_ref: Option<String>,
#[arg(short = 'o', long = "open")]
pub open: bool,
}
#[derive(Parser, Debug)]
pub struct NewArgs {
pub agent_path: String,
#[arg(short = 'o', long = "open")]
pub open: bool,
}
#[derive(Parser, Debug)]
pub struct InitArgs {
pub path: Option<String>,
}
#[derive(Parser, Debug)]
pub struct CheckKeysArgs {}
#[derive(Parser, Debug)]
pub struct XelfArgs {
#[command(subcommand)]
pub cmd: XelfCommand,
}
#[derive(Subcommand, Debug)]
pub enum XelfCommand {
Setup(XelfSetupArgs),
Update(XelfUpdateArgs),
}
#[derive(Parser, Debug)]
pub struct XelfSetupArgs {}
#[derive(Parser, Debug)]
pub struct XelfUpdateArgs {}
impl From<CliCommand> for ExecActionEvent {
fn from(cli_cmd: CliCommand) -> Self {
match cli_cmd {
CliCommand::Init(init_args) => ExecActionEvent::CmdInit(init_args),
CliCommand::InitBase => ExecActionEvent::CmdInitBase,
CliCommand::Run(run_args) => ExecActionEvent::CmdRun(run_args),
CliCommand::List(list_args) => ExecActionEvent::CmdList(list_args),
CliCommand::Pack(pack_args) => ExecActionEvent::CmdPack(pack_args),
CliCommand::Install(install_args) => ExecActionEvent::CmdInstall(install_args),
CliCommand::CheckKeys(args) => ExecActionEvent::CmdCheckKeys(args),
CliCommand::Xelf(xelf_args) => {
match xelf_args.cmd {
XelfCommand::Setup(args) => ExecActionEvent::CmdXelfSetup(args),
XelfCommand::Update(args) => ExecActionEvent::CmdXelfUpdate(args),
}
}
}
}
}