Skip to content

Commit

Permalink
feat: project-group list (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
benPearce1 authored Oct 20, 2022
1 parent 75ebb09 commit d6e7f9f
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pkg/cmd/project/list/list.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package list

import (
"fmt"
"github.com/MakeNowJust/heredoc/v2"
"github.com/OctopusDeploy/cli/pkg/constants"
"github.com/OctopusDeploy/cli/pkg/factory"
"github.com/OctopusDeploy/cli/pkg/output"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/projects"
Expand All @@ -13,10 +15,10 @@ func NewCmdList(f factory.Factory) *cobra.Command {
Use: "list",
Short: "List projects in Octopus Deploy",
Long: "List projects in Octopus Deploy",
Example: heredoc.Doc(`
$ octopus project list
$ octopus project ls
`),
Example: fmt.Sprintf(heredoc.Doc(`
$ %s project list
$ %s project ls
`), constants.ExecutableName, constants.ExecutableName),
Aliases: []string{"ls"},
RunE: func(cmd *cobra.Command, args []string) error {
return listRun(cmd, f)
Expand Down Expand Up @@ -47,7 +49,7 @@ func listRun(cmd *cobra.Command, f factory.Factory) error {
Json: func(p *projects.Project) any {
return ProjectAsJson{
Id: p.GetID(),
Name: p.Name,
Name: p.GetName(),
Description: p.Description,
}
},
Expand All @@ -58,7 +60,7 @@ func listRun(cmd *cobra.Command, f factory.Factory) error {
},
},
Basic: func(p *projects.Project) string {
return p.Name
return p.GetName()
},
})
}
66 changes: 66 additions & 0 deletions pkg/cmd/projectgroup/list/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package list

import (
"fmt"
"github.com/MakeNowJust/heredoc/v2"
"github.com/OctopusDeploy/cli/pkg/constants"
"github.com/OctopusDeploy/cli/pkg/factory"
"github.com/OctopusDeploy/cli/pkg/output"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/projectgroups"
"github.com/spf13/cobra"
)

type ProjectGroupAsJson struct {
Id string `json:"Id"`
Name string `json:"Name"`
Description string `json:"Description"`
}

func NewCmdList(f factory.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "List project groups in Octopus Deploy",
Long: "List project groups in Octopus Deploy",
Example: fmt.Sprintf(heredoc.Doc(`
$ %s project-group list
$ %s project-group ls
`), constants.ExecutableName, constants.ExecutableName),
Aliases: []string{"ls"},
RunE: func(cmd *cobra.Command, args []string) error {
return listRun(cmd, f)
},
}

return cmd
}

func listRun(cmd *cobra.Command, f factory.Factory) error {
client, err := f.GetSpacedClient()
if err != nil {
return err
}

allProjects, err := client.ProjectGroups.GetAll()
if err != nil {
return err
}

return output.PrintArray(allProjects, cmd, output.Mappers[*projectgroups.ProjectGroup]{
Json: func(p *projectgroups.ProjectGroup) any {
return ProjectGroupAsJson{
Id: p.GetID(),
Name: p.Name,
Description: p.Description,
}
},
Table: output.TableDefinition[*projectgroups.ProjectGroup]{
Header: []string{"NAME", "DESCRIPTION"},
Row: func(p *projectgroups.ProjectGroup) []string {
return []string{output.Bold(p.Name), p.Description}
},
},
Basic: func(p *projectgroups.ProjectGroup) string {
return p.Name
},
})
}
2 changes: 2 additions & 0 deletions pkg/cmd/projectgroup/project-group.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/MakeNowJust/heredoc/v2"
createCmd "github.com/OctopusDeploy/cli/pkg/cmd/projectgroup/create"
listCmd "github.com/OctopusDeploy/cli/pkg/cmd/projectgroup/list"
"github.com/OctopusDeploy/cli/pkg/constants"
"github.com/OctopusDeploy/cli/pkg/constants/annotations"
"github.com/OctopusDeploy/cli/pkg/factory"
Expand All @@ -25,6 +26,7 @@ func NewCmdProjectGroup(f factory.Factory) *cobra.Command {
}

cmd.AddCommand(createCmd.NewCmdCreate(f))
cmd.AddCommand(listCmd.NewCmdList(f))

return cmd
}

0 comments on commit d6e7f9f

Please sign in to comment.