| use clap::Args; |
| use clap::Parser; |
| use codex_utils_cli::CliConfigOverrides; |
|
|
| #[derive(Parser, Debug, Default)] |
| #[command(version)] |
| pub struct Cli { |
| #[clap(skip)] |
| pub config_overrides: CliConfigOverrides, |
|
|
| #[command(subcommand)] |
| pub command: Option<Command>, |
| } |
|
|
| #[derive(Debug, clap::Subcommand)] |
| pub enum Command { |
| |
| Exec(ExecCommand), |
| |
| Status(StatusCommand), |
| |
| List(ListCommand), |
| |
| Apply(ApplyCommand), |
| |
| Diff(DiffCommand), |
| } |
|
|
| #[derive(Debug, Args)] |
| pub struct ExecCommand { |
| |
| #[arg(value_name = "QUERY")] |
| pub query: Option<String>, |
|
|
| |
| #[arg(long = "env", value_name = "ENV_ID")] |
| pub environment: String, |
|
|
| |
| #[arg( |
| long = "attempts", |
| default_value_t = 1usize, |
| value_parser = parse_attempts |
| )] |
| pub attempts: usize, |
|
|
| |
| #[arg(long = "branch", value_name = "BRANCH")] |
| pub branch: Option<String>, |
| } |
|
|
| fn parse_attempts(input: &str) -> Result<usize, String> { |
| let value: usize = input |
| .parse() |
| .map_err(|_| "attempts must be an integer between 1 and 4".to_string())?; |
| if (1..=4).contains(&value) { |
| Ok(value) |
| } else { |
| Err("attempts must be between 1 and 4".to_string()) |
| } |
| } |
|
|
| fn parse_limit(input: &str) -> Result<i64, String> { |
| let value: i64 = input |
| .parse() |
| .map_err(|_| "limit must be an integer between 1 and 20".to_string())?; |
| if (1..=20).contains(&value) { |
| Ok(value) |
| } else { |
| Err("limit must be between 1 and 20".to_string()) |
| } |
| } |
|
|
| #[derive(Debug, Args)] |
| pub struct StatusCommand { |
| |
| #[arg(value_name = "TASK_ID")] |
| pub task_id: String, |
| } |
|
|
| #[derive(Debug, Args)] |
| pub struct ListCommand { |
| |
| #[arg(long = "env", value_name = "ENV_ID")] |
| pub environment: Option<String>, |
|
|
| |
| #[arg(long = "limit", default_value_t = 20, value_parser = parse_limit, value_name = "N")] |
| pub limit: i64, |
|
|
| |
| #[arg(long = "cursor", value_name = "CURSOR")] |
| pub cursor: Option<String>, |
|
|
| |
| #[arg(long = "json", default_value_t = false)] |
| pub json: bool, |
| } |
|
|
| #[derive(Debug, Args)] |
| pub struct ApplyCommand { |
| |
| #[arg(value_name = "TASK_ID")] |
| pub task_id: String, |
|
|
| |
| #[arg(long = "attempt", value_parser = parse_attempts, value_name = "N")] |
| pub attempt: Option<usize>, |
| } |
|
|
| #[derive(Debug, Args)] |
| pub struct DiffCommand { |
| |
| #[arg(value_name = "TASK_ID")] |
| pub task_id: String, |
|
|
| |
| #[arg(long = "attempt", value_parser = parse_attempts, value_name = "N")] |
| pub attempt: Option<usize>, |
| } |
|
|