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 {
cmd := &cobra.Command{
Use: "env",
Short: "helm client environment information",
Long: envHelp,
Args: require.NoArgs,
ValidArgsFunction: noCompletions,
Use: "env",
Short: "helm client environment information",
Long: envHelp,
Args: require.MaximumNArgs(1),
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) {
envVars := settings.EnvVars()
// Sort the variables by alphabetical order.
// This allows for a constant output across calls to 'helm env'.
var keys []string
for k := range envVars {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
fmt.Fprintf(out, "%s=\"%s\"\n", k, envVars[k])
if len(args) == 0 {
// Sort the variables by alphabetical order.
// This allows for a constant output across calls to 'helm env'.
keys := getSortedEnvVarKeys()
for _, k := range keys {
fmt.Fprintf(out, "%s=\"%s\"\n", k, envVars[k])
}
} else {
fmt.Fprintf(out, "%s\n", envVars[args[0]])
}
},
}
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"
)
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) {
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