Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: List Project Groups functionality #288

Merged
merged 5 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is groupName defined? This message is confusing. I expect this message to be like "There are no groups for project '%s'" with the cmdProjectName as substitute

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙈
Will fix it up

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the condition though, this shouldn't ever be reached as projects should always have 1 group. Did you encounter this error?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I get this error message for all of our projects. We haven't assigned our projects to a group yet.

~ % lagoon list project-groups -p <PROJECT NAME>
Info: There are no projects in group ''

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.

Loading