use clap::{value_parser, Arg, ArgAction};
use std::str::FromStr;
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum FailureAction {
Rollback,
Ignore,
Error,
}
impl FromStr for FailureAction {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"rollback" => Ok(FailureAction::Rollback),
"ignore" => Ok(FailureAction::Ignore),
"error" => Ok(FailureAction::Error),
_ => Err(format!("Unknown failure action: {}", s)),
}
}
}
pub fn stack_dir() -> Arg {
Arg::new("stack_dir")
.required(true)
.help("Path to the stack directory containing resources")
}
pub fn stack_env() -> Arg {
Arg::new("stack_env")
.required(true)
.help("Environment to deploy to (e.g., `prod`, `dev`, `test`)")
}
pub fn log_level() -> Arg {
Arg::new("log-level")
.long("log-level")
.help("Set the logging level")
.default_value("info")
.value_parser(clap::builder::PossibleValuesParser::new([
"trace", "debug", "info", "warn", "error",
]))
.ignore_case(true)
}
pub fn env_file() -> Arg {
Arg::new("env-file")
.long("env-file")
.help("Environment variables file")
.default_value(".env")
}
pub fn env_var() -> Arg {
Arg::new("env")
.short('e')
.long("env")
.help("Set additional environment variables (format: KEY=VALUE)")
.action(ArgAction::Append)
}
pub fn dry_run() -> Arg {
Arg::new("dry-run")
.long("dry-run")
.help("Perform a dry run of the operation")
.action(ArgAction::SetTrue)
}
pub fn show_queries() -> Arg {
Arg::new("show-queries")
.long("show-queries")
.help("Show queries run in the output logs")
.action(ArgAction::SetTrue)
}
pub fn on_failure() -> Arg {
Arg::new("on-failure")
.long("on-failure")
.help("Action to take on failure")
.value_parser(value_parser!(FailureAction))
.default_value("error")
}