Skip to content

Commit

Permalink
fix: list and get environment and project to display same data (#362)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
shreddedbacon authored Jul 24, 2024
1 parent cf42a13 commit 7fab24a
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 30 deletions.
86 changes: 61 additions & 25 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand Down Expand Up @@ -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")
}
9 changes: 7 additions & 2 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,30 @@ 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{
returnNonEmptyString(fmt.Sprintf("%d", project.ID)),
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)),
})
}
if len(data) == 0 {
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,
}

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions docs/commands/lagoon_get_environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/commands/lagoon_get_project.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 7fab24a

Please sign in to comment.