Skip to content

Commit

Permalink
Refactors environment auto idle to boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
CGoodwin90 committed Aug 21, 2024
1 parent 3aae685 commit 43dd574
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
24 changes: 8 additions & 16 deletions cmd/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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"},
Expand Down Expand Up @@ -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")
Expand Down
7 changes: 6 additions & 1 deletion cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/lagoon_update_environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 43dd574

Please sign in to comment.