github.com/sdbaiguanghe/helm@v2.16.7+incompatible/cmd/helm/get.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 main
    18  
    19  import (
    20  	"errors"
    21  	"io"
    22  
    23  	"github.com/spf13/cobra"
    24  
    25  	"k8s.io/helm/pkg/helm"
    26  )
    27  
    28  var getHelp = `
    29  This command shows the details of a named release.
    30  
    31  It can be used to get extended information about the release, including:
    32  
    33    - The values used to generate the release
    34    - The chart used to generate the release
    35    - The generated manifest file
    36  
    37  By default, this prints a human readable collection of information about the
    38  chart, the supplied values, and the generated manifest file.
    39  `
    40  
    41  var errReleaseRequired = errors.New("release name is required")
    42  
    43  type getCmd struct {
    44  	release  string
    45  	out      io.Writer
    46  	client   helm.Interface
    47  	version  int32
    48  	template string
    49  }
    50  
    51  func newGetCmd(client helm.Interface, out io.Writer) *cobra.Command {
    52  	get := &getCmd{
    53  		out:    out,
    54  		client: client,
    55  	}
    56  
    57  	cmd := &cobra.Command{
    58  		Use:     "get [flags] RELEASE_NAME",
    59  		Short:   "Download a named release",
    60  		Long:    getHelp,
    61  		PreRunE: func(_ *cobra.Command, _ []string) error { return setupConnection() },
    62  		RunE: func(cmd *cobra.Command, args []string) error {
    63  			if len(args) == 0 {
    64  				return errReleaseRequired
    65  			}
    66  			get.release = args[0]
    67  			if get.client == nil {
    68  				get.client = newClient()
    69  			}
    70  			return get.run()
    71  		},
    72  	}
    73  
    74  	f := cmd.Flags()
    75  	settings.AddFlagsTLS(f)
    76  	f.Int32Var(&get.version, "revision", 0, "Get the named release with revision")
    77  	f.StringVar(&get.template, "template", "", "Go template for formatting the output, eg: {{.Release.Name}}")
    78  
    79  	cmd.AddCommand(newGetValuesCmd(nil, out))
    80  	cmd.AddCommand(newGetManifestCmd(nil, out))
    81  	cmd.AddCommand(newGetHooksCmd(nil, out))
    82  	cmd.AddCommand(newGetNotesCmd(nil, out))
    83  
    84  	// set defaults from environment
    85  	settings.InitTLS(f)
    86  
    87  	return cmd
    88  }
    89  
    90  // getCmd is the command that implements 'helm get'
    91  func (g *getCmd) run() error {
    92  	res, err := g.client.ReleaseContent(g.release, helm.ContentReleaseVersion(g.version))
    93  	if err != nil {
    94  		return prettyError(err)
    95  	}
    96  
    97  	if g.template != "" {
    98  		return tpl(g.template, res, g.out)
    99  	}
   100  	return printRelease(g.out, res.Release)
   101  }