github.com/Racer159/helm-experiment@v0.0.0-20230822001441-1eb31183f614/src/get_manifest.go (about) 1 /* 2 Copyright The Helm Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package cmd 18 19 import ( 20 "fmt" 21 "io" 22 "log" 23 24 "github.com/spf13/cobra" 25 26 "helm.sh/helm/v3/cmd/helm/require" 27 "helm.sh/helm/v3/pkg/action" 28 ) 29 30 var getManifestHelp = ` 31 This command fetches the generated manifest for a given release. 32 33 A manifest is a YAML-encoded representation of the Kubernetes resources that 34 were generated from this release's chart(s). If a chart is dependent on other 35 charts, those resources will also be included in the manifest. 36 ` 37 38 func newGetManifestCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { 39 client := action.NewGet(cfg) 40 41 cmd := &cobra.Command{ 42 Use: "manifest RELEASE_NAME", 43 Short: "download the manifest for a named release", 44 Long: getManifestHelp, 45 Args: require.ExactArgs(1), 46 ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { 47 if len(args) != 0 { 48 return nil, cobra.ShellCompDirectiveNoFileComp 49 } 50 return compListReleases(toComplete, args, cfg) 51 }, 52 RunE: func(cmd *cobra.Command, args []string) error { 53 res, err := client.Run(args[0]) 54 if err != nil { 55 return err 56 } 57 fmt.Fprintln(out, res.Manifest) 58 return nil 59 }, 60 } 61 62 cmd.Flags().IntVar(&client.Version, "revision", 0, "get the named release with revision") 63 err := cmd.RegisterFlagCompletionFunc("revision", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { 64 if len(args) == 1 { 65 return compListRevisions(toComplete, cfg, args[0]) 66 } 67 return nil, cobra.ShellCompDirectiveNoFileComp 68 }) 69 70 if err != nil { 71 log.Fatal(err) 72 } 73 74 return cmd 75 }