diff --git a/cmd/list.go b/cmd/list.go index 6c2a23ef..d77f7188 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "os" + "strconv" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -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) diff --git a/docs/commands/lagoon.md b/docs/commands/lagoon.md index 6cfb47c0..7ab9ad66 100644 --- a/docs/commands/lagoon.md +++ b/docs/commands/lagoon.md @@ -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 diff --git a/docs/commands/lagoon_list.md b/docs/commands/lagoon_list.md index 2b48e078..31bdd6ed 100644 --- a/docs/commands/lagoon_list.md +++ b/docs/commands/lagoon_list.md @@ -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 @@ -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) diff --git a/docs/commands/lagoon_list_backups.md b/docs/commands/lagoon_list_backups.md index 962e9c92..6a209b04 100644 --- a/docs/commands/lagoon_list_backups.md +++ b/docs/commands/lagoon_list_backups.md @@ -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 diff --git a/docs/commands/lagoon_list_deployments.md b/docs/commands/lagoon_list_deployments.md index 6175372a..25a09aff 100644 --- a/docs/commands/lagoon_list_deployments.md +++ b/docs/commands/lagoon_list_deployments.md @@ -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 diff --git a/docs/commands/lagoon_list_deploytarget-configs.md b/docs/commands/lagoon_list_deploytarget-configs.md index d3806da4..723d714e 100644 --- a/docs/commands/lagoon_list_deploytarget-configs.md +++ b/docs/commands/lagoon_list_deploytarget-configs.md @@ -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 diff --git a/docs/commands/lagoon_list_deploytargets.md b/docs/commands/lagoon_list_deploytargets.md index eb899903..3791e812 100644 --- a/docs/commands/lagoon_list_deploytargets.md +++ b/docs/commands/lagoon_list_deploytargets.md @@ -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 diff --git a/docs/commands/lagoon_list_environments.md b/docs/commands/lagoon_list_environments.md index 504151f2..5186199d 100644 --- a/docs/commands/lagoon_list_environments.md +++ b/docs/commands/lagoon_list_environments.md @@ -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 diff --git a/docs/commands/lagoon_list_group-projects.md b/docs/commands/lagoon_list_group-projects.md index a1213b98..803d32db 100644 --- a/docs/commands/lagoon_list_group-projects.md +++ b/docs/commands/lagoon_list_group-projects.md @@ -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 diff --git a/docs/commands/lagoon_list_groups.md b/docs/commands/lagoon_list_groups.md index 40f5cf53..cad64322 100644 --- a/docs/commands/lagoon_list_groups.md +++ b/docs/commands/lagoon_list_groups.md @@ -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 diff --git a/docs/commands/lagoon_list_invokable-tasks.md b/docs/commands/lagoon_list_invokable-tasks.md index 0c27bef6..77e92550 100644 --- a/docs/commands/lagoon_list_invokable-tasks.md +++ b/docs/commands/lagoon_list_invokable-tasks.md @@ -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 diff --git a/docs/commands/lagoon_list_notification.md b/docs/commands/lagoon_list_notification.md index 5b4f86b5..f89a4300 100644 --- a/docs/commands/lagoon_list_notification.md +++ b/docs/commands/lagoon_list_notification.md @@ -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) diff --git a/docs/commands/lagoon_list_project-groups.md b/docs/commands/lagoon_list_project-groups.md new file mode 100644 index 00000000..9bfb2d13 --- /dev/null +++ b/docs/commands/lagoon_list_project-groups.md @@ -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 + diff --git a/docs/commands/lagoon_list_projects-by-metadata.md b/docs/commands/lagoon_list_projects-by-metadata.md index ca245d5e..981142ac 100644 --- a/docs/commands/lagoon_list_projects-by-metadata.md +++ b/docs/commands/lagoon_list_projects-by-metadata.md @@ -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 diff --git a/docs/commands/lagoon_list_projects.md b/docs/commands/lagoon_list_projects.md index 7b9fa690..ba3b8559 100644 --- a/docs/commands/lagoon_list_projects.md +++ b/docs/commands/lagoon_list_projects.md @@ -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 diff --git a/docs/commands/lagoon_list_tasks.md b/docs/commands/lagoon_list_tasks.md index 6d3aac8c..11e2fe80 100644 --- a/docs/commands/lagoon_list_tasks.md +++ b/docs/commands/lagoon_list_tasks.md @@ -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 diff --git a/docs/commands/lagoon_list_users.md b/docs/commands/lagoon_list_users.md index 7a22d8d7..7988ae11 100644 --- a/docs/commands/lagoon_list_users.md +++ b/docs/commands/lagoon_list_users.md @@ -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 diff --git a/docs/commands/lagoon_list_variables.md b/docs/commands/lagoon_list_variables.md index a4c01425..59f6eed4 100644 --- a/docs/commands/lagoon_list_variables.md +++ b/docs/commands/lagoon_list_variables.md @@ -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 diff --git a/internal/lagoon/client/lgraphql/lgraphql.go b/internal/lagoon/client/lgraphql/lgraphql.go index f246b0f1..5c965f9e 100644 --- a/internal/lagoon/client/lgraphql/lgraphql.go +++ b/internal/lagoon/client/lgraphql/lgraphql.go @@ -1432,11 +1432,13 @@ var _bindata = map[string]func() (*asset, error){ // directory embedded in the file by go-bindata. // For example if you run go-bindata on data/... and data contains the // following hierarchy: -// data/ -// foo.txt -// img/ -// a.png -// b.png +// +// data/ +// foo.txt +// img/ +// a.png +// b.png +// // then AssetDir("data") would return []string{"foo.txt", "img"} // AssetDir("data/img") would return []string{"a.png", "b.png"} // AssetDir("foo.txt") and AssetDir("notexist") would return an error