1/*
2Copyright The Helm Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package main
18
19import (
20	"io"
21
22	"github.com/spf13/cobra"
23
24	"helm.sh/helm/v3/cmd/helm/require"
25	"helm.sh/helm/v3/internal/completion"
26	"helm.sh/helm/v3/pkg/action"
27	"helm.sh/helm/v3/pkg/cli/output"
28)
29
30var getAllHelp = `
31This command prints a human readable collection of information about the
32notes, hooks, supplied values, and generated manifest file of the given release.
33`
34
35func 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		RunE: func(cmd *cobra.Command, args []string) error {
45			res, err := client.Run(args[0])
46			if err != nil {
47				return err
48			}
49			if template != "" {
50				data := map[string]interface{}{
51					"Release": res,
52				}
53				return tpl(template, data, out)
54			}
55
56			return output.Table.Write(out, &statusPrinter{res, true})
57		},
58	}
59
60	// Function providing dynamic auto-completion
61	completion.RegisterValidArgsFunc(cmd, func(cmd *cobra.Command, args []string, toComplete string) ([]string, completion.BashCompDirective) {
62		if len(args) != 0 {
63			return nil, completion.BashCompDirectiveNoFileComp
64		}
65		return compListReleases(toComplete, cfg)
66	})
67
68	f := cmd.Flags()
69	f.IntVar(&client.Version, "revision", 0, "get the named release with revision")
70	flag := f.Lookup("revision")
71	completion.RegisterFlagCompletionFunc(flag, func(cmd *cobra.Command, args []string, toComplete string) ([]string, completion.BashCompDirective) {
72		if len(args) == 1 {
73			return compListRevisions(cfg, args[0])
74		}
75		return nil, completion.BashCompDirectiveNoFileComp
76	})
77
78	f.StringVar(&template, "template", "", "go template for formatting the output, eg: {{.Release.Name}}")
79
80	return cmd
81}
82