use std::path::PathBuf;
use clap::{Parser, Subcommand};
use assay::install;
use crate::cli;
#[derive(Parser, Debug)]
#[command(name = "assay", version, about, args_conflicts_with_subcommands = true)]
pub(crate) struct Cli {
#[command(subcommand)]
pub(crate) command: Option<Commands>,
pub(crate) file: Option<PathBuf>,
#[arg(short, long, global = true)]
pub(crate) verbose: bool,
#[arg(long, global = true)]
pub(crate) readonly: bool,
#[arg(long, global = true)]
pub(crate) approval_mode: bool,
}
#[derive(Subcommand, Debug)]
pub(crate) enum Commands {
Context {
query: String,
#[arg(short, long, default_value = "5")]
limit: usize,
#[arg(long)]
no_builtins: bool,
},
Exec {
#[arg(short = 'e', long = "eval")]
eval: Option<String>,
file: Option<PathBuf>,
},
Modules {
#[arg(long)]
json: bool,
},
Run {
file: PathBuf,
#[arg(long, value_parser = ["tool", "script"])]
mode: Option<String>,
#[arg(long, default_value = "20")]
timeout: Option<u64>,
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
script_args: Vec<String>,
},
Resume {
#[arg(long)]
token: String,
#[arg(long, value_parser = ["yes", "no"])]
approve: String,
#[arg(long, default_value = "3600")]
resume_ttl: Option<u64>,
#[arg(long)]
approver: Option<String>,
},
Workflow {
#[command(flatten)]
global: CliEngineOpts,
#[command(subcommand)]
command: WorkflowCommands,
},
Schedule {
#[command(flatten)]
global: CliEngineOpts,
#[command(subcommand)]
command: ScheduleCommands,
},
Namespace {
#[command(flatten)]
global: CliEngineOpts,
#[command(subcommand)]
command: NamespaceCommands,
},
Worker {
#[command(flatten)]
global: CliEngineOpts,
#[command(subcommand)]
command: WorkerCommands,
},
Queue {
#[command(flatten)]
global: CliEngineOpts,
#[command(subcommand)]
command: QueueCommands,
},
Install(install::InstallArgs),
Completion {
shell: clap_complete::Shell,
},
McpServe,
ApiServe {
#[arg(long, default_value = "127.0.0.1:8080")]
bind: String,
},
}
#[derive(clap::Args, Debug)]
pub(crate) struct CliEngineOpts {
#[arg(long, global = true, env = "ASSAY_ENGINE_URL")]
pub(crate) engine_url: Option<String>,
#[arg(long, global = true, env = "ASSAY_API_KEY")]
pub(crate) api_key: Option<String>,
#[arg(long, global = true, env = "ASSAY_NAMESPACE")]
pub(crate) namespace: Option<String>,
#[arg(long, global = true, env = "ASSAY_OUTPUT")]
pub(crate) output: Option<String>,
#[arg(long, global = true, env = "ASSAY_CONFIG_FILE")]
pub(crate) config: Option<String>,
}
impl CliEngineOpts {
pub(crate) fn as_flags(&self) -> cli::GlobalFlags<'_> {
cli::GlobalFlags {
engine_url: self.engine_url.as_deref(),
api_key: self.api_key.as_deref(),
namespace: self.namespace.as_deref(),
output: self.output.as_deref(),
config: self.config.as_deref(),
}
}
}
#[derive(Subcommand, Debug)]
pub(crate) enum WorkflowCommands {
Start {
#[arg(long = "type")]
workflow_type: String,
#[arg(long)]
id: Option<String>,
#[arg(long)]
input: Option<String>,
#[arg(long)]
queue: Option<String>,
#[arg(long)]
search_attrs: Option<String>,
},
List {
#[arg(long)]
status: Option<String>,
#[arg(long = "type")]
workflow_type: Option<String>,
#[arg(long)]
search_attrs: Option<String>,
#[arg(long, default_value = "20")]
limit: i64,
},
Describe {
id: String,
},
State {
id: String,
name: Option<String>,
},
Events {
id: String,
#[arg(long)]
follow: bool,
},
Children {
id: String,
},
Signal {
id: String,
name: String,
payload: Option<String>,
},
Cancel {
id: String,
},
Terminate {
id: String,
#[arg(long)]
reason: Option<String>,
},
Retry {
id: String,
#[arg(long)]
requested_by: String,
#[arg(long)]
reason: String,
},
#[command(name = "continue-as-new")]
ContinueAsNew {
id: String,
#[arg(long)]
input: Option<String>,
},
Wait {
id: String,
#[arg(long, default_value = "300")]
timeout: u64,
#[arg(long)]
target: Option<String>,
},
}
#[derive(Subcommand, Debug)]
pub(crate) enum NamespaceCommands {
Create {
name: String,
},
List,
Describe {
name: String,
},
Delete {
name: String,
},
}
#[derive(Subcommand, Debug)]
pub(crate) enum WorkerCommands {
List,
}
#[derive(Subcommand, Debug)]
pub(crate) enum QueueCommands {
Stats,
}
#[derive(Subcommand, Debug)]
pub(crate) enum ScheduleCommands {
List,
Describe {
name: String,
},
Create {
name: String,
#[arg(long = "type")]
workflow_type: String,
#[arg(long)]
cron: String,
#[arg(long)]
timezone: Option<String>,
#[arg(long)]
input: Option<String>,
#[arg(long, default_value = "default")]
queue: String,
},
Patch {
name: String,
#[arg(long)]
cron: Option<String>,
#[arg(long)]
timezone: Option<String>,
#[arg(long)]
input: Option<String>,
#[arg(long)]
queue: Option<String>,
#[arg(long)]
overlap: Option<String>,
},
Pause {
name: String,
},
Resume {
name: String,
},
Delete {
name: String,
},
}