Skip to content

Commit

Permalink
fix: list and get project to display same information, extend get to …
Browse files Browse the repository at this point in the history
…include wide
  • Loading branch information
shreddedbacon committed Jul 22, 2024
1 parent 40bac57 commit ac4b94c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
43 changes: 29 additions & 14 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 @@ -413,4 +427,5 @@ func init() {
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")
}
7 changes: 6 additions & 1 deletion 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
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.24-0.20240722003955-19e63e32423a
github.com/uselagoon/machinery v0.0.24-0.20240722005832-5029bf3feafb
golang.org/x/crypto v0.21.0
golang.org/x/term v0.18.0
gopkg.in/yaml.v3 v3.0.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ github.com/uselagoon/machinery v0.0.23 h1:8fRoVo3/dAByFQQH7Po35vEjFmtT4MmE326EuC
github.com/uselagoon/machinery v0.0.23/go.mod h1:NbgtEofjK2XY0iUpk9aMYazIo+W/NI56+UF72jv8zVY=
github.com/uselagoon/machinery v0.0.24-0.20240722003955-19e63e32423a h1:yQZRU4TORa4QYr5Mxuj7VSZN84Qo0b//asRQdNlhAbo=
github.com/uselagoon/machinery v0.0.24-0.20240722003955-19e63e32423a/go.mod h1:NbgtEofjK2XY0iUpk9aMYazIo+W/NI56+UF72jv8zVY=
github.com/uselagoon/machinery v0.0.24-0.20240722005832-5029bf3feafb h1:wG4E7caTaB5p0CIrfpXLhmFQiucvav8fspAhE7XzSCQ=
github.com/uselagoon/machinery v0.0.24-0.20240722005832-5029bf3feafb/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 ac4b94c

Please sign in to comment.