Skip to content

Commit

Permalink
Feature: List Project Groups functionality (#288)
Browse files Browse the repository at this point in the history
Co-authored-by: Ben Jackson <[email protected]>
  • Loading branch information
CGoodwin90 and shreddedbacon authored Dec 5, 2023
1 parent 9274b3f commit fb8a37a
Show file tree
Hide file tree
Showing 19 changed files with 120 additions and 22 deletions.
56 changes: 56 additions & 0 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"os"
"strconv"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -436,11 +437,66 @@ var listNotificationCmd = &cobra.Command{
},
}

var listProjectGroupsCmd = &cobra.Command{
Use: "project-groups",
Aliases: []string{"pg"},
Short: "List groups in a project (alias: pg)",
PreRunE: func(_ *cobra.Command, _ []string) error {
return validateTokenE(lagoonCLIConfig.Current)
},
RunE: func(cmd *cobra.Command, args []string) error {
debug, err := cmd.Flags().GetBool("debug")
if err != nil {
return err
}
if cmdProjectName == "" {
fmt.Println("Missing arguments: Project is not defined")
cmd.Help()
os.Exit(1)
}

current := lagoonCLIConfig.Current
token := lagoonCLIConfig.Lagoons[current].Token
lc := lclient.New(
lagoonCLIConfig.Lagoons[current].GraphQL,
lagoonCLIVersion,
&token,
debug)
projectGroups, err := l.GetProjectGroups(context.TODO(), cmdProjectName, lc)
handleError(err)

if len(projectGroups.Groups) == 0 {
output.RenderInfo(fmt.Sprintf("There are no projects in group '%s'", groupName), outputOptions)
os.Exit(0)
}

data := []output.Data{}
for _, group := range projectGroups.Groups {
var organization = "null"
if group.Organization != 0 {
organization = strconv.Itoa(group.Organization)
}
data = append(data, []string{
returnNonEmptyString(fmt.Sprintf("%v", group.ID)),
returnNonEmptyString(fmt.Sprintf("%v", group.Name)),
returnNonEmptyString(fmt.Sprintf("%v", organization)),
})
}
dataMain := output.Table{
Header: []string{"Group ID", "Group Name", "Organization"},
Data: data,
}
output.RenderOutput(dataMain, outputOptions)
return nil
},
}

func init() {
listCmd.AddCommand(listDeployTargetsCmd)
listCmd.AddCommand(listDeploymentsCmd)
listCmd.AddCommand(listGroupsCmd)
listCmd.AddCommand(listGroupProjectsCmd)
listCmd.AddCommand(listProjectGroupsCmd)
listCmd.AddCommand(listEnvironmentsCmd)
listCmd.AddCommand(listProjectsCmd)
listCmd.AddCommand(listNotificationCmd)
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/lagoon.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ lagoon [flags]
* [lagoon get](lagoon_get.md) - Get info on a resource
* [lagoon import](lagoon_import.md) - Import a config from a yaml file
* [lagoon kibana](lagoon_kibana.md) - Launch the kibana interface
* [lagoon list](lagoon_list.md) - List projects, deployments, variables or notifications
* [lagoon list](lagoon_list.md) - List projects, environments, deployments, variables or notifications
* [lagoon login](lagoon_login.md) - Log into a Lagoon instance
* [lagoon retrieve](lagoon_retrieve.md) - Trigger a retrieval operation on backups
* [lagoon run](lagoon_run.md) - Run a task against an environment
Expand Down
5 changes: 3 additions & 2 deletions docs/commands/lagoon_list.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
## lagoon list

List projects, deployments, variables or notifications
List projects, environments, deployments, variables or notifications

### Synopsis

List projects, deployments, variables or notifications
List projects, environments, deployments, variables or notifications

### Options

Expand Down Expand Up @@ -42,6 +42,7 @@ List projects, deployments, variables or notifications
* [lagoon list groups](lagoon_list_groups.md) - List groups you have access to (alias: g)
* [lagoon list invokable-tasks](lagoon_list_invokable-tasks.md) - Print a list of invokable tasks
* [lagoon list notification](lagoon_list_notification.md) - List all notifications or notifications on projects
* [lagoon list project-groups](lagoon_list_project-groups.md) - List groups in a project (alias: pg)
* [lagoon list projects](lagoon_list_projects.md) - List all projects you have access to (alias: p)
* [lagoon list projects-by-metadata](lagoon_list_projects-by-metadata.md) - List projects by a given metadata key or key:value
* [lagoon list tasks](lagoon_list_tasks.md) - List tasks for an environment (alias: t)
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/lagoon_list_backups.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ lagoon list backups [flags]

### SEE ALSO

* [lagoon list](lagoon_list.md) - List projects, deployments, variables or notifications
* [lagoon list](lagoon_list.md) - List projects, environments, deployments, variables or notifications

2 changes: 1 addition & 1 deletion docs/commands/lagoon_list_deployments.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ lagoon list deployments [flags]

### SEE ALSO

* [lagoon list](lagoon_list.md) - List projects, deployments, variables or notifications
* [lagoon list](lagoon_list.md) - List projects, environments, deployments, variables or notifications

2 changes: 1 addition & 1 deletion docs/commands/lagoon_list_deploytarget-configs.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ lagoon list deploytarget-configs [flags]

### SEE ALSO

* [lagoon list](lagoon_list.md) - List projects, deployments, variables or notifications
* [lagoon list](lagoon_list.md) - List projects, environments, deployments, variables or notifications

2 changes: 1 addition & 1 deletion docs/commands/lagoon_list_deploytargets.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ lagoon list deploytargets [flags]

### SEE ALSO

* [lagoon list](lagoon_list.md) - List projects, deployments, variables or notifications
* [lagoon list](lagoon_list.md) - List projects, environments, deployments, variables or notifications

2 changes: 1 addition & 1 deletion docs/commands/lagoon_list_environments.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ lagoon list environments [flags]

### SEE ALSO

* [lagoon list](lagoon_list.md) - List projects, deployments, variables or notifications
* [lagoon list](lagoon_list.md) - List projects, environments, deployments, variables or notifications

2 changes: 1 addition & 1 deletion docs/commands/lagoon_list_group-projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ lagoon list group-projects [flags]

### SEE ALSO

* [lagoon list](lagoon_list.md) - List projects, deployments, variables or notifications
* [lagoon list](lagoon_list.md) - List projects, environments, deployments, variables or notifications

2 changes: 1 addition & 1 deletion docs/commands/lagoon_list_groups.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ lagoon list groups [flags]

### SEE ALSO

* [lagoon list](lagoon_list.md) - List projects, deployments, variables or notifications
* [lagoon list](lagoon_list.md) - List projects, environments, deployments, variables or notifications

2 changes: 1 addition & 1 deletion docs/commands/lagoon_list_invokable-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ lagoon list invokable-tasks [flags]

### SEE ALSO

* [lagoon list](lagoon_list.md) - List projects, deployments, variables or notifications
* [lagoon list](lagoon_list.md) - List projects, environments, deployments, variables or notifications

2 changes: 1 addition & 1 deletion docs/commands/lagoon_list_notification.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ List all notifications or notifications on projects

### SEE ALSO

* [lagoon list](lagoon_list.md) - List projects, deployments, variables or notifications
* [lagoon list](lagoon_list.md) - List projects, environments, deployments, variables or notifications
* [lagoon list notification email](lagoon_list_notification_email.md) - List all email notification details (alias: e)
* [lagoon list notification microsoftteams](lagoon_list_notification_microsoftteams.md) - List all Microsoft Teams notification details (alias: m)
* [lagoon list notification project-email](lagoon_list_notification_project-email.md) - List email details about a project (alias: pe)
Expand Down
39 changes: 39 additions & 0 deletions docs/commands/lagoon_list_project-groups.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## lagoon list project-groups

List groups in a project (alias: pg)

### Synopsis

List groups in a project (alias: pg)

```
lagoon list project-groups [flags]
```

### Options

```
-h, --help help for project-groups
```

### Options inherited from parent commands

```
--config-file string Path to the config file to use (must be *.yml or *.yaml)
--debug Enable debugging output (if supported)
-e, --environment string Specify an environment to use
--force Force yes on prompts (if supported)
-l, --lagoon string The Lagoon instance to interact with
--no-header No header on table (if supported)
--output-csv Output as CSV (if supported)
--output-json Output as JSON (if supported)
--pretty Make JSON pretty (if supported)
-p, --project string Specify a project to use
--skip-update-check Skip checking for updates
-i, --ssh-key string Specify path to a specific SSH key to use for lagoon authentication
```

### SEE ALSO

* [lagoon list](lagoon_list.md) - List projects, environments, deployments, variables or notifications

2 changes: 1 addition & 1 deletion docs/commands/lagoon_list_projects-by-metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ lagoon list projects-by-metadata [flags]

### SEE ALSO

* [lagoon list](lagoon_list.md) - List projects, deployments, variables or notifications
* [lagoon list](lagoon_list.md) - List projects, environments, deployments, variables or notifications

2 changes: 1 addition & 1 deletion docs/commands/lagoon_list_projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ lagoon list projects [flags]

### SEE ALSO

* [lagoon list](lagoon_list.md) - List projects, deployments, variables or notifications
* [lagoon list](lagoon_list.md) - List projects, environments, deployments, variables or notifications

2 changes: 1 addition & 1 deletion docs/commands/lagoon_list_tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ lagoon list tasks [flags]

### SEE ALSO

* [lagoon list](lagoon_list.md) - List projects, deployments, variables or notifications
* [lagoon list](lagoon_list.md) - List projects, environments, deployments, variables or notifications

2 changes: 1 addition & 1 deletion docs/commands/lagoon_list_users.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ lagoon list users [flags]

### SEE ALSO

* [lagoon list](lagoon_list.md) - List projects, deployments, variables or notifications
* [lagoon list](lagoon_list.md) - List projects, environments, deployments, variables or notifications

2 changes: 1 addition & 1 deletion docs/commands/lagoon_list_variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ lagoon list variables [flags]

### SEE ALSO

* [lagoon list](lagoon_list.md) - List projects, deployments, variables or notifications
* [lagoon list](lagoon_list.md) - List projects, environments, deployments, variables or notifications

12 changes: 7 additions & 5 deletions internal/lagoon/client/lgraphql/lgraphql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fb8a37a

Please sign in to comment.