Merge pull request #8638 from rudeigerc/feat/env-variable

Signed-off-by: Matt Farina <matt@mattfarina.com>
pull/8650/head
Matt Farina 4 years ago committed by GitHub
commit 4f7b9fcb67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -32,25 +32,45 @@ Env prints out all the environment information in use by Helm.
func newEnvCmd(out io.Writer) *cobra.Command { func newEnvCmd(out io.Writer) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "env", Use: "env",
Short: "helm client environment information", Short: "helm client environment information",
Long: envHelp, Long: envHelp,
Args: require.NoArgs, Args: require.MaximumNArgs(1),
ValidArgsFunction: noCompletions, ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) == 0 {
keys := getSortedEnvVarKeys()
return keys, cobra.ShellCompDirectiveNoFileComp
}
return nil, cobra.ShellCompDirectiveNoFileComp
},
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
envVars := settings.EnvVars() envVars := settings.EnvVars()
// Sort the variables by alphabetical order. if len(args) == 0 {
// This allows for a constant output across calls to 'helm env'. // Sort the variables by alphabetical order.
var keys []string // This allows for a constant output across calls to 'helm env'.
for k := range envVars { keys := getSortedEnvVarKeys()
keys = append(keys, k)
} for _, k := range keys {
sort.Strings(keys) fmt.Fprintf(out, "%s=\"%s\"\n", k, envVars[k])
for _, k := range keys { }
fmt.Fprintf(out, "%s=\"%s\"\n", k, envVars[k]) } else {
fmt.Fprintf(out, "%s\n", envVars[args[0]])
} }
}, },
} }
return cmd return cmd
} }
func getSortedEnvVarKeys() []string {
envVars := settings.EnvVars()
var keys []string
for k := range envVars {
keys = append(keys, k)
}
sort.Strings(keys)
return keys
}

@ -20,6 +20,16 @@ import (
"testing" "testing"
) )
func TestEnv(t *testing.T) {
tests := []cmdTestCase{{
name: "completion for env",
cmd: "__complete env ''",
golden: "output/env-comp.txt",
}}
runTestCmd(t, tests)
}
func TestEnvFileCompletion(t *testing.T) { func TestEnvFileCompletion(t *testing.T) {
checkFileCompletion(t, "env", false) checkFileCompletion(t, "env", false)
checkFileCompletion(t, "env HELM_BIN", false)
} }

@ -0,0 +1,16 @@
HELM_BIN
HELM_CACHE_HOME
HELM_CONFIG_HOME
HELM_DATA_HOME
HELM_DEBUG
HELM_KUBEAPISERVER
HELM_KUBECONTEXT
HELM_KUBETOKEN
HELM_MAX_HISTORY
HELM_NAMESPACE
HELM_PLUGINS
HELM_REGISTRY_CONFIG
HELM_REPOSITORY_CACHE
HELM_REPOSITORY_CONFIG
:4
Completion ended with directive: ShellCompDirectiveNoFileComp
Loading…
Cancel
Save