Skip to main content

helm_rs/command/
show.rs

1use super::{ChartPathOptions, ChartRef};
2use crate::backend::Command;
3use crate::chart::Metadata;
4use crate::manifest::Manifest;
5
6/// Declares a `helm show` command: a chart, the chart download flags, `--devel` and an output
7/// type. Helm registers the same flags on every subcommand (`addShowFlags`, `pkg/cmd/show.go`).
8macro_rules! show_command {
9    ($(#[$meta:meta])* $name:ident => $output:ty) => {
10        $(#[$meta])*
11        #[derive(Debug, Clone, PartialEq, bon::Builder)]
12        #[builder(on(bool, default))]
13        pub struct $name {
14            /// The chart to inspect (`[CHART]`).
15            #[builder(start_fn)]
16            pub chart: ChartRef,
17            /// The chart download flags.
18            #[builder(default)]
19            pub chart_path: ChartPathOptions,
20            /// Flag `--devel`: use development versions too (`--version '>0.0.0-0'`); ignored
21            /// when a version is set.
22            pub devel: bool,
23        }
24
25        impl $name {
26            /// Inspects `chart` with Helm's defaults.
27            #[must_use]
28            pub fn new(chart: ChartRef) -> Self {
29                Self::builder(chart).build()
30            }
31        }
32
33        impl Command for $name {
34            type Output = $output;
35        }
36    };
37}
38
39show_command! {
40    /// `helm show chart` (`pkg/cmd/show.go`): the `Chart.yaml` metadata Helm prints, parsed.
41    ShowChart => Metadata
42}
43
44show_command! {
45    /// `helm show readme`: the contents of the chart's README (`README.md`, `README.txt` or
46    /// `README`, any case), exactly as in the file. `None` when the chart has none; an empty
47    /// README is `Some("")` (Helm prints a newline for it and nothing for no README).
48    ShowReadme => Option<String>
49}
50
51show_command! {
52    /// `helm show crds`: the files of the chart's `crds/` directory, parsed.
53    ShowCrds => Manifest
54}
55
56show_command! {
57    /// `helm show all`: the chart metadata, values, README and CRDs. Helm's own `show all`
58    /// output cannot be split reliably (it marks no part boundaries), so the CLI backend runs
59    /// `show chart`, `show values`, `show readme` and `show crds` concurrently and combines them.
60    ShowAll => ChartInfo
61}
62
63/// `helm show values` (`pkg/cmd/show.go`, `pkg/action/show.go`): the chart's `values.yaml`,
64/// exactly as in the file. `None` when the chart has none; an empty file is `Some("")` (Helm
65/// prints a newline for it and nothing for no file). With `jsonpath` the output is what the
66/// expression selects, and `None` means it selected nothing (or there are no values).
67#[derive(Debug, Clone, PartialEq, bon::Builder)]
68#[builder(on(String, into), on(bool, default))]
69pub struct ShowValues {
70    /// The chart to inspect (`[CHART]`).
71    #[builder(start_fn)]
72    pub chart: ChartRef,
73    /// The chart download flags.
74    #[builder(default)]
75    pub chart_path: ChartPathOptions,
76    /// Flag `--devel`: use development versions too (`--version '>0.0.0-0'`); ignored when a
77    /// version is set.
78    pub devel: bool,
79    /// Flag `--jsonpath`: a `JSONPath` expression applied to the parsed values instead of printing
80    /// the file; the output is then what the expression selects, not the file.
81    pub jsonpath: Option<String>,
82}
83
84impl ShowValues {
85    /// Shows the values of `chart` with Helm's defaults.
86    #[must_use]
87    pub fn new(chart: ChartRef) -> Self {
88        Self::builder(chart).build()
89    }
90}
91
92impl Command for ShowValues {
93    type Output = Option<String>;
94}
95
96/// What `helm show all` reports, assembled from the individual `show` commands.
97#[derive(Debug, Clone, PartialEq)]
98pub struct ChartInfo {
99    /// The `Chart.yaml` metadata.
100    pub metadata: Metadata,
101    /// The text of `values.yaml`; `None` when the chart has no values file.
102    pub values: Option<String>,
103    /// The text of the README; `None` when the chart has none.
104    pub readme: Option<String>,
105    /// The CRD files; empty when the chart has none.
106    pub crds: Manifest,
107}