MCPcopy
hub / github.com/helm/helm / newEnvCmd

Function newEnvCmd

pkg/cmd/env.go:33–64  ·  view source on GitHub ↗
(out io.Writer)

Source from the content-addressed store, hash-verified

31`
32
33func newEnvCmd(out io.Writer) *cobra.Command {
34 cmd := &cobra.Command{
35 Use: "env",
36 Short: "helm client environment information",
37 Long: envHelp,
38 Args: require.MaximumNArgs(1),
39 ValidArgsFunction: func(_ *cobra.Command, args []string, _ string) ([]string, cobra.ShellCompDirective) {
40 if len(args) == 0 {
41 keys := getSortedEnvVarKeys()
42 return keys, cobra.ShellCompDirectiveNoFileComp
43 }
44
45 return noMoreArgsComp()
46 },
47 Run: func(_ *cobra.Command, args []string) {
48 envVars := settings.EnvVars()
49
50 if len(args) == 0 {
51 // Sort the variables by alphabetical order.
52 // This allows for a constant output across calls to 'helm env'.
53 keys := getSortedEnvVarKeys()
54
55 for _, k := range keys {
56 fmt.Fprintf(out, "%s=\"%s\"\n", k, envVars[k])
57 }
58 } else {
59 fmt.Fprintf(out, "%s\n", envVars[args[0]])
60 }
61 },
62 }
63 return cmd
64}
65
66func getSortedEnvVarKeys() []string {
67 envVars := settings.EnvVars()

Callers 1

newRootCmdWithConfigFunction · 0.85

Calls 4

MaximumNArgsFunction · 0.92
getSortedEnvVarKeysFunction · 0.85
noMoreArgsCompFunction · 0.85
EnvVarsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…