diff --git a/cmd/environment.go b/cmd/environment.go index fa4f6172..45b95185 100644 --- a/cmd/environment.go +++ b/cmd/environment.go @@ -8,16 +8,11 @@ import ( "github.com/uselagoon/machinery/api/schema" "github.com/spf13/cobra" - "github.com/spf13/pflag" "github.com/uselagoon/lagoon-cli/pkg/output" "github.com/uselagoon/machinery/api/lagoon" lclient "github.com/uselagoon/machinery/api/lagoon/client" ) -// @TODO re-enable this at some point if more environment based commands are made available -var environmentAutoIdle uint -var environmentAutoIdleProvided bool - var deleteEnvCmd = &cobra.Command{ Use: "environment", Aliases: []string{"e"}, @@ -105,8 +100,11 @@ var updateEnvironmentCmd = &cobra.Command{ if err != nil { return err } - - cmd.Flags().Visit(checkFlags) + autoIdle, err := cmd.Flags().GetBool("auto-idle") + if err != nil { + return err + } + autoIdleProvided := cmd.Flags().Lookup("auto-idle").Changed if err := requiredInputCheck("Project name", cmdProjectName, "Environment name", cmdProjectEnvironment); err != nil { return err @@ -144,8 +142,8 @@ var updateEnvironmentCmd = &cobra.Command{ DeployTitle: nullStrCheck(deployTitle), Openshift: nullUintCheck(deploytarget), } - if environmentAutoIdleProvided { - environmentFlags.AutoIdle = &environmentAutoIdle + if autoIdleProvided { + environmentFlags.AutoIdle = nullBoolToUint(autoIdle) } if environmentType != "" { envType := schema.EnvType(strings.ToUpper(environmentType)) @@ -179,12 +177,6 @@ var updateEnvironmentCmd = &cobra.Command{ }, } -func checkFlags(f *pflag.Flag) { - if f.Name == "auto-idle" { - environmentAutoIdleProvided = true - } -} - var listBackupsCmd = &cobra.Command{ Use: "backups", Aliases: []string{"b"}, @@ -320,7 +312,7 @@ func init() { updateEnvironmentCmd.Flags().String("namespace", "", "Update the namespace for the selected environment") updateEnvironmentCmd.Flags().String("route", "", "Update the route for the selected environment") updateEnvironmentCmd.Flags().String("routes", "", "Update the routes for the selected environment") - updateEnvironmentCmd.Flags().UintVarP(&environmentAutoIdle, "auto-idle", "a", 1, "Auto idle setting of the environment") + updateEnvironmentCmd.Flags().BoolP("auto-idle", "a", false, "Auto idle setting of the environment. Set to enable, --auto-idle=false to disable") updateEnvironmentCmd.Flags().UintP("deploytarget", "d", 0, "Reference to Deploytarget(Kubernetes) this Environment should be deployed to") updateEnvironmentCmd.Flags().String("environment-type", "", "Update the environment type - production | development") updateEnvironmentCmd.Flags().String("deploy-type", "", "Update the deploy type - branch | pullrequest | promote") diff --git a/cmd/get.go b/cmd/get.go index 0449ee55..b9411898 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -256,6 +256,11 @@ var getEnvironmentCmd = &cobra.Command{ } } + autoIdle, err := strconv.ParseBool(strconv.Itoa(int(*environment.AutoIdle))) + if err != nil { + return err + } + data := []output.Data{} var envRoute = "none" if environment.Route != "" { @@ -276,7 +281,7 @@ var getEnvironmentCmd = &cobra.Command{ envHeader = append(envHeader, "Created") envData = append(envData, returnNonEmptyString(fmt.Sprintf("%v", environment.Created))) envHeader = append(envHeader, "AutoIdle") - envData = append(envData, returnNonEmptyString(fmt.Sprintf("%v", environment.AutoIdle))) + envData = append(envData, returnNonEmptyString(fmt.Sprintf("%v", autoIdle))) envHeader = append(envHeader, "DeployTitle") envData = append(envData, returnNonEmptyString(fmt.Sprintf("%v", environment.DeployTitle))) envHeader = append(envHeader, "DeployBaseRef") diff --git a/docs/commands/lagoon_update_environment.md b/docs/commands/lagoon_update_environment.md index a2a06ca1..b938f8f6 100644 --- a/docs/commands/lagoon_update_environment.md +++ b/docs/commands/lagoon_update_environment.md @@ -9,7 +9,7 @@ lagoon update environment [flags] ### Options ``` - -a, --auto-idle uint Auto idle setting of the environment (default 1) + -a, --auto-idle Auto idle setting of the environment. Set to enable, --auto-idle=false to disable --deploy-base-ref string Updates the deploy base ref for the selected environment --deploy-head-ref string Updates the deploy head ref for the selected environment --deploy-title string Updates the deploy title for the selected environment