use crate::entities::update::Update;
use anyhow::Context;
use clap::ArgAction::SetTrue;
use clap::Parser;
use derive_empty_traits::EmptyTraits;
use resolver_api::Resolve;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use typeshare::typeshare;
use super::{BatchExecutionResponse, KomodoExecuteRequest};
#[typeshare]
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
Resolve,
EmptyTraits,
Parser,
)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(serror::Error)]
pub struct DeployStack {
pub stack: String,
#[serde(default)]
pub services: Vec<String>,
pub stop_time: Option<i32>,
}
#[typeshare]
#[derive(
Serialize,
Deserialize,
Debug,
Clone,
PartialEq,
Resolve,
EmptyTraits,
Parser,
)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(BatchExecutionResponse)]
#[error(serror::Error)]
pub struct BatchDeployStack {
pub pattern: String,
}
#[typeshare]
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
Resolve,
EmptyTraits,
Parser,
)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(serror::Error)]
pub struct DeployStackIfChanged {
pub stack: String,
pub stop_time: Option<i32>,
}
#[typeshare]
#[derive(
Serialize,
Deserialize,
Debug,
Clone,
PartialEq,
Resolve,
EmptyTraits,
Parser,
)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(BatchExecutionResponse)]
#[error(serror::Error)]
pub struct BatchDeployStackIfChanged {
pub pattern: String,
}
#[typeshare]
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
Resolve,
EmptyTraits,
Parser,
)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(serror::Error)]
pub struct PullStack {
pub stack: String,
#[serde(default)]
pub services: Vec<String>,
}
#[typeshare]
#[derive(
Serialize,
Deserialize,
Debug,
Clone,
PartialEq,
Resolve,
EmptyTraits,
Parser,
)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(BatchExecutionResponse)]
#[error(serror::Error)]
pub struct BatchPullStack {
pub pattern: String,
}
#[typeshare]
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
Resolve,
EmptyTraits,
Parser,
)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(serror::Error)]
pub struct StartStack {
pub stack: String,
#[serde(default)]
pub services: Vec<String>,
}
#[typeshare]
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
Resolve,
EmptyTraits,
Parser,
)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(serror::Error)]
pub struct RestartStack {
pub stack: String,
#[serde(default)]
pub services: Vec<String>,
}
#[typeshare]
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
Resolve,
EmptyTraits,
Parser,
)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(serror::Error)]
pub struct PauseStack {
pub stack: String,
#[serde(default)]
pub services: Vec<String>,
}
#[typeshare]
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
Resolve,
EmptyTraits,
Parser,
)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(serror::Error)]
pub struct UnpauseStack {
pub stack: String,
#[serde(default)]
pub services: Vec<String>,
}
#[typeshare]
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
Resolve,
EmptyTraits,
Parser,
)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(serror::Error)]
pub struct StopStack {
pub stack: String,
pub stop_time: Option<i32>,
#[serde(default)]
pub services: Vec<String>,
}
#[typeshare]
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
Resolve,
EmptyTraits,
Parser,
)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(serror::Error)]
pub struct DestroyStack {
pub stack: String,
#[serde(default)]
pub services: Vec<String>,
#[serde(default)]
pub remove_orphans: bool,
pub stop_time: Option<i32>,
}
#[typeshare]
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
Resolve,
EmptyTraits,
Parser,
)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(serror::Error)]
pub struct RunStackService {
pub stack: String,
pub service: String,
#[arg(trailing_var_arg = true, num_args = 1.., allow_hyphen_values = true)]
pub command: Option<Vec<String>>,
#[arg(long = "no-tty", action = SetTrue)]
pub no_tty: Option<bool>,
#[arg(long = "no-deps", action = SetTrue)]
pub no_deps: Option<bool>,
#[arg(long = "detach", action = SetTrue)]
pub detach: Option<bool>,
#[arg(long = "service-ports", action = SetTrue)]
pub service_ports: Option<bool>,
#[arg(long = "env", short = 'e', value_parser = env_parser)]
pub env: Option<HashMap<String, String>>,
#[arg(long = "workdir")]
pub workdir: Option<String>,
#[arg(long = "user")]
pub user: Option<String>,
#[arg(long = "entrypoint")]
pub entrypoint: Option<String>,
#[arg(long = "pull", action = SetTrue)]
pub pull: Option<bool>,
}
fn env_parser(args: &str) -> anyhow::Result<HashMap<String, String>> {
serde_qs::from_str(args).context("Failed to parse env")
}
#[typeshare]
#[derive(
Serialize,
Deserialize,
Debug,
Clone,
PartialEq,
Resolve,
EmptyTraits,
Parser,
)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(BatchExecutionResponse)]
#[error(serror::Error)]
pub struct BatchDestroyStack {
pub pattern: String,
}