use crate::exec::ExecActionEvent;
use clap::{Parser, Subcommand};
use serde::{Deserialize, Serialize};
#[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 a direct agent file from the local directory\n\
aip run some/agent.aip\n\
\n\
# Gives two inputs\n\
aip run some/agent.aip -i \"input 1\" -i \"input 2\"\n\
\n\
# Use -f to give file or globs (each matched file will be a input)\n\
aip run some/agent.aip -f \"src/**/*.js\"\n\
\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 single file as input\n\
aip run demo@proof -f ./README.md\n\
\n\
```"
)]
Run(RunArgs),
List(ListArgs),
Pack(PackArgs),
Install(InstallArgs),
Unpack(UnpackArgs),
#[command(name = "check-keys", about = "Check available API keys in the environment")]
CheckKeys(CheckKeysArgs),
#[command(name = "create-gitignore", about = "Create a .gitignore file from a template")]
CreateGitignore(CreateGitignoreArgs),
#[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::Unpack(_) => false,
CliCommand::CheckKeys(_) => false, CliCommand::CreateGitignore(_) => false, CliCommand::Xelf(_) => false, }
}
pub fn is_tui(&self) -> bool {
match self {
CliCommand::Run(run_args) => run_args.is_tui(),
CliCommand::Init(_) => false,
CliCommand::InitBase => false,
CliCommand::List(_) => false,
CliCommand::Pack(_) => false,
CliCommand::Install(_) => false,
CliCommand::Unpack(_) => false,
CliCommand::CheckKeys(_) => false, CliCommand::CreateGitignore(_) => false, CliCommand::Xelf(_) => false, }
}
}
#[derive(Parser, Debug, Clone, Serialize, Deserialize)]
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,
#[arg(long = "xp-tui")]
xp_tui: bool,
#[arg(long = "old-term")]
old_term: bool,
}
impl RunArgs {
pub fn is_tui(&self) -> bool {
!self.old_term }
}
#[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 {
#[arg(long = "force")]
pub force: bool,
pub aipack_ref: String,
}
#[derive(Parser, Debug)]
pub struct UnpackArgs {
pub pack_ref: String,
#[arg(long = "force")]
pub force: bool,
}
#[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: Option<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 CreateGitignoreArgs {
#[arg(long = "force")]
pub force: bool,
}
#[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 {
#[arg(short = 'v', long = "version")]
pub version: Option<String>,
}
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::Run(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::Unpack(unpack_args) => ExecActionEvent::CmdUnpack(unpack_args),
CliCommand::CheckKeys(args) => ExecActionEvent::CmdCheckKeys(args),
CliCommand::CreateGitignore(args) => ExecActionEvent::CmdCreateGitignore(args),
CliCommand::Xelf(xelf_args) => {
match xelf_args.cmd {
XelfCommand::Setup(args) => ExecActionEvent::CmdXelfSetup(args),
XelfCommand::Update(args) => ExecActionEvent::CmdXelfUpdate(args),
}
}
}
}
}