helm-rs 0.1.2

Typed Rust API for Helm 4: swappable backends, native chart, values and release reading
Documentation
use super::{ChartPathOptions, ChartRef};
use crate::backend::Command;
use crate::chart::Metadata;
use crate::manifest::Manifest;

/// Declares a `helm show` command: a chart, the chart download flags, `--devel` and an output
/// type. Helm registers the same flags on every subcommand (`addShowFlags`, `pkg/cmd/show.go`).
macro_rules! show_command {
    ($(#[$meta:meta])* $name:ident => $output:ty) => {
        $(#[$meta])*
        #[derive(Debug, Clone, PartialEq, bon::Builder)]
        #[builder(on(bool, default))]
        pub struct $name {
            /// The chart to inspect (`[CHART]`).
            #[builder(start_fn)]
            pub chart: ChartRef,
            /// The chart download flags.
            #[builder(default)]
            pub chart_path: ChartPathOptions,
            /// Flag `--devel`: use development versions too (`--version '>0.0.0-0'`); ignored
            /// when a version is set.
            pub devel: bool,
        }

        impl $name {
            /// Inspects `chart` with Helm's defaults.
            #[must_use]
            pub fn new(chart: ChartRef) -> Self {
                Self::builder(chart).build()
            }
        }

        impl Command for $name {
            type Output = $output;
        }
    };
}

show_command! {
    /// `helm show chart` (`pkg/cmd/show.go`): the `Chart.yaml` metadata Helm prints, parsed.
    ShowChart => Metadata
}

show_command! {
    /// `helm show readme`: the contents of the chart's README (`README.md`, `README.txt` or
    /// `README`, any case), exactly as in the file. `None` when the chart has none; an empty
    /// README is `Some("")` (Helm prints a newline for it and nothing for no README).
    ShowReadme => Option<String>
}

show_command! {
    /// `helm show crds`: the files of the chart's `crds/` directory, parsed.
    ShowCrds => Manifest
}

show_command! {
    /// `helm show all`: the chart metadata, values, README and CRDs. Helm's own `show all`
    /// output cannot be split reliably (it marks no part boundaries), so the CLI backend runs
    /// `show chart`, `show values`, `show readme` and `show crds` concurrently and combines them.
    ShowAll => ChartInfo
}

/// `helm show values` (`pkg/cmd/show.go`, `pkg/action/show.go`): the chart's `values.yaml`,
/// exactly as in the file. `None` when the chart has none; an empty file is `Some("")` (Helm
/// prints a newline for it and nothing for no file). With `jsonpath` the output is what the
/// expression selects, and `None` means it selected nothing (or there are no values).
#[derive(Debug, Clone, PartialEq, bon::Builder)]
#[builder(on(String, into), on(bool, default))]
pub struct ShowValues {
    /// The chart to inspect (`[CHART]`).
    #[builder(start_fn)]
    pub chart: ChartRef,
    /// The chart download flags.
    #[builder(default)]
    pub chart_path: ChartPathOptions,
    /// Flag `--devel`: use development versions too (`--version '>0.0.0-0'`); ignored when a
    /// version is set.
    pub devel: bool,
    /// Flag `--jsonpath`: a `JSONPath` expression applied to the parsed values instead of printing
    /// the file; the output is then what the expression selects, not the file.
    pub jsonpath: Option<String>,
}

impl ShowValues {
    /// Shows the values of `chart` with Helm's defaults.
    #[must_use]
    pub fn new(chart: ChartRef) -> Self {
        Self::builder(chart).build()
    }
}

impl Command for ShowValues {
    type Output = Option<String>;
}

/// What `helm show all` reports, assembled from the individual `show` commands.
#[derive(Debug, Clone, PartialEq)]
pub struct ChartInfo {
    /// The `Chart.yaml` metadata.
    pub metadata: Metadata,
    /// The text of `values.yaml`; `None` when the chart has no values file.
    pub values: Option<String>,
    /// The text of the README; `None` when the chart has none.
    pub readme: Option<String>,
    /// The CRD files; empty when the chart has none.
    pub crds: Manifest,
}