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