(out io.Writer)
| 31 | ` |
| 32 | |
| 33 | func 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 | |
| 66 | func getSortedEnvVarKeys() []string { |
| 67 | envVars := settings.EnvVars() |
no test coverage detected
searching dependent graphs…