-
Notifications
You must be signed in to change notification settings - Fork 788
/
step_helm_env.go
75 lines (64 loc) · 1.62 KB
/
step_helm_env.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package helm
import (
"strings"
"github.com/jenkins-x/jx/v2/pkg/cmd/opts/step"
"github.com/jenkins-x/jx/v2/pkg/cmd/helper"
"github.com/jenkins-x/jx/v2/pkg/cmd/opts"
"github.com/jenkins-x/jx/v2/pkg/cmd/templates"
"github.com/jenkins-x/jx/v2/pkg/log"
"github.com/jenkins-x/jx/v2/pkg/util"
"github.com/spf13/cobra"
)
// StepHelmEnvOptions contains the command line flags
type StepHelmEnvOptions struct {
StepHelmOptions
}
var (
StepHelmEnvLong = templates.LongDesc(`
Generates the helm environment variables
`)
StepHelmEnvExample = templates.Examples(`
# output the helm environment variables that should be set to use helm directly
jx step helm env
`)
)
func NewCmdStepHelmEnv(commonOpts *opts.CommonOptions) *cobra.Command {
options := StepHelmEnvOptions{
StepHelmOptions: StepHelmOptions{
StepOptions: step.StepOptions{
CommonOptions: commonOpts,
},
},
}
cmd := &cobra.Command{
Use: "env",
Short: "Generates the helm environment variables",
Aliases: []string{""},
Long: StepHelmEnvLong,
Example: StepHelmEnvExample,
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
err := options.Run()
helper.CheckErr(err)
},
}
options.addStepHelmFlags(cmd)
return cmd
}
func (o *StepHelmEnvOptions) Run() error {
h := o.Helm()
if h != nil {
log.Logger().Info("")
log.Logger().Info("# helm environment variables")
envVars := h.Env()
keys := util.SortedMapKeys(envVars)
for _, key := range keys {
if strings.HasPrefix(key, "HELM") {
log.Logger().Infof("export %s=\"%s\"", key, envVars[key])
}
}
log.Logger().Info("")
}
return nil
}