Skip to content

Commit e4ad4ce

Browse files
authored
Refactor: Refactors environment auto-idle from uint to boolean (#377)
1 parent 3aae685 commit e4ad4ce

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

cmd/environment.go

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,11 @@ import (
88
"github.com/uselagoon/machinery/api/schema"
99

1010
"github.com/spf13/cobra"
11-
"github.com/spf13/pflag"
1211
"github.com/uselagoon/lagoon-cli/pkg/output"
1312
"github.com/uselagoon/machinery/api/lagoon"
1413
lclient "github.com/uselagoon/machinery/api/lagoon/client"
1514
)
1615

17-
// @TODO re-enable this at some point if more environment based commands are made available
18-
var environmentAutoIdle uint
19-
var environmentAutoIdleProvided bool
20-
2116
var deleteEnvCmd = &cobra.Command{
2217
Use: "environment",
2318
Aliases: []string{"e"},
@@ -105,8 +100,11 @@ var updateEnvironmentCmd = &cobra.Command{
105100
if err != nil {
106101
return err
107102
}
108-
109-
cmd.Flags().Visit(checkFlags)
103+
autoIdle, err := cmd.Flags().GetBool("auto-idle")
104+
if err != nil {
105+
return err
106+
}
107+
autoIdleProvided := cmd.Flags().Lookup("auto-idle").Changed
110108

111109
if err := requiredInputCheck("Project name", cmdProjectName, "Environment name", cmdProjectEnvironment); err != nil {
112110
return err
@@ -144,8 +142,8 @@ var updateEnvironmentCmd = &cobra.Command{
144142
DeployTitle: nullStrCheck(deployTitle),
145143
Openshift: nullUintCheck(deploytarget),
146144
}
147-
if environmentAutoIdleProvided {
148-
environmentFlags.AutoIdle = &environmentAutoIdle
145+
if autoIdleProvided {
146+
environmentFlags.AutoIdle = nullBoolToUint(autoIdle)
149147
}
150148
if environmentType != "" {
151149
envType := schema.EnvType(strings.ToUpper(environmentType))
@@ -179,12 +177,6 @@ var updateEnvironmentCmd = &cobra.Command{
179177
},
180178
}
181179

182-
func checkFlags(f *pflag.Flag) {
183-
if f.Name == "auto-idle" {
184-
environmentAutoIdleProvided = true
185-
}
186-
}
187-
188180
var listBackupsCmd = &cobra.Command{
189181
Use: "backups",
190182
Aliases: []string{"b"},
@@ -320,7 +312,7 @@ func init() {
320312
updateEnvironmentCmd.Flags().String("namespace", "", "Update the namespace for the selected environment")
321313
updateEnvironmentCmd.Flags().String("route", "", "Update the route for the selected environment")
322314
updateEnvironmentCmd.Flags().String("routes", "", "Update the routes for the selected environment")
323-
updateEnvironmentCmd.Flags().UintVarP(&environmentAutoIdle, "auto-idle", "a", 1, "Auto idle setting of the environment")
315+
updateEnvironmentCmd.Flags().BoolP("auto-idle", "a", false, "Auto idle setting of the environment. Set to enable, --auto-idle=false to disable")
324316
updateEnvironmentCmd.Flags().UintP("deploytarget", "d", 0, "Reference to Deploytarget(Kubernetes) this Environment should be deployed to")
325317
updateEnvironmentCmd.Flags().String("environment-type", "", "Update the environment type - production | development")
326318
updateEnvironmentCmd.Flags().String("deploy-type", "", "Update the deploy type - branch | pullrequest | promote")

cmd/get.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@ var getEnvironmentCmd = &cobra.Command{
256256
}
257257
}
258258

259+
autoIdle, err := strconv.ParseBool(strconv.Itoa(int(*environment.AutoIdle)))
260+
if err != nil {
261+
return err
262+
}
263+
259264
data := []output.Data{}
260265
var envRoute = "none"
261266
if environment.Route != "" {
@@ -276,7 +281,7 @@ var getEnvironmentCmd = &cobra.Command{
276281
envHeader = append(envHeader, "Created")
277282
envData = append(envData, returnNonEmptyString(fmt.Sprintf("%v", environment.Created)))
278283
envHeader = append(envHeader, "AutoIdle")
279-
envData = append(envData, returnNonEmptyString(fmt.Sprintf("%v", environment.AutoIdle)))
284+
envData = append(envData, returnNonEmptyString(fmt.Sprintf("%v", autoIdle)))
280285
envHeader = append(envHeader, "DeployTitle")
281286
envData = append(envData, returnNonEmptyString(fmt.Sprintf("%v", environment.DeployTitle)))
282287
envHeader = append(envHeader, "DeployBaseRef")

docs/commands/lagoon_update_environment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ lagoon update environment [flags]
99
### Options
1010

1111
```
12-
-a, --auto-idle uint Auto idle setting of the environment (default 1)
12+
-a, --auto-idle Auto idle setting of the environment. Set to enable, --auto-idle=false to disable
1313
--deploy-base-ref string Updates the deploy base ref for the selected environment
1414
--deploy-head-ref string Updates the deploy head ref for the selected environment
1515
--deploy-title string Updates the deploy title for the selected environment

0 commit comments

Comments
 (0)