helm-rs 0.1.2

Typed Rust API for Helm 4: swappable backends, native chart, values and release reading
Documentation
use std::path::PathBuf;

use crate::backend::Command;
use crate::command::release::{ReleaseName, release_command};
use crate::manifest::Rendered;

release_command! {
    /// `helm template` (`pkg/cmd/template.go`): renders a chart locally, with the flags of
    /// `helm install` (`addInstallFlags`) and its own. `helm template` is always a dry run, so
    /// `dry_run` may be `Client` (Helm's default) or `Server` but not `None`. The deprecated
    /// `--validate` (use `--dry-run=server`) and the no-op `--hide-notes` and
    /// `--render-subchart-notes` are not modelled.
    Template, TemplateBuilder, template_builder {
        required {}
        collections {
            api_versions / api_version: String, "--api-versions",
                "Kubernetes API versions for `Capabilities.APIVersions`";
            show_only / add_show_only: String, "--show-only",
                "print only the documents of these templates (globs such as `templates/*.yaml` \
                work); a template without output is an error";
        }
        flags {
            /// The `NAME` argument or `--name-template`. Without one Helm names the release
            /// `release-name`, and `Generated` (`--generate-name`) changes nothing: `NameAndChart`
            /// (`pkg/action/install.go`) returns the preset name before it generates one.
            name: Option<ReleaseName>,
            /// Flag `--include-crds`: print the CRDs of `crds/` too.
            include_crds: bool,
            /// Flag `--is-upgrade`: set `.Release.IsUpgrade` instead of `.Release.IsInstall`.
            is_upgrade: bool,
            /// Flag `--kube-version`: the version for `Capabilities.KubeVersion`.
            kube_version: Option<String>,
            /// Flag `--output-dir`: write the documents to files below this directory instead
            /// of printing them.
            output_dir: Option<PathBuf>,
            /// Flag `--replace`: skip the check that the release name is free (`template` always
            /// does).
            replace: bool,
            /// Flag `--server-side`, a boolean here that Helm defaults to true.
            server_side: Option<bool>,
            /// Flag `--skip-tests`: leave the `test` hooks out.
            skip_tests: bool,
            /// Flag `--release-name`: put the files below `<output_dir>/<release name>`.
            use_release_name: bool,
        }
    }
}

impl Template {
    /// A render of `chart` with every setting left to Helm.
    #[must_use]
    pub fn new(chart: crate::command::ChartRef) -> Self {
        Self::builder(chart).build()
    }
}

/// What `helm template` produced: the documents it printed, or, with `output_dir`, the files it
/// wrote instead.
#[derive(Debug, Clone, PartialEq)]
pub enum Templated {
    /// The printed documents: CRDs (with `include_crds`), resources and hooks.
    Rendered(Rendered),
    /// The files Helm wrote (`wrote <path>` lines, `pkg/cmd/template.go`), each once, in order.
    /// A file with several hooks is appended to and listed once. Paths are as Helm printed them:
    /// `output_dir` joined with the file's `<chart>/templates/...` source, relative to the working
    /// directory when `output_dir` is.
    Written(Vec<PathBuf>),
}

impl Command for Template {
    type Output = Templated;
}