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

Change: Moves AddOrganizationCmd from a subcommand to the top level for Organization #324

Closed
wants to merge 3 commits into from
Closed
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
89 changes: 88 additions & 1 deletion cmd/add.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package cmd

import (
"context"
"fmt"

"github.com/spf13/cobra"
"github.com/uselagoon/lagoon-cli/pkg/output"
lclient "github.com/uselagoon/machinery/api/lagoon/client"
s "github.com/uselagoon/machinery/api/schema"
)

var addCmd = &cobra.Command{
Expand All @@ -25,10 +31,82 @@ var addNotificationCmd = &cobra.Command{
var addOrganizationCmd = &cobra.Command{
Use: "organization",
Aliases: []string{"o"},
Short: "Add an organization, or add a group/project to an organization",
Short: "Add an organization, or add a deploytarget/group/project/user to an organization",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
validateToken(lagoonCLIConfig.Current) // get a new token if the current one is invalid
},
RunE: func(cmd *cobra.Command, args []string) error {
debug, err := cmd.Flags().GetBool("debug")
if err != nil {
return err
}
organizationName, err := cmd.Flags().GetString("name")
if err != nil {
return err
}
if err := requiredInputCheck("Organization name", organizationName); err != nil {
return fmt.Errorf("%v | Additional subcommands for deploytarget, group, project & user are available. --help for more information", err)
}
organizationFriendlyName, err := cmd.Flags().GetString("friendly-name")
if err != nil {
return err
}
organizationDescription, err := cmd.Flags().GetString("description")
if err != nil {
return err
}
organizationQuotaProject, err := cmd.Flags().GetInt("project-quota")
if err != nil {
return err
}
organizationQuotaGroup, err := cmd.Flags().GetInt("group-quota")
if err != nil {
return err
}
organizationQuotaNotification, err := cmd.Flags().GetInt("notification-quota")
if err != nil {
return err
}
organizationQuotaEnvironment, err := cmd.Flags().GetInt("environment-quota")
if err != nil {
return err
}
organizationQuotaRoute, err := cmd.Flags().GetInt("route-quota")
if err != nil {
return err
}

current := lagoonCLIConfig.Current
token := lagoonCLIConfig.Lagoons[current].Token
lc := lclient.New(
lagoonCLIConfig.Lagoons[current].GraphQL,
lagoonCLIVersion,
&token,
debug)

organizationInput := s.AddOrganizationInput{
Name: organizationName,
FriendlyName: organizationFriendlyName,
Description: organizationDescription,
QuotaProject: organizationQuotaProject,
QuotaGroup: organizationQuotaGroup,
QuotaNotification: organizationQuotaNotification,
QuotaEnvironment: organizationQuotaEnvironment,
QuotaRoute: organizationQuotaRoute,
}
org := s.Organization{}
err = lc.AddOrganization(context.TODO(), &organizationInput, &org)
handleError(err)

resultData := output.Result{
Result: "success",
ResultData: map[string]interface{}{
"Organization Name": organizationName,
},
}
output.RenderResult(resultData, outputOptions)
return nil
},
}

func init() {
Expand All @@ -43,4 +121,13 @@ func init() {
addCmd.AddCommand(addUserSSHKeyCmd)
addCmd.AddCommand(addVariableCmd)
addCmd.AddCommand(addDeployTargetConfigCmd)

addOrganizationCmd.Flags().StringP("name", "O", "", "Name of the organization")
addOrganizationCmd.Flags().String("friendly-name", "", "Friendly name of the organization")
addOrganizationCmd.Flags().String("description", "", "Description of the organization")
addOrganizationCmd.Flags().Int("project-quota", 0, "Project quota for the organization")
addOrganizationCmd.Flags().Int("group-quota", 0, "Group quota for the organization")
addOrganizationCmd.Flags().Int("notification-quota", 0, "Notification quota for the organization")
addOrganizationCmd.Flags().Int("environment-quota", 0, "Environment quota for the organization")
addOrganizationCmd.Flags().Int("route-quota", 0, "Route quota for the organization")
}
91 changes: 0 additions & 91 deletions cmd/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,87 +10,6 @@ import (
s "github.com/uselagoon/machinery/api/schema"
)

var addOrgCmd = &cobra.Command{
Use: "organization",
Aliases: []string{"o"},
Short: "Add a new organization to Lagoon",
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
}
organizationName, err := cmd.Flags().GetString("name")
if err != nil {
return err
}
if err := requiredInputCheck("Organization name", organizationName); err != nil {
return err
}
organizationFriendlyName, err := cmd.Flags().GetString("friendly-name")
if err != nil {
return err
}
organizationDescription, err := cmd.Flags().GetString("description")
if err != nil {
return err
}
organizationQuotaProject, err := cmd.Flags().GetInt("project-quota")
if err != nil {
return err
}
organizationQuotaGroup, err := cmd.Flags().GetInt("group-quota")
if err != nil {
return err
}
organizationQuotaNotification, err := cmd.Flags().GetInt("notification-quota")
if err != nil {
return err
}
organizationQuotaEnvironment, err := cmd.Flags().GetInt("environment-quota")
if err != nil {
return err
}
organizationQuotaRoute, err := cmd.Flags().GetInt("route-quota")
if err != nil {
return err
}

current := lagoonCLIConfig.Current
token := lagoonCLIConfig.Lagoons[current].Token
lc := lclient.New(
lagoonCLIConfig.Lagoons[current].GraphQL,
lagoonCLIVersion,
&token,
debug)

organizationInput := s.AddOrganizationInput{
Name: organizationName,
FriendlyName: organizationFriendlyName,
Description: organizationDescription,
QuotaProject: organizationQuotaProject,
QuotaGroup: organizationQuotaGroup,
QuotaNotification: organizationQuotaNotification,
QuotaEnvironment: organizationQuotaEnvironment,
QuotaRoute: organizationQuotaRoute,
}
org := s.Organization{}
err = lc.AddOrganization(context.TODO(), &organizationInput, &org)
handleError(err)

resultData := output.Result{
Result: "success",
ResultData: map[string]interface{}{
"Organization Name": organizationName,
},
}
output.RenderResult(resultData, outputOptions)
return nil
},
}

var deleteOrgCmd = &cobra.Command{
Use: "organization",
Aliases: []string{"o"},
Expand Down Expand Up @@ -217,7 +136,6 @@ var updateOrganizationCmd = &cobra.Command{
}

func init() {
addOrganizationCmd.AddCommand(addOrgCmd)
addOrganizationCmd.AddCommand(addGroupToOrganizationCmd)
addOrganizationCmd.AddCommand(addProjectToOrganizationCmd)
addOrganizationCmd.AddCommand(addDeployTargetToOrganizationCmd)
Expand All @@ -228,15 +146,6 @@ func init() {
deleteOrganizationCmd.AddCommand(RemoveProjectFromOrganizationCmd)
deleteOrganizationCmd.AddCommand(RemoveUserFromOrganization)

addOrgCmd.Flags().StringP("name", "O", "", "Name of the organization")
addOrgCmd.Flags().String("friendly-name", "", "Friendly name of the organization")
addOrgCmd.Flags().String("description", "", "Description of the organization")
addOrgCmd.Flags().Int("project-quota", 0, "Project quota for the organization")
addOrgCmd.Flags().Int("group-quota", 0, "Group quota for the organization")
addOrgCmd.Flags().Int("notification-quota", 0, "Notification quota for the organization")
addOrgCmd.Flags().Int("environment-quota", 0, "Environment quota for the organization")
addOrgCmd.Flags().Int("route-quota", 0, "Route quota for the organization")

updateOrganizationCmd.Flags().StringP("name", "O", "", "Name of the organization to update")
updateOrganizationCmd.Flags().String("friendly-name", "", "Friendly name of the organization")
updateOrganizationCmd.Flags().String("description", "", "Description of the organization")
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/lagoon_add.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Add a project, or add notifications and variables to projects or environments
* [lagoon add deploytarget-config](lagoon_add_deploytarget-config.md) - Add deploytarget config to a project
* [lagoon add group](lagoon_add_group.md) - Add a group to lagoon
* [lagoon add notification](lagoon_add_notification.md) - Add notifications or add notifications to projects
* [lagoon add organization](lagoon_add_organization.md) - Add an organization, or add a group/project to an organization
* [lagoon add organization](lagoon_add_organization.md) - Add an organization, or add a deploytarget/group/project/user to an organization
* [lagoon add project](lagoon_add_project.md) - Add a new project to Lagoon
* [lagoon add project-group](lagoon_add_project-group.md) - Add a project to a group in lagoon
* [lagoon add user](lagoon_add_user.md) - Add a user to lagoon
Expand Down
17 changes: 14 additions & 3 deletions docs/commands/lagoon_add_organization.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
## lagoon add organization

Add an organization, or add a group/project to an organization
Add an organization, or add a deploytarget/group/project/user to an organization

```
lagoon add organization [flags]
```

### Options

```
-h, --help help for organization
--description string Description of the organization
--environment-quota int Environment quota for the organization
--friendly-name string Friendly name of the organization
--group-quota int Group quota for the organization
-h, --help help for organization
-O, --name string Name of the organization
--notification-quota int Notification quota for the organization
--project-quota int Project quota for the organization
--route-quota int Route quota for the organization
```

### Options inherited from parent commands
Expand All @@ -30,7 +42,6 @@ Add an organization, or add a group/project to an organization
* [lagoon add](lagoon_add.md) - Add a project, or add notifications and variables to projects or environments
* [lagoon add organization deploytarget](lagoon_add_organization_deploytarget.md) - Add a deploy target to an Organization
* [lagoon add organization group](lagoon_add_organization_group.md) - Add a group to an Organization
* [lagoon add organization organization](lagoon_add_organization_organization.md) - Add a new organization to Lagoon
* [lagoon add organization project](lagoon_add_organization_project.md) - Add a project to an Organization
* [lagoon add organization user](lagoon_add_organization_user.md) - Add a user to an Organization

2 changes: 1 addition & 1 deletion docs/commands/lagoon_add_organization_deploytarget.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ lagoon add organization deploytarget [flags]

### SEE ALSO

* [lagoon add organization](lagoon_add_organization.md) - Add an organization, or add a group/project to an organization
* [lagoon add organization](lagoon_add_organization.md) - Add an organization, or add a deploytarget/group/project/user to an organization

2 changes: 1 addition & 1 deletion docs/commands/lagoon_add_organization_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ lagoon add organization group [flags]

### SEE ALSO

* [lagoon add organization](lagoon_add_organization.md) - Add an organization, or add a group/project to an organization
* [lagoon add organization](lagoon_add_organization.md) - Add an organization, or add a deploytarget/group/project/user to an organization

2 changes: 1 addition & 1 deletion docs/commands/lagoon_add_organization_project.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ lagoon add organization project [flags]

### SEE ALSO

* [lagoon add organization](lagoon_add_organization.md) - Add an organization, or add a group/project to an organization
* [lagoon add organization](lagoon_add_organization.md) - Add an organization, or add a deploytarget/group/project/user to an organization

2 changes: 1 addition & 1 deletion docs/commands/lagoon_add_organization_user.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ lagoon add organization user [flags]

### SEE ALSO

* [lagoon add organization](lagoon_add_organization.md) - Add an organization, or add a group/project to an organization
* [lagoon add organization](lagoon_add_organization.md) - Add an organization, or add a deploytarget/group/project/user to an organization

Loading