From 7fab24af71a15b2307a4c97e3846b97376446e8a Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Wed, 24 Jul 2024 10:42:38 +1000 Subject: [PATCH] fix: list and get environment and project to display same data (#362) * fix: list and get environment to display same information, extend get to include wide * fix: list and get project to display same information, extend get to include wide --- cmd/get.go | 86 ++++++++++++++++++------- cmd/list.go | 9 ++- docs/commands/lagoon_get_environment.md | 1 + docs/commands/lagoon_get_project.md | 1 + go.mod | 2 +- go.sum | 4 +- 6 files changed, 73 insertions(+), 30 deletions(-) diff --git a/cmd/get.go b/cmd/get.go index de1c6d66..5d5ca03d 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -41,6 +41,10 @@ var getProjectCmd = &cobra.Command{ if err != nil { return err } + wide, err := cmd.Flags().GetBool("wide") + if err != nil { + return err + } if err := requiredInputCheck("Project name", cmdProjectName); err != nil { return err } @@ -65,7 +69,7 @@ var getProjectCmd = &cobra.Command{ } DevEnvironments := 0 - productionRoute := "none" + productionRoute := "" deploymentsDisabled, err := strconv.ParseBool(strconv.Itoa(int(project.DeploymentsDisabled))) if err != nil { return err @@ -91,25 +95,35 @@ var getProjectCmd = &cobra.Command{ } } - data := []output.Data{} - data = append(data, []string{ + projData := []string{ returnNonEmptyString(fmt.Sprintf("%d", project.ID)), returnNonEmptyString(fmt.Sprintf("%v", project.Name)), returnNonEmptyString(fmt.Sprintf("%v", project.GitURL)), - returnNonEmptyString(fmt.Sprintf("%v", project.Branches)), - returnNonEmptyString(fmt.Sprintf("%v", project.PullRequests)), + returnNonEmptyString(fmt.Sprintf("%v", project.ProductionEnvironment)), returnNonEmptyString(fmt.Sprintf("%v", productionRoute)), returnNonEmptyString(fmt.Sprintf("%v/%v", DevEnvironments, project.DevelopmentEnvironmentsLimit)), - returnNonEmptyString(fmt.Sprintf("%v", project.DevelopmentEnvironmentsLimit)), - returnNonEmptyString(fmt.Sprintf("%v", project.ProductionEnvironment)), - returnNonEmptyString(fmt.Sprintf("%v", project.RouterPattern)), - returnNonEmptyString(fmt.Sprintf("%v", autoIdle)), - returnNonEmptyString(fmt.Sprintf("%v", factsUI)), - returnNonEmptyString(fmt.Sprintf("%v", problemsUI)), - returnNonEmptyString(fmt.Sprintf("%v", deploymentsDisabled)), - }) + } + projHeader := []string{"ID", "ProjectName", "GitUrl", "ProductionEnvironment", "ProductionRoute", "DevEnvironments"} + if wide { + projHeader = append(projHeader, "AutoIdle") + projData = append(projData, returnNonEmptyString(fmt.Sprintf("%v", autoIdle))) + projHeader = append(projHeader, "Branches") + projData = append(projData, returnNonEmptyString(fmt.Sprintf("%v", project.Branches))) + projHeader = append(projHeader, "PullRequests") + projData = append(projData, returnNonEmptyString(fmt.Sprintf("%v", project.PullRequests))) + projHeader = append(projHeader, "RouterPattern") + projData = append(projData, returnNonEmptyString(fmt.Sprintf("%v", project.RouterPattern))) + projHeader = append(projHeader, "FactsUI") + projData = append(projData, returnNonEmptyString(fmt.Sprintf("%v", factsUI))) + projHeader = append(projHeader, "ProblemsUI") + projData = append(projData, returnNonEmptyString(fmt.Sprintf("%v", problemsUI))) + projHeader = append(projHeader, "DeploymentsDisabled") + projData = append(projData, returnNonEmptyString(fmt.Sprintf("%v", deploymentsDisabled))) + } + data := []output.Data{} + data = append(data, projData) dataMain := output.Table{ - Header: []string{"ID", "ProjectName", "GitURL", "Branches", "PullRequests", "ProductionRoute", "DevEnvironments", "DevEnvLimit", "ProductionEnv", "RouterPattern", "AutoIdle", "FactsUI", "ProblemsUI", "DeploymentsDisabled"}, + Header: projHeader, Data: data, } output.RenderOutput(dataMain, outputOptions) @@ -204,6 +218,10 @@ var getEnvironmentCmd = &cobra.Command{ if err != nil { return err } + wide, err := cmd.Flags().GetBool("wide") + if err != nil { + return err + } if err := requiredInputCheck("Project name", cmdProjectName, "Environment name", cmdProjectEnvironment); err != nil { return err } @@ -226,22 +244,38 @@ var getEnvironmentCmd = &cobra.Command{ } data := []output.Data{} - data = append(data, []string{ + var envRoute = "none" + if environment.Route != "" { + envRoute = environment.Route + } + envData := []string{ returnNonEmptyString(fmt.Sprintf("%d", environment.ID)), returnNonEmptyString(fmt.Sprintf("%v", environment.Name)), - returnNonEmptyString(fmt.Sprintf("%v", environment.EnvironmentType)), returnNonEmptyString(fmt.Sprintf("%v", environment.DeployType)), - returnNonEmptyString(fmt.Sprintf("%v", environment.Created)), + returnNonEmptyString(fmt.Sprintf("%v", environment.EnvironmentType)), returnNonEmptyString(fmt.Sprintf("%v", environment.OpenshiftProjectName)), - returnNonEmptyString(fmt.Sprintf("%v", environment.Route)), - returnNonEmptyString(fmt.Sprintf("%v", environment.Routes)), - returnNonEmptyString(fmt.Sprintf("%d", environment.AutoIdle)), - returnNonEmptyString(fmt.Sprintf("%v", environment.DeployTitle)), - returnNonEmptyString(fmt.Sprintf("%v", environment.DeployBaseRef)), - returnNonEmptyString(fmt.Sprintf("%v", environment.DeployHeadRef)), - }) + returnNonEmptyString(fmt.Sprintf("%v", envRoute)), + returnNonEmptyString(fmt.Sprintf("%v", environment.DeployTarget.Name)), + } + envHeader := []string{"ID", "Name", "DeployType", "EnvironmentType", "Namespace", "Route", "DeployTarget"} + // if wide, add additional fields to the result + if wide { + 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))) + envHeader = append(envHeader, "DeployTitle") + envData = append(envData, returnNonEmptyString(fmt.Sprintf("%v", environment.DeployTitle))) + envHeader = append(envHeader, "DeployBaseRef") + envData = append(envData, returnNonEmptyString(fmt.Sprintf("%v", environment.DeployBaseRef))) + envHeader = append(envHeader, "DeployHeadRef") + envData = append(envData, returnNonEmptyString(fmt.Sprintf("%v", environment.DeployHeadRef))) + envHeader = append(envHeader, "Routes") + envData = append(envData, returnNonEmptyString(fmt.Sprintf("%v", environment.Routes))) + } + data = append(data, envData) dataMain := output.Table{ - Header: []string{"ID", "EnvironmentName", "EnvironmentType", "DeployType", "Created", "Namespace", "Route", "Routes", "AutoIdle", "DeployTitle", "DeployBaseRef", "DeployHeadRef"}, + Header: envHeader, Data: data, } output.RenderOutput(dataMain, outputOptions) @@ -392,4 +426,6 @@ func init() { getDeploymentByNameCmd.Flags().StringP("name", "N", "", "The name of the deployment (eg, lagoon-build-abcdef)") getDeploymentByNameCmd.Flags().BoolP("logs", "L", false, "Show the build logs if available") getOrganizationCmd.Flags().StringP("organization-name", "O", "", "Name of the organization") + getEnvironmentCmd.Flags().Bool("wide", false, "Display additional information about the environment") + getProjectCmd.Flags().Bool("wide", false, "Display additional information about the project") } diff --git a/cmd/list.go b/cmd/list.go index efa302cc..9483e882 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -56,10 +56,14 @@ var listProjectsCmd = &cobra.Command{ data := []output.Data{} for _, project := range *projects { var devEnvironments = 0 + productionRoute := "" for _, environment := range project.Environments { if environment.EnvironmentType == "development" { devEnvironments++ } + if environment.EnvironmentType == "production" { + productionRoute = environment.Route + } } data = append(data, []string{ @@ -67,6 +71,7 @@ var listProjectsCmd = &cobra.Command{ returnNonEmptyString(fmt.Sprintf("%v", project.Name)), returnNonEmptyString(fmt.Sprintf("%v", project.GitURL)), returnNonEmptyString(fmt.Sprintf("%v", project.ProductionEnvironment)), + returnNonEmptyString(fmt.Sprintf("%v", productionRoute)), returnNonEmptyString(fmt.Sprintf("%v/%v", devEnvironments, project.DevelopmentEnvironmentsLimit)), }) } @@ -74,7 +79,7 @@ var listProjectsCmd = &cobra.Command{ outputOptions.Error = "No access to any projects in Lagoon\n" } dataMain := output.Table{ - Header: []string{"ID", "ProjectName", "GitUrl", "ProductionEnvironment", "DevEnvironments"}, + Header: []string{"ID", "ProjectName", "GitUrl", "ProductionEnvironment", "ProductionRoute", "DevEnvironments"}, Data: data, } @@ -331,7 +336,7 @@ var listEnvironmentsCmd = &cobra.Command{ }) } dataMain := output.Table{ - Header: []string{"ID", "Name", "DeployType", "Environment", "Namespace", "Route", "DeployTarget"}, + Header: []string{"ID", "Name", "DeployType", "EnvironmentType", "Namespace", "Route", "DeployTarget"}, Data: data, } output.RenderOutput(dataMain, outputOptions) diff --git a/docs/commands/lagoon_get_environment.md b/docs/commands/lagoon_get_environment.md index 85d37874..f4a19fcc 100644 --- a/docs/commands/lagoon_get_environment.md +++ b/docs/commands/lagoon_get_environment.md @@ -10,6 +10,7 @@ lagoon get environment [flags] ``` -h, --help help for environment + --wide Display additional information about the environment ``` ### Options inherited from parent commands diff --git a/docs/commands/lagoon_get_project.md b/docs/commands/lagoon_get_project.md index 8c0cb54a..bae36beb 100644 --- a/docs/commands/lagoon_get_project.md +++ b/docs/commands/lagoon_get_project.md @@ -10,6 +10,7 @@ lagoon get project [flags] ``` -h, --help help for project + --wide Display additional information about the project ``` ### Options inherited from parent commands diff --git a/go.mod b/go.mod index aa4907f1..08505142 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/spf13/cobra v1.8.0 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.8.2 - github.com/uselagoon/machinery v0.0.23 + github.com/uselagoon/machinery v0.0.24 golang.org/x/crypto v0.21.0 golang.org/x/term v0.18.0 gopkg.in/yaml.v3 v3.0.1 diff --git a/go.sum b/go.sum index 181cb364..cf04cbec 100644 --- a/go.sum +++ b/go.sum @@ -66,8 +66,8 @@ github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/uselagoon/machinery v0.0.23 h1:8fRoVo3/dAByFQQH7Po35vEjFmtT4MmE326EuCkSvFc= -github.com/uselagoon/machinery v0.0.23/go.mod h1:NbgtEofjK2XY0iUpk9aMYazIo+W/NI56+UF72jv8zVY= +github.com/uselagoon/machinery v0.0.24 h1:Kea7eQiwqrlF1NnG4YmV5dMNM1NxuhiY1vhoahEFkQA= +github.com/uselagoon/machinery v0.0.24/go.mod h1:NbgtEofjK2XY0iUpk9aMYazIo+W/NI56+UF72jv8zVY= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=