use std::path::PathBuf;
use crate::backend::Command;
use crate::options::Secret;
#[derive(Debug, Clone, Default, PartialEq, bon::Builder)]
#[builder(
on(String, into),
on(PathBuf, into),
on(Secret, into),
on(bool, default)
)]
#[allow(clippy::struct_excessive_bools, reason = "one field per Helm flag")]
pub struct DependencyOptions {
pub verify: bool,
pub keyring: Option<PathBuf>,
pub skip_refresh: bool,
pub username: Option<String>,
pub password: Option<Secret>,
pub cert_file: Option<PathBuf>,
pub key_file: Option<PathBuf>,
pub ca_file: Option<PathBuf>,
pub insecure_skip_tls_verify: bool,
pub plain_http: bool,
}
macro_rules! dependency_command {
($(#[$meta:meta])* $name:ident) => {
$(#[$meta])*
#[derive(Debug, Clone, PartialEq, bon::Builder)]
#[builder(on(PathBuf, into))]
pub struct $name {
/// The chart directory (`CHART`).
#[builder(start_fn)]
pub chart: PathBuf,
#[builder(default)]
pub options: DependencyOptions,
}
impl $name {
#[must_use]
pub fn new(chart: impl Into<PathBuf>) -> Self {
Self::builder(chart).build()
}
}
impl Command for $name {
type Output = ();
}
};
}
dependency_command! {
DependencyBuild
}
dependency_command! {
DependencyUpdate
}
#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
#[builder(on(PathBuf, into))]
pub struct DependencyList {
#[builder(start_fn)]
pub chart: PathBuf,
}
impl DependencyList {
#[must_use]
pub fn new(chart: impl Into<PathBuf>) -> Self {
Self::builder(chart).build()
}
}
impl Command for DependencyList {
type Output = DependencyListing;
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct DependencyListing {
pub dependencies: Vec<DependencyRow>,
pub warnings: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DependencyRow {
pub name: String,
pub version: String,
pub repository: String,
pub status: DependencyStatus,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DependencyStatus {
Ok,
Unpacked,
Missing,
WrongVersion,
InvalidVersion,
Corrupt,
Misnamed,
TooManyMatches,
BadPattern,
}
impl DependencyStatus {
#[must_use]
pub fn from_helm(text: &str) -> Option<Self> {
Some(match text {
"ok" => Self::Ok,
"unpacked" => Self::Unpacked,
"missing" => Self::Missing,
"wrong version" => Self::WrongVersion,
"invalid version" => Self::InvalidVersion,
"corrupt" => Self::Corrupt,
"misnamed" => Self::Misnamed,
"too many matches" => Self::TooManyMatches,
"bad pattern" => Self::BadPattern,
_ => return None,
})
}
}