Run executes 'helm show' against the given release.
(chartpath string)
| 81 | |
| 82 | // Run executes 'helm show' against the given release. |
| 83 | func (s *Show) Run(chartpath string) (string, error) { |
| 84 | if s.chart == nil { |
| 85 | chrt, err := loader.Load(chartpath) |
| 86 | if err != nil { |
| 87 | return "", err |
| 88 | } |
| 89 | s.chart = chrt |
| 90 | } |
| 91 | cf, err := yaml.Marshal(s.chart.Metadata) |
| 92 | if err != nil { |
| 93 | return "", err |
| 94 | } |
| 95 | |
| 96 | var out strings.Builder |
| 97 | if s.OutputFormat == ShowChart || s.OutputFormat == ShowAll { |
| 98 | fmt.Fprintf(&out, "%s\n", cf) |
| 99 | } |
| 100 | |
| 101 | if (s.OutputFormat == ShowValues || s.OutputFormat == ShowAll) && s.chart.Values != nil { |
| 102 | if s.OutputFormat == ShowAll { |
| 103 | fmt.Fprintln(&out, "---") |
| 104 | } |
| 105 | if s.JSONPathTemplate != "" { |
| 106 | printer, err := printers.NewJSONPathPrinter(s.JSONPathTemplate) |
| 107 | if err != nil { |
| 108 | return "", fmt.Errorf("error parsing jsonpath %s: %w", s.JSONPathTemplate, err) |
| 109 | } |
| 110 | printer.Execute(&out, s.chart.Values) |
| 111 | } else { |
| 112 | for _, f := range s.chart.Raw { |
| 113 | if f.Name == chartutil.ValuesfileName { |
| 114 | fmt.Fprintln(&out, string(f.Data)) |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | if s.OutputFormat == ShowReadme || s.OutputFormat == ShowAll { |
| 121 | readme := findReadme(s.chart.Files) |
| 122 | if readme != nil { |
| 123 | if s.OutputFormat == ShowAll { |
| 124 | fmt.Fprintln(&out, "---") |
| 125 | } |
| 126 | fmt.Fprintf(&out, "%s\n", readme.Data) |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | if s.OutputFormat == ShowCRDs || s.OutputFormat == ShowAll { |
| 131 | crds := s.chart.CRDObjects() |
| 132 | if len(crds) > 0 { |
| 133 | for _, crd := range crds { |
| 134 | if !bytes.HasPrefix(crd.File.Data, []byte("---")) { |
| 135 | fmt.Fprintln(&out, "---") |
| 136 | } |
| 137 | fmt.Fprintf(&out, "%s\n", string(crd.File.Data)) |
| 138 | } |
| 139 | } |
| 140 | } |