github.com/Racer159/helm-experiment@v0.0.0-20230822001441-1eb31183f614/src/get_all.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  	"io"
    21  	"log"
    22  
    23  	"github.com/spf13/cobra"
    24  
    25  	"helm.sh/helm/v3/cmd/helm/require"
    26  	"helm.sh/helm/v3/pkg/action"
    27  	"helm.sh/helm/v3/pkg/cli/output"
    28  )
    29  
    30  var getAllHelp = `
    31  This command prints a human readable collection of information about the
    32  notes, hooks, supplied values, and generated manifest file of the given release.
    33  `
    34  
    35  func newGetAllCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
    36  	var template string
    37  	client := action.NewGet(cfg)
    38  
    39  	cmd := &cobra.Command{
    40  		Use:   "all RELEASE_NAME",
    41  		Short: "download all information for a named release",
    42  		Long:  getAllHelp,
    43  		Args:  require.ExactArgs(1),
    44  		ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
    45  			if len(args) != 0 {
    46  				return nil, cobra.ShellCompDirectiveNoFileComp
    47  			}
    48  			return compListReleases(toComplete, args, cfg)
    49  		},
    50  		RunE: func(cmd *cobra.Command, args []string) error {
    51  			res, err := client.Run(args[0])
    52  			if err != nil {
    53  				return err
    54  			}
    55  			if template != "" {
    56  				data := map[string]interface{}{
    57  					"Release": res,
    58  				}
    59  				return tpl(template, data, out)
    60  			}
    61  
    62  			return output.Table.Write(out, &statusPrinter{res, true, false, false})
    63  		},
    64  	}
    65  
    66  	f := cmd.Flags()
    67  	f.IntVar(&client.Version, "revision", 0, "get the named release with revision")
    68  	err := cmd.RegisterFlagCompletionFunc("revision", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
    69  		if len(args) == 1 {
    70  			return compListRevisions(toComplete, cfg, args[0])
    71  		}
    72  		return nil, cobra.ShellCompDirectiveNoFileComp
    73  	})
    74  
    75  	if err != nil {
    76  		log.Fatal(err)
    77  	}
    78  
    79  	f.StringVar(&template, "template", "", "go template for formatting the output, eg: {{.Release.Name}}")
    80  
    81  	return cmd
    82  }