Skip to content

Commit

Permalink
Refactor: Updates return types to utilize the output package (#301)
Browse files Browse the repository at this point in the history
* Started updating return types to utilize the output package

* Updated to return zero results instead of erroring

* Updated additional cmds

* Updated machinery

* chore: fix indrect reference and go mod tidy

---------

Co-authored-by: shreddedbacon <[email protected]>
  • Loading branch information
CGoodwin90 and shreddedbacon authored Mar 21, 2024
1 parent e6f5bad commit 936d760
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
16 changes: 16 additions & 0 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ var listEnvironmentsCmd = &cobra.Command{
return err
}

if len(*environments) == 0 {
outputOptions.Error = fmt.Sprintf("No environments found for project '%s'\n", cmdProjectName)
}

data := []output.Data{}
for _, environment := range *environments {
var envRoute = "none"
Expand Down Expand Up @@ -674,6 +678,10 @@ var listOrganizationProjectsCmd = &cobra.Command{
orgProjects, err := l.ListProjectsByOrganizationID(context.TODO(), org.ID, lc)
handleError(err)

if len(*orgProjects) == 0 {
outputOptions.Error = fmt.Sprintf("No associated projects found for organization '%s'\n", organizationName)
}

data := []output.Data{}
for _, project := range *orgProjects {
data = append(data, []string{
Expand Down Expand Up @@ -723,6 +731,10 @@ var listOrganizationGroupsCmd = &cobra.Command{
orgGroups, err := l.ListGroupsByOrganizationID(context.TODO(), org.ID, lc)
handleError(err)

if len(*orgGroups) == 0 {
outputOptions.Error = fmt.Sprintf("No associated groups found for organization '%s'\n", organizationName)
}

data := []output.Data{}
for _, group := range *orgGroups {
data = append(data, []string{
Expand Down Expand Up @@ -777,6 +789,10 @@ var listOrganizationDeployTargetsCmd = &cobra.Command{
deployTargets, err := l.ListDeployTargetsByOrganizationNameOrID(context.TODO(), nullStrCheck(organizationName), nullUintCheck(organizationID), lc)
handleError(err)

if len(*deployTargets) == 0 {
outputOptions.Error = fmt.Sprintf("No associated deploy targets found for organization '%s'\n", organizationName)
}

data := []output.Data{}
for _, dt := range *deployTargets {
data = append(data, []string{
Expand Down
7 changes: 3 additions & 4 deletions cmd/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ var listProjectByMetadata = &cobra.Command{
}
if len(*projects) == 0 {
if value != "" {
return fmt.Errorf(fmt.Sprintf("No projects found with metadata key %s and value %s", key, value))
outputOptions.Error = fmt.Sprintf("No projects found with metadata key '%s' and value '%s'\n", key, value)
}
return fmt.Errorf(fmt.Sprintf("No projects found with metadata key %s", key))
outputOptions.Error = fmt.Sprintf("No projects found with metadata key '%s'\n", key)
}
data := []output.Data{}
for _, project := range *projects {
Expand Down Expand Up @@ -231,8 +231,7 @@ var getProjectMetadata = &cobra.Command{
return err
}
if len(project.Metadata) == 0 {
output.RenderInfo(fmt.Sprintf("There is no metadata for project '%s'", cmdProjectName), outputOptions)
return nil
outputOptions.Error = fmt.Sprintf("There is no metadata for project '%s'\n", cmdProjectName)
}
data := []output.Data{}
for metaKey, metaVal := range project.Metadata {
Expand Down
13 changes: 0 additions & 13 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,11 @@ 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.16 h1:LGWUaESTXPfiTyJTJCC1i+3ghidY2qsf9li7mGbH9Wo=
github.com/uselagoon/machinery v0.0.16/go.mod h1:Duljjz/3d/7m0jbmF1nVRDTNaMxMr6m+5LkgjiRrQaU=
github.com/uselagoon/machinery v0.0.17-0.20240313011522-ed1d14100c69 h1:T6wm/RNQMhIdAWtzcVGttbXKasPNN/KKqUeBBOURiFI=
github.com/uselagoon/machinery v0.0.17-0.20240313011522-ed1d14100c69/go.mod h1:Duljjz/3d/7m0jbmF1nVRDTNaMxMr6m+5LkgjiRrQaU=
github.com/uselagoon/machinery v0.0.18 h1:KQLMAYa0pJOSDlnwv7uKa4XXZTqw8WiI0VL+yIFgesM=
github.com/uselagoon/machinery v0.0.18/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=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
Expand All @@ -93,15 +86,9 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down

0 comments on commit 936d760

Please sign in to comment.