From 46e91086d67cb7d75204682a27575f85c3cf0b91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20F=C3=A9ron?= Date: Tue, 11 Jan 2022 13:33:37 +0100 Subject: [PATCH] Add --jsonpath to helm show chart MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gabriel Féron --- cmd/helm/show.go | 3 ++- pkg/action/show.go | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/cmd/helm/show.go b/cmd/helm/show.go index 4640b3ccf..c36d1038c 100644 --- a/cmd/helm/show.go +++ b/cmd/helm/show.go @@ -174,9 +174,10 @@ func addShowFlags(subCmd *cobra.Command, client *action.Show) { f := subCmd.Flags() f.BoolVar(&client.Devel, "devel", false, "use development versions, too. Equivalent to version '>0.0.0-0'. If --version is set, this is ignored") - if subCmd.Name() == "values" { + if subCmd.Name() == "chart" || subCmd.Name() == "values" { f.StringVar(&client.JSONPathTemplate, "jsonpath", "", "supply a JSONPath expression to filter the output") } + addChartPathOptionsFlags(f, &client.ChartPathOptions) err := subCmd.RegisterFlagCompletionFunc("version", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { diff --git a/pkg/action/show.go b/pkg/action/show.go index 1e3da3bdc..fd6e35103 100644 --- a/pkg/action/show.go +++ b/pkg/action/show.go @@ -86,7 +86,15 @@ func (s *Show) Run(chartpath string) (string, error) { var out strings.Builder if s.OutputFormat == ShowChart || s.OutputFormat == ShowAll { - fmt.Fprintf(&out, "%s\n", cf) + if s.JSONPathTemplate != "" { + printer, err := printers.NewJSONPathPrinter(s.JSONPathTemplate) + if err != nil { + return "", errors.Wrapf(err, "error parsing jsonpath %s", s.JSONPathTemplate) + } + printer.Execute(&out, s.chart.Metadata) + } else { + fmt.Fprintf(&out, "%s\n", cf) + } } if (s.OutputFormat == ShowValues || s.OutputFormat == ShowAll) && s.chart.Values != nil {