helm-rs 0.1.1

Typed Rust API for Helm 4: swappable backends, native chart, values and release reading
Documentation
use serde::Deserialize;

use crate::backend::Command;

/// `helm search hub`: searches Artifact Hub (or another Monocular-compatible hub) over the
/// network, requested as `-o json`. `--max-col-width` and `--list-repo-url` only shape the table,
/// and the JSON always carries the repository, so they are not modelled.
#[derive(Debug, Clone, Default, PartialEq, Eq, bon::Builder)]
#[builder(on(String, into), on(bool, default))]
pub struct SearchHub {
    /// The search keyword (`KEYWORD`); Artifact Hub also accepts its rich query syntax.
    pub keyword: Option<String>,
    /// Flag `--endpoint`: the hub to query (Helm's default is `https://hub.helm.sh`).
    pub endpoint: Option<String>,
    /// Flag `--fail-on-no-result`: fail when nothing matches.
    pub fail_on_no_result: bool,
}

/// One hub result (`hubChartElement` in `pkg/cmd/search_hub.go`, Helm v4.3.0).
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
pub struct HubChart {
    /// The package page on the hub.
    pub url: String,
    /// The latest chart version.
    #[serde(default)]
    pub version: String,
    /// The latest application version.
    #[serde(default)]
    pub app_version: String,
    /// The chart description.
    #[serde(default)]
    pub description: String,
    /// The repository that hosts the chart.
    pub repository: HubRepository,
}

/// The repository of a [`HubChart`] (`hubChartRepo`).
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
pub struct HubRepository {
    /// The repository URL.
    #[serde(default)]
    pub url: String,
    /// The repository name on the hub.
    #[serde(default)]
    pub name: String,
}

impl Command for SearchHub {
    type Output = Vec<HubChart>;
}

/// `helm search repo`: searches the cached indexes of the added repositories, requested as
/// `-o json`. `--max-col-width` only shapes the table, so it is not modelled.
#[derive(Debug, Clone, Default, PartialEq, Eq, bon::Builder)]
#[builder(on(String, into), on(bool, default))]
#[allow(clippy::struct_excessive_bools, reason = "one field per Helm flag")]
pub struct SearchRepo {
    /// The search keyword (`keyword`); empty lists every chart.
    pub keyword: Option<String>,
    /// Flag `--devel`: include pre-releases (the constraint `>0.0.0-0`); ignored with `version`.
    pub devel: bool,
    /// Flag `--fail-on-no-result`: fail when nothing matches.
    pub fail_on_no_result: bool,
    /// Flag `--regexp` (`-r`): treat the keyword as a regular expression.
    pub regexp: bool,
    /// Flag `--version`: a semantic version constraint.
    pub version: Option<String>,
    /// Flag `--versions` (`-l`): list every version of each chart, not only the newest.
    pub versions: bool,
}

/// One repository search result (`repoChartElement` in `pkg/cmd/search_repo.go`, Helm v4.3.0).
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
pub struct RepoChart {
    /// The chart as `repository/chart`.
    pub name: String,
    /// The chart version.
    #[serde(default)]
    pub version: String,
    /// The application version.
    #[serde(default)]
    pub app_version: String,
    /// The chart description.
    #[serde(default)]
    pub description: String,
}

impl Command for SearchRepo {
    type Output = Vec<RepoChart>;
}