helm-rs 0.1.0

Typed Rust API for Helm 4: swappable backends, native chart, values and release reading
Documentation
use super::{CliCommand, Invocation, flags, parse_json};
use crate::command::{HubChart, RepoChart, SearchHub, SearchRepo};
use crate::error::Result;

#[cfg(test)]
mod tests;

impl CliCommand for SearchHub {
    fn build(&self, inv: &mut Invocation) -> Result<()> {
        inv.arg("search");
        inv.arg("hub");

        if let Some(keyword) = &self.keyword {
            inv.arg(keyword);
        }

        inv.json_output();

        flags! { inv, self;
            option("--endpoint", endpoint);
            switch("--fail-on-no-result", fail_on_no_result);
        }

        Ok(())
    }

    fn parse(&self, stdout: String) -> Result<Vec<HubChart>> {
        parse_json("helm search hub", &stdout)
    }
}

impl CliCommand for SearchRepo {
    fn build(&self, inv: &mut Invocation) -> Result<()> {
        inv.arg("search");
        inv.arg("repo");

        if let Some(keyword) = &self.keyword {
            inv.arg(keyword);
        }

        inv.json_output();

        flags! { inv, self;
            switch("--devel", devel);
            switch("--fail-on-no-result", fail_on_no_result);
            switch("--regexp", regexp);
            option("--version", version);
            switch("--versions", versions);
        }

        Ok(())
    }

    fn parse(&self, stdout: String) -> Result<Vec<RepoChart>> {
        parse_json("helm search repo", &stdout)
    }
}