From e568a88764d883b7717531571c93039298fbc3c6 Mon Sep 17 00:00:00 2001 From: cgoodwin90 Date: Fri, 22 Mar 2024 18:34:13 +1100 Subject: [PATCH 1/9] Initial commit --- cmd/add.go | 19 ++-- cmd/delete.go | 11 +- cmd/deploytarget.go | 8 +- cmd/organization.go | 36 +++--- cmd/project.go | 260 +++++++++++++++++++++++++++++++++----------- cmd/shared.go | 12 +- cmd/users.go | 28 ++--- 7 files changed, 253 insertions(+), 121 deletions(-) diff --git a/cmd/add.go b/cmd/add.go index 6ea38fef..6922daea 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -22,14 +22,14 @@ 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", - PersistentPreRun: func(cmd *cobra.Command, args []string) { - validateToken(lagoonCLIConfig.Current) // get a new token if the current one is invalid - }, -} +//var addOrganizationCmd = &cobra.Command{ +// Use: "organization", +// Aliases: []string{"o"}, +// Short: "Add an organization, or add a group/project to an organization", +// PersistentPreRun: func(cmd *cobra.Command, args []string) { +// validateToken(lagoonCLIConfig.Current) // get a new token if the current one is invalid +// }, +//} func init() { addCmd.AddCommand(addDeployTargetCmd) @@ -43,4 +43,7 @@ func init() { addCmd.AddCommand(addUserSSHKeyCmd) addCmd.AddCommand(addVariableCmd) addCmd.AddCommand(addDeployTargetConfigCmd) + addCmd.AddCommand(addDeployTargetToOrganizationCmd) + addCmd.AddCommand(addAdministratorToOrganizationCmd) + addCmd.AddCommand(addProjectToOrganizationCmd) } diff --git a/cmd/delete.go b/cmd/delete.go index d2e07788..e404c8fd 100644 --- a/cmd/delete.go +++ b/cmd/delete.go @@ -22,15 +22,6 @@ var deleteNotificationCmd = &cobra.Command{ }, } -var deleteOrganizationCmd = &cobra.Command{ - Use: "organization", - Aliases: []string{"o"}, - Short: "Add an organization, or add a group/project to an organization", - PersistentPreRun: func(cmd *cobra.Command, args []string) { - validateToken(lagoonCLIConfig.Current) // get a new token if the current one is invalid - }, -} - func init() { deleteCmd.AddCommand(deleteEnvCmd) deleteCmd.AddCommand(deleteGroupCmd) @@ -44,4 +35,6 @@ func init() { deleteCmd.AddCommand(deleteVariableCmd) deleteCmd.AddCommand(deleteDeployTargetConfigCmd) deleteCmd.AddCommand(deleteOrganizationCmd) + deleteCmd.AddCommand(RemoveDeployTargetFromOrganizationCmd) + deleteCmd.AddCommand(RemoveAdministratorFromOrganizationCmd) } diff --git a/cmd/deploytarget.go b/cmd/deploytarget.go index e1025b33..d3368fd1 100644 --- a/cmd/deploytarget.go +++ b/cmd/deploytarget.go @@ -323,8 +323,8 @@ var deleteDeployTargetCmd = &cobra.Command{ } var addDeployTargetToOrganizationCmd = &cobra.Command{ - Use: "deploytarget", - Aliases: []string{"dt"}, + Use: "organization-deploytarget", + Aliases: []string{"org-dt"}, Short: "Add a deploy target to an Organization", PreRunE: func(_ *cobra.Command, _ []string) error { return validateTokenE(lagoonCLIConfig.Current) @@ -380,8 +380,8 @@ var addDeployTargetToOrganizationCmd = &cobra.Command{ } var RemoveDeployTargetFromOrganizationCmd = &cobra.Command{ - Use: "deploytarget", - Aliases: []string{"dt"}, + Use: "organization-deploytarget", + Aliases: []string{"org-dt"}, Short: "Remove a deploy target from an Organization", PreRunE: func(_ *cobra.Command, _ []string) error { return validateTokenE(lagoonCLIConfig.Current) diff --git a/cmd/organization.go b/cmd/organization.go index 4ca36b13..a611a3e5 100644 --- a/cmd/organization.go +++ b/cmd/organization.go @@ -10,7 +10,7 @@ import ( s "github.com/uselagoon/machinery/api/schema" ) -var addOrgCmd = &cobra.Command{ +var addOrganizationCmd = &cobra.Command{ Use: "organization", Aliases: []string{"o"}, Short: "Add a new organization to Lagoon", @@ -91,7 +91,7 @@ var addOrgCmd = &cobra.Command{ }, } -var deleteOrgCmd = &cobra.Command{ +var deleteOrganizationCmd = &cobra.Command{ Use: "organization", Aliases: []string{"o"}, Short: "Delete an organization", @@ -217,25 +217,25 @@ var updateOrganizationCmd = &cobra.Command{ } func init() { - addOrganizationCmd.AddCommand(addOrgCmd) + //addOrganizationCmd.AddCommand(addOrgCmd) addOrganizationCmd.AddCommand(addGroupToOrganizationCmd) - addOrganizationCmd.AddCommand(addProjectToOrganizationCmd) - addOrganizationCmd.AddCommand(addDeployTargetToOrganizationCmd) - addOrganizationCmd.AddCommand(addUserToOrganizationCmd) + //addOrganizationCmd.AddCommand(addProjectToOrganizationCmd) + //addOrganizationCmd.AddCommand(addDeployTargetToOrganizationCmd) + //addOrganizationCmd.AddCommand(addUserToOrganizationCmd) - deleteOrganizationCmd.AddCommand(deleteOrgCmd) - deleteOrganizationCmd.AddCommand(RemoveDeployTargetFromOrganizationCmd) + //deleteOrganizationCmd.AddCommand(deleteOrgCmd) + //deleteOrganizationCmd.AddCommand(RemoveDeployTargetFromOrganizationCmd) deleteOrganizationCmd.AddCommand(RemoveProjectFromOrganizationCmd) - deleteOrganizationCmd.AddCommand(RemoveUserFromOrganization) + //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") + 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") updateOrganizationCmd.Flags().StringP("name", "O", "", "Name of the organization to update") updateOrganizationCmd.Flags().String("friendly-name", "", "Friendly name of the organization") @@ -246,5 +246,5 @@ func init() { updateOrganizationCmd.Flags().Int("environment-quota", 0, "Environment quota for the organization") updateOrganizationCmd.Flags().Int("route-quota", 0, "Route quota for the organization") - deleteOrgCmd.Flags().StringP("name", "O", "", "Name of the organization to delete") + deleteOrganizationCmd.Flags().StringP("name", "O", "", "Name of the organization to delete") } diff --git a/cmd/project.go b/cmd/project.go index 1819b3af..1c475200 100644 --- a/cmd/project.go +++ b/cmd/project.go @@ -62,37 +62,167 @@ var deleteProjectCmd = &cobra.Command{ }, } +//var addProjectCmd = &cobra.Command{ +// Use: "project", +// Aliases: []string{"p"}, +// Short: "Add a new project to Lagoon", +// Run: func(cmd *cobra.Command, args []string) { +// projectFlags := parseProjectFlags(*cmd.Flags()) +// if cmdProjectName == "" { +// fmt.Println("Missing arguments: Project name is not defined") +// cmd.Help() +// os.Exit(1) +// } +// +// jsonPatch, _ := json.Marshal(projectFlags) +// addResult, err := pClient.AddProject(cmdProjectName, string(jsonPatch)) +// handleError(err) +// var addedProject api.Project +// err = json.Unmarshal([]byte(addResult), &addedProject) +// handleError(err) +// +// if err != nil { +// output.RenderError(err.Error(), outputOptions) +// } else { +// resultData := output.Result{ +// Result: "success", +// ResultData: map[string]interface{}{ +// "Project Name": addedProject.Name, +// "GitURL": addedProject.GitURL, +// }, +// } +// output.RenderResult(resultData, outputOptions) +// } +// }, +//} + var addProjectCmd = &cobra.Command{ Use: "project", Aliases: []string{"p"}, Short: "Add a new project to Lagoon", - Run: func(cmd *cobra.Command, args []string) { - projectFlags := parseProjectFlags(*cmd.Flags()) - if cmdProjectName == "" { - fmt.Println("Missing arguments: Project name is not defined") - cmd.Help() - os.Exit(1) - } - - jsonPatch, _ := json.Marshal(projectFlags) - addResult, err := pClient.AddProject(cmdProjectName, string(jsonPatch)) - handleError(err) - var addedProject api.Project - err = json.Unmarshal([]byte(addResult), &addedProject) + PreRunE: func(_ *cobra.Command, _ []string) error { + return validateTokenE(lagoonCLIConfig.Current) + }, + RunE: func(cmd *cobra.Command, args []string) error { + debug, err := cmd.Flags().GetBool("debug") handleError(err) + organizationName, err := cmd.Flags().GetString("org-name") if err != nil { - output.RenderError(err.Error(), outputOptions) - } else { - resultData := output.Result{ - Result: "success", - ResultData: map[string]interface{}{ - "Project Name": addedProject.Name, - "GitURL": addedProject.GitURL, - }, - } - output.RenderResult(resultData, outputOptions) + return err + } + gitUrl, err := cmd.Flags().GetString("gitUrl") + if err != nil { + return err + } + productionEnvironment, err := cmd.Flags().GetString("productionEnvironment") + if err != nil { + return err + } + openshift, err := cmd.Flags().GetUint("openshift") + if err != nil { + return err + } + standbyProductionEnvironment, err := cmd.Flags().GetString("standbyProductionEnvironment") + if err != nil { + return err + } + branches, err := cmd.Flags().GetString("branches") + if err != nil { + return err + } + pullrequests, err := cmd.Flags().GetString("pullrequests") + if err != nil { + return err + } + openshiftProjectPattern, err := cmd.Flags().GetString("openshiftProjectPattern") + if err != nil { + return err + } + developmentEnvironmentsLimit, err := cmd.Flags().GetUint("developmentEnvironmentsLimit") + if err != nil { + return err + } + storageCalc, err := cmd.Flags().GetUint("storageCalc") + if err != nil { + return err + } + autoIdle, err := cmd.Flags().GetUint("autoIdle") + if err != nil { + return err + } + subfolder, err := cmd.Flags().GetString("subfolder") + if err != nil { + return err + } + privateKey, err := cmd.Flags().GetString("privateKey") + if err != nil { + return err + } + orgOwner, err := cmd.Flags().GetBool("org-owner") + if err != nil { + return err } + routerPattern, err := cmd.Flags().GetString("routerPattern") + if err != nil { + return err + } + //json, err := cmd.Flags().GetString("json") + //if err != nil { + // return err + //} + + if err := requiredInputCheck("Project name", cmdProjectName, "GitURL", gitUrl, "Production environment", productionEnvironment, "Openshift", strconv.Itoa(int(openshift))); err != nil { + return err + } + + current := lagoonCLIConfig.Current + token := lagoonCLIConfig.Lagoons[current].Token + lc := lclient.New( + lagoonCLIConfig.Lagoons[current].GraphQL, + lagoonCLIVersion, + &token, + debug) + + projectInput := s.AddProjectInput{ + Name: cmdProjectName, + AddOrgOwner: orgOwner, + GitURL: gitUrl, + ProductionEnvironment: productionEnvironment, + StandbyProductionEnvironment: standbyProductionEnvironment, + Branches: branches, + PullRequests: pullrequests, + OpenshiftProjectPattern: openshiftProjectPattern, + Openshift: openshift, + DevelopmentEnvironmentsLimit: developmentEnvironmentsLimit, + StorageCalc: storageCalc, + AutoIdle: autoIdle, + Subfolder: subfolder, + PrivateKey: privateKey, + RouterPattern: routerPattern, + } + + if organizationName != "" { + organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc) + handleError(err) + projectInput.Organization = organization.ID + } + + project := s.Project{} + err = lc.AddProject(context.TODO(), &projectInput, &project) + handleError(err) + resultData := output.Result{ + Result: "success", + ResultData: map[string]interface{}{ + "Project Name": project.Name, + "GitURL": gitUrl, + }, + } + if organizationName != "" { + resultData.ResultData["Organization"] = organizationName + } + output.RenderResult(resultData, outputOptions) + return nil }, } @@ -368,8 +498,8 @@ var deleteProjectMetadataByKey = &cobra.Command{ } var addProjectToOrganizationCmd = &cobra.Command{ - Use: "project", - Aliases: []string{"p"}, + Use: "organization-project", + Aliases: []string{"op"}, Short: "Add a project to an Organization", PreRunE: func(_ *cobra.Command, _ []string) error { return validateTokenE(lagoonCLIConfig.Current) @@ -614,22 +744,24 @@ func init() { updateProjectCmd.Flags().IntVarP(&factsUi, "factsUi", "", 0, "Enables the Lagoon insights Facts tab in the UI. Set to 1 to enable, 0 to disable") updateProjectCmd.Flags().IntVarP(&problemsUi, "problemsUi", "", 0, "Enables the Lagoon insights Problems tab in the UI. Set to 1 to enable, 0 to disable") - addProjectCmd.Flags().StringVarP(&jsonPatch, "json", "j", "", "JSON string to patch") - - addProjectCmd.Flags().StringVarP(&projectPatch.GitURL, "gitUrl", "g", "", "GitURL of the project") - addProjectCmd.Flags().StringVarP(&projectPatch.PrivateKey, "privateKey", "I", "", "Private key to use for the project") - addProjectCmd.Flags().StringVarP(&projectPatch.Subfolder, "subfolder", "s", "", "Set if the .lagoon.yml should be found in a subfolder useful if you have multiple Lagoon projects per Git Repository") - addProjectCmd.Flags().StringVarP(&projectPatch.RouterPattern, "routerPattern", "Z", "", "Router pattern of the project, e.g. '${service}-${environment}-${project}.lagoon.example.com'") - addProjectCmd.Flags().StringVarP(&projectPatch.Branches, "branches", "b", "", "Which branches should be deployed") - addProjectCmd.Flags().StringVarP(&projectPatch.Pullrequests, "pullrequests", "m", "", "Which Pull Requests should be deployed") - addProjectCmd.Flags().StringVarP(&projectPatch.ProductionEnvironment, "productionEnvironment", "E", "", "Which environment(the name) should be marked as the production environment") - addProjectCmd.Flags().StringVar(&projectPatch.StandbyProductionEnvironment, "standbyProductionEnvironment", "", "Which environment(the name) should be marked as the standby production environment") - addProjectCmd.Flags().StringVarP(&projectPatch.OpenshiftProjectPattern, "openshiftProjectPattern", "o", "", "Pattern of OpenShift Project/Namespace that should be generated") - - addProjectCmd.Flags().IntVarP(&projectAutoIdle, "autoIdle", "a", 0, "Auto idle setting of the project") - addProjectCmd.Flags().IntVarP(&projectStorageCalc, "storageCalc", "C", 0, "Should storage for this environment be calculated") - addProjectCmd.Flags().IntVarP(&projectDevelopmentEnvironmentsLimit, "developmentEnvironmentsLimit", "L", 0, "How many environments can be deployed at one time") - addProjectCmd.Flags().IntVarP(&projectOpenshift, "openshift", "S", 0, "Reference to OpenShift Object this Project should be deployed to") + addProjectCmd.Flags().StringP("json", "j", "", "JSON string to patch") + + addProjectCmd.Flags().StringP("gitUrl", "g", "", "GitURL of the project") + addProjectCmd.Flags().StringP("privateKey", "I", "", "Private key to use for the project") + addProjectCmd.Flags().StringP("subfolder", "s", "", "Set if the .lagoon.yml should be found in a subfolder useful if you have multiple Lagoon projects per Git Repository") + addProjectCmd.Flags().StringP("routerPattern", "Z", "", "Router pattern of the project, e.g. '${service}-${environment}-${project}.lagoon.example.com'") + addProjectCmd.Flags().StringP("branches", "b", "", "Which branches should be deployed") + addProjectCmd.Flags().StringP("pullrequests", "m", "", "Which Pull Requests should be deployed") + addProjectCmd.Flags().StringP("productionEnvironment", "E", "", "Which environment(the name) should be marked as the production environment") + addProjectCmd.Flags().String("standbyProductionEnvironment", "", "Which environment(the name) should be marked as the standby production environment") + addProjectCmd.Flags().StringP("openshiftProjectPattern", "o", "", "Pattern of OpenShift Project/Namespace that should be generated") + + addProjectCmd.Flags().UintP("autoIdle", "a", 0, "Auto idle setting of the project") + addProjectCmd.Flags().UintP("storageCalc", "C", 0, "Should storage for this environment be calculated") + addProjectCmd.Flags().UintP("developmentEnvironmentsLimit", "L", 0, "How many environments can be deployed at one time") + addProjectCmd.Flags().UintP("openshift", "S", 0, "Reference to OpenShift Object this Project should be deployed to") + addProjectCmd.Flags().Bool("org-owner", false, "Add the user as an owner of the project") + addProjectCmd.Flags().StringP("org-name", "O", "", "Name of the Organization to add the project to") listCmd.AddCommand(listProjectByMetadata) listProjectByMetadata.Flags().StringP("key", "K", "", "The key name of the metadata value you are querying on") @@ -645,30 +777,28 @@ func init() { getCmd.AddCommand(getProjectMetadata) - addProjectToOrganizationCmd.Flags().String("build-image", "", "Build Image for the project") - addProjectToOrganizationCmd.Flags().String("availability", "", "Availability of the project") - addProjectToOrganizationCmd.Flags().String("git-url", "", "GitURL of the project") - addProjectToOrganizationCmd.Flags().String("production-environment", "", "Production Environment for the project") - addProjectToOrganizationCmd.Flags().String("standby-production-environment", "", "Standby Production Environment for the project") - addProjectToOrganizationCmd.Flags().String("subfolder", "", "Set if the .lagoon.yml should be found in a subfolder useful if you have multiple Lagoon projects per Git Repository") - addProjectToOrganizationCmd.Flags().String("private-key", "", "Private key to use for the project") - addProjectToOrganizationCmd.Flags().String("branches", "", "branches") - addProjectToOrganizationCmd.Flags().String("pullrequests", "", "Which Pull Requests should be deployed") - addProjectToOrganizationCmd.Flags().StringP("name", "O", "", "Name of the Organization to add the project to") - addProjectToOrganizationCmd.Flags().String("openshift-project-pattern", "", "Pattern of OpenShift Project/Namespace that should be generated") - addProjectToOrganizationCmd.Flags().String("router-pattern", "", "Router pattern of the project, e.g. '${service}-${environment}-${project}.lagoon.example.com'") - - addProjectToOrganizationCmd.Flags().Uint("openshift", 0, "Reference to OpenShift Object this Project should be deployed to") - addProjectToOrganizationCmd.Flags().Uint("auto-idle", 0, "Auto idle setting of the project") - addProjectToOrganizationCmd.Flags().Uint("storage-calc", 0, "Should storage for this environment be calculated") - addProjectToOrganizationCmd.Flags().Uint("development-environments-limit", 0, "How many environments can be deployed at one time") - addProjectToOrganizationCmd.Flags().Uint("facts-ui", 0, "Enables the Lagoon insights Facts tab in the UI. Set to 1 to enable, 0 to disable") - addProjectToOrganizationCmd.Flags().Uint("problems-ui", 0, "Enables the Lagoon insights Problems tab in the UI. Set to 1 to enable, 0 to disable") - addProjectToOrganizationCmd.Flags().Uint("deployments-disabled", 0, "Admin only flag for disabling deployments on a project, 1 to disable deployments, 0 to enable") - addProjectToOrganizationCmd.Flags().Uint("production-build-priority", 0, "Set the priority of the production build") - addProjectToOrganizationCmd.Flags().Uint("development-build-priority", 0, "Set the priority of the development build") - - addProjectToOrganizationCmd.Flags().Bool("org-owner", false, "Add the user as an owner of the project") + //addProjectToOrganizationCmd.Flags().String("build-image", "", "Build Image for the project") + //addProjectToOrganizationCmd.Flags().String("availability", "", "Availability of the project") + //addProjectToOrganizationCmd.Flags().String("git-url", "", "GitURL of the project") + //addProjectToOrganizationCmd.Flags().String("production-environment", "", "Production Environment for the project") + //addProjectToOrganizationCmd.Flags().String("standby-production-environment", "", "Standby Production Environment for the project") + //addProjectToOrganizationCmd.Flags().String("subfolder", "", "Set if the .lagoon.yml should be found in a subfolder useful if you have multiple Lagoon projects per Git Repository") + //addProjectToOrganizationCmd.Flags().String("private-key", "", "Private key to use for the project") + //addProjectToOrganizationCmd.Flags().String("branches", "", "branches") + //addProjectToOrganizationCmd.Flags().String("pullrequests", "", "Which Pull Requests should be deployed") + //addProjectToOrganizationCmd.Flags().StringP("name", "O", "", "Name of the Organization to add the project to") + //addProjectToOrganizationCmd.Flags().String("openshift-project-pattern", "", "Pattern of OpenShift Project/Namespace that should be generated") + //addProjectToOrganizationCmd.Flags().String("router-pattern", "", "Router pattern of the project, e.g. '${service}-${environment}-${project}.lagoon.example.com'") + // + //addProjectToOrganizationCmd.Flags().Uint("openshift", 0, "Reference to OpenShift Object this Project should be deployed to") + //addProjectToOrganizationCmd.Flags().Uint("auto-idle", 0, "Auto idle setting of the project") + //addProjectToOrganizationCmd.Flags().Uint("storage-calc", 0, "Should storage for this environment be calculated") + //addProjectToOrganizationCmd.Flags().Uint("development-environments-limit", 0, "How many environments can be deployed at one time") + //addProjectToOrganizationCmd.Flags().Uint("facts-ui", 0, "Enables the Lagoon insights Facts tab in the UI. Set to 1 to enable, 0 to disable") + //addProjectToOrganizationCmd.Flags().Uint("problems-ui", 0, "Enables the Lagoon insights Problems tab in the UI. Set to 1 to enable, 0 to disable") + //addProjectToOrganizationCmd.Flags().Uint("deployments-disabled", 0, "Admin only flag for disabling deployments on a project, 1 to disable deployments, 0 to enable") + //addProjectToOrganizationCmd.Flags().Uint("production-build-priority", 0, "Set the priority of the production build") + //addProjectToOrganizationCmd.Flags().Uint("development-build-priority", 0, "Set the priority of the development build") RemoveProjectFromOrganizationCmd.Flags().StringP("name", "O", "", "Name of the Organization to remove the project from") } diff --git a/cmd/shared.go b/cmd/shared.go index 7af150db..c605e51e 100644 --- a/cmd/shared.go +++ b/cmd/shared.go @@ -113,9 +113,15 @@ func nullIntCheck(i int) *int { return &i } -func requiredInputCheck(field string, value string) error { - if value == "" || value == "0" { - return fmt.Errorf(fmt.Sprintf("Missing argument: %s is not defined", field)) +// Specify the fields and values to check for required input e.g. requiredInputCheck("field1", value1, "field2", value2) +func requiredInputCheck(fieldsAndValues ...string) error { + for i := 0; i < len(fieldsAndValues); i += 2 { + field := fieldsAndValues[i] + value := fieldsAndValues[i+1] + + if value == "" || value == "0" { + return fmt.Errorf("Missing argument: %s is not defined", field) + } } return nil } diff --git a/cmd/users.go b/cmd/users.go index 4cdec7a4..e498cf7b 100644 --- a/cmd/users.go +++ b/cmd/users.go @@ -361,10 +361,10 @@ var getAllUserKeysCmd = &cobra.Command{ }, } -var addUserToOrganizationCmd = &cobra.Command{ - Use: "user", - Aliases: []string{"u"}, - Short: "Add a user to an Organization", +var addAdministratorToOrganizationCmd = &cobra.Command{ + Use: "organization-administrator", + Aliases: []string{"org-admin"}, + Short: "Add an administrator to an Organization", PreRunE: func(_ *cobra.Command, _ []string) error { return validateTokenE(lagoonCLIConfig.Current) }, @@ -424,10 +424,10 @@ var addUserToOrganizationCmd = &cobra.Command{ }, } -var RemoveUserFromOrganization = &cobra.Command{ - Use: "user", - Aliases: []string{"u"}, - Short: "Remove a user to an Organization", +var RemoveAdministratorFromOrganizationCmd = &cobra.Command{ + Use: "organization-administrator", + Aliases: []string{"org-admin"}, + Short: "Remove an administrator from an Organization", PreRunE: func(_ *cobra.Command, _ []string) error { return validateTokenE(lagoonCLIConfig.Current) }, @@ -510,10 +510,10 @@ func init() { updateUserCmd.Flags().StringVarP(¤tUserEmail, "current-email", "C", "", "Current email address of the user") getUserKeysCmd.Flags().StringP("email", "E", "", "New email address of the user") getAllUserKeysCmd.Flags().StringP("name", "N", "", "Name of the group to list users in (if not specified, will default to all groups)") - addUserToOrganizationCmd.Flags().StringP("name", "O", "", "Name of the organization") - addUserToOrganizationCmd.Flags().StringP("email", "E", "", "Email address of the user") - addUserToOrganizationCmd.Flags().Bool("owner", false, "Set the user as an owner of the organization") - RemoveUserFromOrganization.Flags().StringP("name", "O", "", "Name of the organization") - RemoveUserFromOrganization.Flags().StringP("email", "E", "", "Email address of the user") - RemoveUserFromOrganization.Flags().Bool("owner", false, "Set the user as an owner of the organization") + addAdministratorToOrganizationCmd.Flags().StringP("name", "O", "", "Name of the organization") + addAdministratorToOrganizationCmd.Flags().StringP("email", "E", "", "Email address of the user") + addAdministratorToOrganizationCmd.Flags().Bool("owner", false, "Set the user as an owner of the organization") + RemoveAdministratorFromOrganizationCmd.Flags().StringP("name", "O", "", "Name of the organization") + RemoveAdministratorFromOrganizationCmd.Flags().StringP("email", "E", "", "Email address of the user") + RemoveAdministratorFromOrganizationCmd.Flags().Bool("owner", false, "Set the user as an owner of the organization") } From c6a6d7cd0d631056fd5a5477088cb4b0de80b5bd Mon Sep 17 00:00:00 2001 From: cgoodwin90 Date: Mon, 25 Mar 2024 17:54:57 +1100 Subject: [PATCH 2/9] Restructures organization subcommands --- cmd/add.go | 10 -- cmd/delete.go | 1 + cmd/deploytarget.go | 12 +-- cmd/groups.go | 139 +++++++++++-------------- cmd/list.go | 59 +++++------ cmd/organization.go | 11 -- cmd/project.go | 245 ++------------------------------------------ cmd/users.go | 5 +- 8 files changed, 95 insertions(+), 387 deletions(-) diff --git a/cmd/add.go b/cmd/add.go index 6922daea..fd74a218 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -22,15 +22,6 @@ 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", -// PersistentPreRun: func(cmd *cobra.Command, args []string) { -// validateToken(lagoonCLIConfig.Current) // get a new token if the current one is invalid -// }, -//} - func init() { addCmd.AddCommand(addDeployTargetCmd) addCmd.AddCommand(addGroupCmd) @@ -45,5 +36,4 @@ func init() { addCmd.AddCommand(addDeployTargetConfigCmd) addCmd.AddCommand(addDeployTargetToOrganizationCmd) addCmd.AddCommand(addAdministratorToOrganizationCmd) - addCmd.AddCommand(addProjectToOrganizationCmd) } diff --git a/cmd/delete.go b/cmd/delete.go index e404c8fd..1c3a25a1 100644 --- a/cmd/delete.go +++ b/cmd/delete.go @@ -37,4 +37,5 @@ func init() { deleteCmd.AddCommand(deleteOrganizationCmd) deleteCmd.AddCommand(RemoveDeployTargetFromOrganizationCmd) deleteCmd.AddCommand(RemoveAdministratorFromOrganizationCmd) + deleteCmd.AddCommand(RemoveProjectFromOrganizationCmd) } diff --git a/cmd/deploytarget.go b/cmd/deploytarget.go index d3368fd1..d9146d85 100644 --- a/cmd/deploytarget.go +++ b/cmd/deploytarget.go @@ -332,19 +332,16 @@ var addDeployTargetToOrganizationCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { debug, err := cmd.Flags().GetBool("debug") handleError(err) - organizationName, err := cmd.Flags().GetString("name") if err != nil { return err } - if err := requiredInputCheck("Organization name", organizationName); err != nil { - return err - } deployTarget, err := cmd.Flags().GetUint("deploy-target") if err != nil { return err } - if err := requiredInputCheck("Deploy Target", strconv.Itoa(int(deployTarget))); err != nil { + + if err := requiredInputCheck("Organization name", organizationName, "Deploy Target", strconv.Itoa(int(deployTarget))); err != nil { return err } @@ -366,12 +363,11 @@ var addDeployTargetToOrganizationCmd = &cobra.Command{ deployTargetResponse, err := l.AddDeployTargetToOrganization(context.TODO(), &deployTargetInput, lc) handleError(err) - resultData := output.Result{ Result: "success", ResultData: map[string]interface{}{ - "Deploy Target": deployTargetResponse.Name, - "Organization Name": organizationName, + "Deploy Target": deployTarget, + "Organization Name": deployTargetResponse.Name, }, } output.RenderResult(resultData, outputOptions) diff --git a/cmd/groups.go b/cmd/groups.go index 1dedda77..cd07ec62 100644 --- a/cmd/groups.go +++ b/cmd/groups.go @@ -33,25 +33,65 @@ var addGroupCmd = &cobra.Command{ Use: "group", Aliases: []string{"g"}, Short: "Add a group to lagoon", - Run: func(cmd *cobra.Command, args []string) { - groupFlags := parseGroup(*cmd.Flags()) - if groupFlags.Name == "" { - fmt.Println("Missing arguments: Group name is not defined") - cmd.Help() - os.Exit(1) - } - var customReqResult []byte - var err error - customReqResult, err = uClient.AddGroup(groupFlags) - handleError(err) - returnResultData := map[string]interface{}{} - err = json.Unmarshal([]byte(customReqResult), &returnResultData) + PreRunE: func(_ *cobra.Command, _ []string) error { + return validateTokenE(lagoonCLIConfig.Current) + }, + RunE: func(cmd *cobra.Command, args []string) error { + debug, err := cmd.Flags().GetBool("debug") handleError(err) + groupName, err := cmd.Flags().GetString("name") + if err != nil { + return err + } + if err := requiredInputCheck("Group name", groupName); err != nil { + return err + } + orgOwner, err := cmd.Flags().GetBool("org-owner") + if err != nil { + return err + } + organizationName, err := cmd.Flags().GetString("organization") + if err != nil { + return err + } + + current := lagoonCLIConfig.Current + token := lagoonCLIConfig.Lagoons[current].Token + lc := lclient.New( + lagoonCLIConfig.Lagoons[current].GraphQL, + lagoonCLIVersion, + &token, + debug) + + if organizationName != "" { + organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc) + handleError(err) + groupInput := s.AddGroupToOrganizationInput{ + Name: groupName, + Organization: organization.ID, + AddOrgOwner: orgOwner, + } + _, err = l.AddGroupToOrganization(context.TODO(), &groupInput, lc) + handleError(err) + } else { + groupInput := s.AddGroupInput{ + Name: groupName, + } + _, err = l.AddGroup(context.TODO(), &groupInput, lc) + handleError(err) + } + resultData := output.Result{ - Result: "success", - ResultData: returnResultData, + Result: "success", + ResultData: map[string]interface{}{ + "Group Name": groupName, + }, + } + if organizationName != "" { + resultData.ResultData["Organization"] = organizationName } output.RenderResult(resultData, outputOptions) + return nil }, } @@ -232,69 +272,10 @@ var deleteGroupCmd = &cobra.Command{ }, } -var addGroupToOrganizationCmd = &cobra.Command{ - Use: "group", - Aliases: []string{"g"}, - Short: "Add a group to an Organization", - PreRunE: func(_ *cobra.Command, _ []string) error { - return validateTokenE(lagoonCLIConfig.Current) - }, - RunE: func(cmd *cobra.Command, args []string) error { - debug, err := cmd.Flags().GetBool("debug") - handleError(err) - orgOwner, err := cmd.Flags().GetBool("org-owner") - 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 - } - groupName, err := cmd.Flags().GetString("group") - if err != nil { - return err - } - if err := requiredInputCheck("Group name", groupName); err != nil { - return err - } - - current := lagoonCLIConfig.Current - token := lagoonCLIConfig.Lagoons[current].Token - lc := lclient.New( - lagoonCLIConfig.Lagoons[current].GraphQL, - lagoonCLIVersion, - &token, - debug) - - organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc) - handleError(err) - - groupInput := s.AddGroupToOrganizationInput{ - Name: groupName, - Organization: organization.ID, - AddOrgOwner: orgOwner, - } - group := s.OrgGroup{} - err = lc.AddGroupToOrganization(context.TODO(), &groupInput, &group) - handleError(err) - - resultData := output.Result{ - Result: "success", - ResultData: map[string]interface{}{ - "Group Name": group.Name, - "Organization Name": organizationName, - }, - } - output.RenderResult(resultData, outputOptions) - return nil - }, -} - func init() { - addGroupCmd.Flags().StringVarP(&groupName, "name", "N", "", "Name of the group") + addGroupCmd.Flags().StringP("name", "N", "", "Name of the group") + addGroupCmd.Flags().StringP("organization", "O", "", "Name of the organization") + addGroupCmd.Flags().Bool("org-owner", false, "Flag to add the user to the group as an owner") addUserToGroupCmd.Flags().StringVarP(&groupName, "name", "N", "", "Name of the group") addUserToGroupCmd.Flags().StringVarP(&groupRole, "role", "R", "", "Role in the group [owner, maintainer, developer, reporter, guest]") addUserToGroupCmd.Flags().StringVarP(&userEmail, "email", "E", "", "Email address of the user") @@ -303,7 +284,5 @@ func init() { deleteUserFromGroupCmd.Flags().StringVarP(&userEmail, "email", "E", "", "Email address of the user") deleteProjectFromGroupCmd.Flags().StringVarP(&groupName, "name", "N", "", "Name of the group") deleteGroupCmd.Flags().StringVarP(&groupName, "name", "N", "", "Name of the group") - addGroupToOrganizationCmd.Flags().StringP("name", "O", "", "Name of the organization") - addGroupToOrganizationCmd.Flags().StringP("group", "G", "", "Name of the group") - addGroupToOrganizationCmd.Flags().Bool("org-owner", false, "Flag to add the user to the group as an owner") + } diff --git a/cmd/list.go b/cmd/list.go index 6ae097d2..c155ef30 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -637,18 +637,9 @@ var listProjectGroupsCmd = &cobra.Command{ }, } -var listOrganizationCmd = &cobra.Command{ - Use: "organization", - Aliases: []string{"o"}, - Short: "List all organizations projects, groups, deploy targets or users", - PersistentPreRun: func(cmd *cobra.Command, args []string) { - validateToken(lagoonCLIConfig.Current) - }, -} - var listOrganizationProjectsCmd = &cobra.Command{ - Use: "projects", - Aliases: []string{"p"}, + Use: "organization-projects", + Aliases: []string{"org-p"}, Short: "List projects in an organization", PreRunE: func(_ *cobra.Command, _ []string) error { return validateTokenE(cmdLagoon) @@ -658,7 +649,7 @@ var listOrganizationProjectsCmd = &cobra.Command{ if err != nil { return err } - organizationName, err := cmd.Flags().GetString("name") + organizationName, err := cmd.Flags().GetString("organization") if err != nil { return err } @@ -700,8 +691,8 @@ var listOrganizationProjectsCmd = &cobra.Command{ } var listOrganizationGroupsCmd = &cobra.Command{ - Use: "groups", - Aliases: []string{"g"}, + Use: "organization-groups", + Aliases: []string{"org-g"}, Short: "List groups in an organization", PreRunE: func(_ *cobra.Command, _ []string) error { return validateTokenE(cmdLagoon) @@ -711,7 +702,7 @@ var listOrganizationGroupsCmd = &cobra.Command{ if err != nil { return err } - organizationName, err := cmd.Flags().GetString("name") + organizationName, err := cmd.Flags().GetString("organization") if err != nil { return err } @@ -754,8 +745,8 @@ var listOrganizationGroupsCmd = &cobra.Command{ } var listOrganizationDeployTargetsCmd = &cobra.Command{ - Use: "deploytargets", - Aliases: []string{"d"}, + Use: "organization-deploytargets", + Aliases: []string{"org-dt"}, Short: "List deploy targets in an organization", PreRunE: func(_ *cobra.Command, _ []string) error { return validateTokenE(cmdLagoon) @@ -765,7 +756,7 @@ var listOrganizationDeployTargetsCmd = &cobra.Command{ if err != nil { return err } - organizationName, err := cmd.Flags().GetString("name") + organizationName, err := cmd.Flags().GetString("organization") if err != nil { return err } @@ -773,10 +764,8 @@ var listOrganizationDeployTargetsCmd = &cobra.Command{ if err != nil { return err } - if err := requiredInputCheck("Organization name", organizationName); err != nil { - if err := requiredInputCheck("Organization ID", strconv.Itoa(int(organizationID))); err != nil { - return err - } + if organizationName == "" && organizationID == 0 { + return fmt.Errorf("Missing arguments: Organization name or ID is not defined") } current := lagoonCLIConfig.Current @@ -788,7 +777,6 @@ var listOrganizationDeployTargetsCmd = &cobra.Command{ debug) deployTargets, err := l.ListDeployTargetsByOrganizationNameOrID(context.TODO(), nullStrCheck(organizationName), nullUintCheck(organizationID), lc) handleError(err) - if len(*deployTargets) == 0 { outputOptions.Error = fmt.Sprintf("No associated deploy targets found for organization '%s'\n", organizationName) } @@ -815,8 +803,8 @@ var listOrganizationDeployTargetsCmd = &cobra.Command{ } var ListOrganizationUsersCmd = &cobra.Command{ - Use: "users", - Aliases: []string{"u"}, + Use: "organization-users", + Aliases: []string{"org-u"}, Short: "List users in an organization", PreRunE: func(_ *cobra.Command, _ []string) error { return validateTokenE(cmdLagoon) @@ -826,7 +814,7 @@ var ListOrganizationUsersCmd = &cobra.Command{ if err != nil { return err } - organizationName, err := cmd.Flags().GetString("name") + organizationName, err := cmd.Flags().GetString("organization") if err != nil { return err } @@ -928,21 +916,20 @@ func init() { listCmd.AddCommand(listDeployTargetConfigsCmd) listCmd.AddCommand(listAllUsersCmd) listCmd.AddCommand(listUsersGroupsCmd) + listCmd.AddCommand(listOrganizationProjectsCmd) + listCmd.AddCommand(ListOrganizationUsersCmd) + listCmd.AddCommand(listOrganizationGroupsCmd) + listCmd.AddCommand(listOrganizationDeployTargetsCmd) + listCmd.AddCommand(listOrganizationsCmd) listAllUsersCmd.Flags().StringP("email-address", "E", "", "The email address of a user") listUsersGroupsCmd.Flags().StringP("email-address", "E", "", "The email address of a user") - listCmd.AddCommand(listOrganizationCmd) - listOrganizationCmd.AddCommand(listOrganizationProjectsCmd) - listOrganizationCmd.AddCommand(ListOrganizationUsersCmd) - listOrganizationCmd.AddCommand(listOrganizationGroupsCmd) - listOrganizationCmd.AddCommand(listOrganizationDeployTargetsCmd) - listOrganizationCmd.AddCommand(listOrganizationsCmd) listCmd.Flags().BoolVarP(&listAllProjects, "all-projects", "", false, "All projects (if supported)") listUsersCmd.Flags().StringVarP(&groupName, "name", "N", "", "Name of the group to list users in") listGroupProjectsCmd.Flags().StringVarP(&groupName, "name", "N", "", "Name of the group to list projects in") listVariablesCmd.Flags().BoolP("reveal", "", false, "Reveal the variable values") - listOrganizationProjectsCmd.Flags().StringP("name", "O", "", "Name of the organization to list associated projects for") - ListOrganizationUsersCmd.Flags().StringP("name", "O", "", "Name of the organization to list associated users for") - listOrganizationGroupsCmd.Flags().StringP("name", "O", "", "Name of the organization to list associated groups for") - listOrganizationDeployTargetsCmd.Flags().StringP("name", "O", "", "Name of the organization to list associated deploy targets for") + listOrganizationProjectsCmd.Flags().StringP("organization", "O", "", "Name of the organization to list associated projects for") + ListOrganizationUsersCmd.Flags().StringP("organization", "O", "", "Name of the organization to list associated users for") + listOrganizationGroupsCmd.Flags().StringP("organization", "O", "", "Name of the organization to list associated groups for") + listOrganizationDeployTargetsCmd.Flags().StringP("organization", "O", "", "Name of the organization to list associated deploy targets for") listOrganizationDeployTargetsCmd.Flags().Uint("id", 0, "ID of the organization to list associated deploy targets for") } diff --git a/cmd/organization.go b/cmd/organization.go index a611a3e5..31746aa0 100644 --- a/cmd/organization.go +++ b/cmd/organization.go @@ -217,17 +217,6 @@ var updateOrganizationCmd = &cobra.Command{ } func init() { - //addOrganizationCmd.AddCommand(addOrgCmd) - addOrganizationCmd.AddCommand(addGroupToOrganizationCmd) - //addOrganizationCmd.AddCommand(addProjectToOrganizationCmd) - //addOrganizationCmd.AddCommand(addDeployTargetToOrganizationCmd) - //addOrganizationCmd.AddCommand(addUserToOrganizationCmd) - - //deleteOrganizationCmd.AddCommand(deleteOrgCmd) - //deleteOrganizationCmd.AddCommand(RemoveDeployTargetFromOrganizationCmd) - deleteOrganizationCmd.AddCommand(RemoveProjectFromOrganizationCmd) - //deleteOrganizationCmd.AddCommand(RemoveUserFromOrganization) - 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") diff --git a/cmd/project.go b/cmd/project.go index 1c475200..93c1c8e3 100644 --- a/cmd/project.go +++ b/cmd/project.go @@ -62,40 +62,6 @@ var deleteProjectCmd = &cobra.Command{ }, } -//var addProjectCmd = &cobra.Command{ -// Use: "project", -// Aliases: []string{"p"}, -// Short: "Add a new project to Lagoon", -// Run: func(cmd *cobra.Command, args []string) { -// projectFlags := parseProjectFlags(*cmd.Flags()) -// if cmdProjectName == "" { -// fmt.Println("Missing arguments: Project name is not defined") -// cmd.Help() -// os.Exit(1) -// } -// -// jsonPatch, _ := json.Marshal(projectFlags) -// addResult, err := pClient.AddProject(cmdProjectName, string(jsonPatch)) -// handleError(err) -// var addedProject api.Project -// err = json.Unmarshal([]byte(addResult), &addedProject) -// handleError(err) -// -// if err != nil { -// output.RenderError(err.Error(), outputOptions) -// } else { -// resultData := output.Result{ -// Result: "success", -// ResultData: map[string]interface{}{ -// "Project Name": addedProject.Name, -// "GitURL": addedProject.GitURL, -// }, -// } -// output.RenderResult(resultData, outputOptions) -// } -// }, -//} - var addProjectCmd = &cobra.Command{ Use: "project", Aliases: []string{"p"}, @@ -107,7 +73,7 @@ var addProjectCmd = &cobra.Command{ debug, err := cmd.Flags().GetBool("debug") handleError(err) - organizationName, err := cmd.Flags().GetString("org-name") + organizationName, err := cmd.Flags().GetString("organization") if err != nil { return err } @@ -167,10 +133,6 @@ var addProjectCmd = &cobra.Command{ if err != nil { return err } - //json, err := cmd.Flags().GetString("json") - //if err != nil { - // return err - //} if err := requiredInputCheck("Project name", cmdProjectName, "GitURL", gitUrl, "Production environment", productionEnvironment, "Openshift", strconv.Itoa(int(openshift))); err != nil { return err @@ -497,176 +459,9 @@ var deleteProjectMetadataByKey = &cobra.Command{ }, } -var addProjectToOrganizationCmd = &cobra.Command{ - Use: "organization-project", - Aliases: []string{"op"}, - Short: "Add a project to an Organization", - PreRunE: func(_ *cobra.Command, _ []string) error { - return validateTokenE(lagoonCLIConfig.Current) - }, - RunE: func(cmd *cobra.Command, args []string) error { - debug, err := cmd.Flags().GetBool("debug") - handleError(err) - - if err := requiredInputCheck("Project name", cmdProjectName); 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 - } - gitUrl, err := cmd.Flags().GetString("git-url") - if err != nil { - return err - } - if err := requiredInputCheck("gitUrl", gitUrl); err != nil { - return err - } - productionEnvironment, err := cmd.Flags().GetString("production-environment") - if err != nil { - return err - } - if err := requiredInputCheck("Production Environment", productionEnvironment); err != nil { - return err - } - openshift, err := cmd.Flags().GetUint("openshift") - if err != nil { - return err - } - if err := requiredInputCheck("openshift", strconv.Itoa(int(openshift))); err != nil { - return err - } - standbyProductionEnvironment, err := cmd.Flags().GetString("standby-production-environment") - if err != nil { - return err - } - branches, err := cmd.Flags().GetString("branches") - if err != nil { - return err - } - pullrequests, err := cmd.Flags().GetString("pullrequests") - if err != nil { - return err - } - openshiftProjectPattern, err := cmd.Flags().GetString("openshift-project-pattern") - if err != nil { - return err - } - developmentEnvironmentsLimit, err := cmd.Flags().GetUint("development-environments-limit") - if err != nil { - return err - } - storageCalc, err := cmd.Flags().GetUint("storage-calc") - if err != nil { - return err - } - autoIdle, err := cmd.Flags().GetUint("auto-idle") - if err != nil { - return err - } - subfolder, err := cmd.Flags().GetString("subfolder") - if err != nil { - return err - } - privateKey, err := cmd.Flags().GetString("private-key") - if err != nil { - return err - } - orgOwner, err := cmd.Flags().GetBool("org-owner") - if err != nil { - return err - } - buildImage, err := cmd.Flags().GetString("build-image") - if err != nil { - return err - } - availability, err := cmd.Flags().GetString("availability") - if err != nil { - return err - } - factsUi, err := cmd.Flags().GetUint("facts-ui") - if err != nil { - return err - } - problemsUi, err := cmd.Flags().GetUint("problems-ui") - if err != nil { - return err - } - routerPattern, err := cmd.Flags().GetString("router-pattern") - if err != nil { - return err - } - deploymentsDisabled, err := cmd.Flags().GetUint("deployments-disabled") - if err != nil { - return err - } - ProductionBuildPriority, err := cmd.Flags().GetUint("production-build-priority") - if err != nil { - return err - } - DevelopmentBuildPriority, err := cmd.Flags().GetUint("development-build-priority") - if err != nil { - return err - } - - current := lagoonCLIConfig.Current - token := lagoonCLIConfig.Lagoons[current].Token - lc := lclient.New( - lagoonCLIConfig.Lagoons[current].GraphQL, - lagoonCLIVersion, - &token, - debug) - - organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc) - handleError(err) - - projectInput := s.AddProjectInput{ - Name: cmdProjectName, - Organization: organization.ID, - AddOrgOwner: orgOwner, - BuildImage: buildImage, - Availability: s.ProjectAvailability(availability), - GitURL: gitUrl, - ProductionEnvironment: productionEnvironment, - StandbyProductionEnvironment: standbyProductionEnvironment, - Branches: branches, - PullRequests: pullrequests, - OpenshiftProjectPattern: openshiftProjectPattern, - Openshift: openshift, - DevelopmentEnvironmentsLimit: developmentEnvironmentsLimit, - StorageCalc: storageCalc, - AutoIdle: autoIdle, - Subfolder: subfolder, - PrivateKey: privateKey, - RouterPattern: routerPattern, - ProblemsUI: problemsUi, - FactsUI: factsUi, - ProductionBuildPriority: ProductionBuildPriority, - DevelopmentBuildPriority: DevelopmentBuildPriority, - DeploymentsDisabled: deploymentsDisabled, - } - project := s.Project{} - err = lc.AddProject(context.TODO(), &projectInput, &project) - handleError(err) - - resultData := output.Result{ - Result: "success", - ResultData: map[string]interface{}{ - "Project Name": project.Name, - "Organization Name": organizationName, - }, - } - output.RenderResult(resultData, outputOptions) - return nil - }, -} - var RemoveProjectFromOrganizationCmd = &cobra.Command{ - Use: "project", - Aliases: []string{"p"}, + Use: "organization-project", + Aliases: []string{"org-p"}, Short: "Remove a project from an Organization", PreRunE: func(_ *cobra.Command, _ []string) error { return validateTokenE(lagoonCLIConfig.Current) @@ -675,14 +470,11 @@ var RemoveProjectFromOrganizationCmd = &cobra.Command{ debug, err := cmd.Flags().GetBool("debug") handleError(err) - if err := requiredInputCheck("Project name", cmdProjectName); err != nil { - return err - } - organizationName, err := cmd.Flags().GetString("name") + organizationName, err := cmd.Flags().GetString("organization") if err != nil { return err } - if err := requiredInputCheck("Organization name", organizationName); err != nil { + if err := requiredInputCheck("Project name", cmdProjectName, "Organization name", organizationName); err != nil { return err } @@ -761,7 +553,7 @@ func init() { addProjectCmd.Flags().UintP("developmentEnvironmentsLimit", "L", 0, "How many environments can be deployed at one time") addProjectCmd.Flags().UintP("openshift", "S", 0, "Reference to OpenShift Object this Project should be deployed to") addProjectCmd.Flags().Bool("org-owner", false, "Add the user as an owner of the project") - addProjectCmd.Flags().StringP("org-name", "O", "", "Name of the Organization to add the project to") + addProjectCmd.Flags().StringP("organization", "O", "", "Name of the Organization to add the project to") listCmd.AddCommand(listProjectByMetadata) listProjectByMetadata.Flags().StringP("key", "K", "", "The key name of the metadata value you are querying on") @@ -777,28 +569,5 @@ func init() { getCmd.AddCommand(getProjectMetadata) - //addProjectToOrganizationCmd.Flags().String("build-image", "", "Build Image for the project") - //addProjectToOrganizationCmd.Flags().String("availability", "", "Availability of the project") - //addProjectToOrganizationCmd.Flags().String("git-url", "", "GitURL of the project") - //addProjectToOrganizationCmd.Flags().String("production-environment", "", "Production Environment for the project") - //addProjectToOrganizationCmd.Flags().String("standby-production-environment", "", "Standby Production Environment for the project") - //addProjectToOrganizationCmd.Flags().String("subfolder", "", "Set if the .lagoon.yml should be found in a subfolder useful if you have multiple Lagoon projects per Git Repository") - //addProjectToOrganizationCmd.Flags().String("private-key", "", "Private key to use for the project") - //addProjectToOrganizationCmd.Flags().String("branches", "", "branches") - //addProjectToOrganizationCmd.Flags().String("pullrequests", "", "Which Pull Requests should be deployed") - //addProjectToOrganizationCmd.Flags().StringP("name", "O", "", "Name of the Organization to add the project to") - //addProjectToOrganizationCmd.Flags().String("openshift-project-pattern", "", "Pattern of OpenShift Project/Namespace that should be generated") - //addProjectToOrganizationCmd.Flags().String("router-pattern", "", "Router pattern of the project, e.g. '${service}-${environment}-${project}.lagoon.example.com'") - // - //addProjectToOrganizationCmd.Flags().Uint("openshift", 0, "Reference to OpenShift Object this Project should be deployed to") - //addProjectToOrganizationCmd.Flags().Uint("auto-idle", 0, "Auto idle setting of the project") - //addProjectToOrganizationCmd.Flags().Uint("storage-calc", 0, "Should storage for this environment be calculated") - //addProjectToOrganizationCmd.Flags().Uint("development-environments-limit", 0, "How many environments can be deployed at one time") - //addProjectToOrganizationCmd.Flags().Uint("facts-ui", 0, "Enables the Lagoon insights Facts tab in the UI. Set to 1 to enable, 0 to disable") - //addProjectToOrganizationCmd.Flags().Uint("problems-ui", 0, "Enables the Lagoon insights Problems tab in the UI. Set to 1 to enable, 0 to disable") - //addProjectToOrganizationCmd.Flags().Uint("deployments-disabled", 0, "Admin only flag for disabling deployments on a project, 1 to disable deployments, 0 to enable") - //addProjectToOrganizationCmd.Flags().Uint("production-build-priority", 0, "Set the priority of the production build") - //addProjectToOrganizationCmd.Flags().Uint("development-build-priority", 0, "Set the priority of the development build") - - RemoveProjectFromOrganizationCmd.Flags().StringP("name", "O", "", "Name of the Organization to remove the project from") + RemoveProjectFromOrganizationCmd.Flags().StringP("organization", "O", "", "Name of the Organization to remove the project from") } diff --git a/cmd/users.go b/cmd/users.go index e498cf7b..9e6adad2 100644 --- a/cmd/users.go +++ b/cmd/users.go @@ -376,14 +376,11 @@ var addAdministratorToOrganizationCmd = &cobra.Command{ if err != nil { return err } - if err := requiredInputCheck("Organization name", organizationName); err != nil { - return err - } userEmail, err := cmd.Flags().GetString("email") if err != nil { return err } - if err := requiredInputCheck("User email", userEmail); err != nil { + if err := requiredInputCheck("Organization name", organizationName, "User email", userEmail); err != nil { return err } owner, err := cmd.Flags().GetBool("owner") From 2657631f25bec245b240731ab7c91c7baada66b2 Mon Sep 17 00:00:00 2001 From: cgoodwin90 Date: Mon, 25 Mar 2024 18:06:23 +1100 Subject: [PATCH 3/9] Generated docs --- docs/commands/lagoon_add.md | 4 +++- docs/commands/lagoon_add_group.md | 6 ++++-- docs/commands/lagoon_add_organization.md | 21 ++++++++++++++------- docs/commands/lagoon_add_project.md | 10 ++++++---- docs/commands/lagoon_delete.md | 5 ++++- docs/commands/lagoon_delete_organization.md | 13 +++++++------ docs/commands/lagoon_list.md | 6 +++++- 7 files changed, 43 insertions(+), 22 deletions(-) diff --git a/docs/commands/lagoon_add.md b/docs/commands/lagoon_add.md index b2a9a9f0..f5e36774 100644 --- a/docs/commands/lagoon_add.md +++ b/docs/commands/lagoon_add.md @@ -32,7 +32,9 @@ 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 a new organization to Lagoon +* [lagoon add organization-administrator](lagoon_add_organization-administrator.md) - Add an administrator to an Organization +* [lagoon add organization-deploytarget](lagoon_add_organization-deploytarget.md) - Add a deploy target 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 diff --git a/docs/commands/lagoon_add_group.md b/docs/commands/lagoon_add_group.md index 25a290be..40079fc5 100644 --- a/docs/commands/lagoon_add_group.md +++ b/docs/commands/lagoon_add_group.md @@ -9,8 +9,10 @@ lagoon add group [flags] ### Options ``` - -h, --help help for group - -N, --name string Name of the group + -h, --help help for group + -N, --name string Name of the group + --org-owner Flag to add the user to the group as an owner + -O, --organization string Name of the organization ``` ### Options inherited from parent commands diff --git a/docs/commands/lagoon_add_organization.md b/docs/commands/lagoon_add_organization.md index db7c2765..7d12f397 100644 --- a/docs/commands/lagoon_add_organization.md +++ b/docs/commands/lagoon_add_organization.md @@ -1,11 +1,23 @@ ## lagoon add organization -Add an organization, or add a group/project to an organization +Add a new organization to Lagoon + +``` +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 @@ -28,9 +40,4 @@ Add an organization, or add a group/project to an organization ### SEE ALSO * [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 diff --git a/docs/commands/lagoon_add_project.md b/docs/commands/lagoon_add_project.md index f10da958..7967dc25 100644 --- a/docs/commands/lagoon_add_project.md +++ b/docs/commands/lagoon_add_project.md @@ -9,20 +9,22 @@ lagoon add project [flags] ### Options ``` - -a, --autoIdle int Auto idle setting of the project + -a, --autoIdle uint Auto idle setting of the project -b, --branches string Which branches should be deployed - -L, --developmentEnvironmentsLimit int How many environments can be deployed at one time + -L, --developmentEnvironmentsLimit uint How many environments can be deployed at one time -g, --gitUrl string GitURL of the project -h, --help help for project -j, --json string JSON string to patch - -S, --openshift int Reference to OpenShift Object this Project should be deployed to + -S, --openshift uint Reference to OpenShift Object this Project should be deployed to -o, --openshiftProjectPattern string Pattern of OpenShift Project/Namespace that should be generated + --org-owner Add the user as an owner of the project + -O, --organization string Name of the Organization to add the project to -I, --privateKey string Private key to use for the project -E, --productionEnvironment string Which environment(the name) should be marked as the production environment -m, --pullrequests string Which Pull Requests should be deployed -Z, --routerPattern string Router pattern of the project, e.g. '${service}-${environment}-${project}.lagoon.example.com' --standbyProductionEnvironment string Which environment(the name) should be marked as the standby production environment - -C, --storageCalc int Should storage for this environment be calculated + -C, --storageCalc uint Should storage for this environment be calculated -s, --subfolder string Set if the .lagoon.yml should be found in a subfolder useful if you have multiple Lagoon projects per Git Repository ``` diff --git a/docs/commands/lagoon_delete.md b/docs/commands/lagoon_delete.md index 6204e2bc..90ac6221 100644 --- a/docs/commands/lagoon_delete.md +++ b/docs/commands/lagoon_delete.md @@ -33,7 +33,10 @@ Delete a project, or delete notifications and variables from projects or environ * [lagoon delete environment](lagoon_delete_environment.md) - Delete an environment * [lagoon delete group](lagoon_delete_group.md) - Delete a group from lagoon * [lagoon delete notification](lagoon_delete_notification.md) - Delete notifications or delete notifications from projects -* [lagoon delete organization](lagoon_delete_organization.md) - Add an organization, or add a group/project to an organization +* [lagoon delete organization](lagoon_delete_organization.md) - Delete an organization +* [lagoon delete organization-administrator](lagoon_delete_organization-administrator.md) - Remove an administrator from an Organization +* [lagoon delete organization-deploytarget](lagoon_delete_organization-deploytarget.md) - Remove a deploy target from an Organization +* [lagoon delete organization-project](lagoon_delete_organization-project.md) - Remove a project from an Organization * [lagoon delete project](lagoon_delete_project.md) - Delete a project * [lagoon delete project-group](lagoon_delete_project-group.md) - Delete a project from a group in lagoon * [lagoon delete project-metadata](lagoon_delete_project-metadata.md) - Delete a key from a projects metadata diff --git a/docs/commands/lagoon_delete_organization.md b/docs/commands/lagoon_delete_organization.md index be5c5566..577187a7 100644 --- a/docs/commands/lagoon_delete_organization.md +++ b/docs/commands/lagoon_delete_organization.md @@ -1,11 +1,16 @@ ## lagoon delete organization -Add an organization, or add a group/project to an organization +Delete an organization + +``` +lagoon delete organization [flags] +``` ### Options ``` - -h, --help help for organization + -h, --help help for organization + -O, --name string Name of the organization to delete ``` ### Options inherited from parent commands @@ -28,8 +33,4 @@ Add an organization, or add a group/project to an organization ### SEE ALSO * [lagoon delete](lagoon_delete.md) - Delete a project, or delete notifications and variables from projects or environments -* [lagoon delete organization deploytarget](lagoon_delete_organization_deploytarget.md) - Remove a deploy target from an Organization -* [lagoon delete organization organization](lagoon_delete_organization_organization.md) - Delete an organization -* [lagoon delete organization project](lagoon_delete_organization_project.md) - Remove a project from an Organization -* [lagoon delete organization user](lagoon_delete_organization_user.md) - Remove a user to an Organization diff --git a/docs/commands/lagoon_list.md b/docs/commands/lagoon_list.md index 784a07a4..fbf25ee9 100644 --- a/docs/commands/lagoon_list.md +++ b/docs/commands/lagoon_list.md @@ -40,7 +40,11 @@ List projects, environments, 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 organization](lagoon_list_organization.md) - List all organizations projects, groups, deploy targets or users +* [lagoon list organization-deploytargets](lagoon_list_organization-deploytargets.md) - List deploy targets in an organization +* [lagoon list organization-groups](lagoon_list_organization-groups.md) - List groups in an organization +* [lagoon list organization-projects](lagoon_list_organization-projects.md) - List projects in an organization +* [lagoon list organization-users](lagoon_list_organization-users.md) - List users in an organization +* [lagoon list organizations](lagoon_list_organizations.md) - List all organizations * [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 From 4096aa32f1eacfbfb7ca36da370766b5b8d9f634 Mon Sep 17 00:00:00 2001 From: cgoodwin90 Date: Thu, 11 Apr 2024 10:19:07 +1000 Subject: [PATCH 4/9] Removed old docs & re-ran docs generator --- ... lagoon_add_organization-administrator.md} | 10 ++-- ...> lagoon_add_organization-deploytarget.md} | 8 +-- .../commands/lagoon_add_organization_group.md | 38 ------------- .../lagoon_add_organization_organization.md | 43 -------------- .../lagoon_add_organization_project.md | 57 ------------------- ...goon_delete_organization-administrator.md} | 10 ++-- ...agoon_delete_organization-deploytarget.md} | 8 +-- ... => lagoon_delete_organization-project.md} | 10 ++-- ...lagoon_delete_organization_organization.md | 36 ------------ ...lagoon_list_organization-deploytargets.md} | 12 ++-- ....md => lagoon_list_organization-groups.md} | 10 ++-- ...d => lagoon_list_organization-projects.md} | 10 ++-- ...s.md => lagoon_list_organization-users.md} | 10 ++-- docs/commands/lagoon_list_organization.md | 36 ------------ ...ations.md => lagoon_list_organizations.md} | 6 +- 15 files changed, 47 insertions(+), 257 deletions(-) rename docs/commands/{lagoon_delete_organization_user.md => lagoon_add_organization-administrator.md} (78%) rename docs/commands/{lagoon_add_organization_deploytarget.md => lagoon_add_organization-deploytarget.md} (79%) delete mode 100644 docs/commands/lagoon_add_organization_group.md delete mode 100644 docs/commands/lagoon_add_organization_organization.md delete mode 100644 docs/commands/lagoon_add_organization_project.md rename docs/commands/{lagoon_add_organization_user.md => lagoon_delete_organization-administrator.md} (76%) rename docs/commands/{lagoon_delete_organization_deploytarget.md => lagoon_delete_organization-deploytarget.md} (78%) rename docs/commands/{lagoon_delete_organization_project.md => lagoon_delete_organization-project.md} (72%) delete mode 100644 docs/commands/lagoon_delete_organization_organization.md rename docs/commands/{lagoon_list_organization_deploytargets.md => lagoon_list_organization-deploytargets.md} (67%) rename docs/commands/{lagoon_list_organization_groups.md => lagoon_list_organization-groups.md} (74%) rename docs/commands/{lagoon_list_organization_projects.md => lagoon_list_organization-projects.md} (73%) rename docs/commands/{lagoon_list_organization_users.md => lagoon_list_organization-users.md} (74%) delete mode 100644 docs/commands/lagoon_list_organization.md rename docs/commands/{lagoon_list_organization_organizations.md => lagoon_list_organizations.md} (81%) diff --git a/docs/commands/lagoon_delete_organization_user.md b/docs/commands/lagoon_add_organization-administrator.md similarity index 78% rename from docs/commands/lagoon_delete_organization_user.md rename to docs/commands/lagoon_add_organization-administrator.md index d7ebd6df..68d1d2ce 100644 --- a/docs/commands/lagoon_delete_organization_user.md +++ b/docs/commands/lagoon_add_organization-administrator.md @@ -1,16 +1,16 @@ -## lagoon delete organization user +## lagoon add organization-administrator -Remove a user to an Organization +Add an administrator to an Organization ``` -lagoon delete organization user [flags] +lagoon add organization-administrator [flags] ``` ### Options ``` -E, --email string Email address of the user - -h, --help help for user + -h, --help help for organization-administrator -O, --name string Name of the organization --owner Set the user as an owner of the organization ``` @@ -34,5 +34,5 @@ lagoon delete organization user [flags] ### SEE ALSO -* [lagoon delete organization](lagoon_delete_organization.md) - 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 diff --git a/docs/commands/lagoon_add_organization_deploytarget.md b/docs/commands/lagoon_add_organization-deploytarget.md similarity index 79% rename from docs/commands/lagoon_add_organization_deploytarget.md rename to docs/commands/lagoon_add_organization-deploytarget.md index 12baa1b9..a9a6d6ee 100644 --- a/docs/commands/lagoon_add_organization_deploytarget.md +++ b/docs/commands/lagoon_add_organization-deploytarget.md @@ -1,16 +1,16 @@ -## lagoon add organization deploytarget +## lagoon add organization-deploytarget Add a deploy target to an Organization ``` -lagoon add organization deploytarget [flags] +lagoon add organization-deploytarget [flags] ``` ### Options ``` -D, --deploy-target uint ID of DeployTarget - -h, --help help for deploytarget + -h, --help help for organization-deploytarget -O, --name string Name of Organization ``` @@ -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](lagoon_add.md) - Add a project, or add notifications and variables to projects or environments diff --git a/docs/commands/lagoon_add_organization_group.md b/docs/commands/lagoon_add_organization_group.md deleted file mode 100644 index ed5fbffc..00000000 --- a/docs/commands/lagoon_add_organization_group.md +++ /dev/null @@ -1,38 +0,0 @@ -## lagoon add organization group - -Add a group to an Organization - -``` -lagoon add organization group [flags] -``` - -### Options - -``` - -G, --group string Name of the group - -h, --help help for group - -O, --name string Name of the organization - --org-owner Flag to add the user to the group as an owner -``` - -### 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 add organization](lagoon_add_organization.md) - Add an organization, or add a group/project to an organization - diff --git a/docs/commands/lagoon_add_organization_organization.md b/docs/commands/lagoon_add_organization_organization.md deleted file mode 100644 index ce70a134..00000000 --- a/docs/commands/lagoon_add_organization_organization.md +++ /dev/null @@ -1,43 +0,0 @@ -## lagoon add organization organization - -Add a new organization to Lagoon - -``` -lagoon add organization organization [flags] -``` - -### Options - -``` - --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 - -``` - --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 add organization](lagoon_add_organization.md) - Add an organization, or add a group/project to an organization - diff --git a/docs/commands/lagoon_add_organization_project.md b/docs/commands/lagoon_add_organization_project.md deleted file mode 100644 index 1b7815d5..00000000 --- a/docs/commands/lagoon_add_organization_project.md +++ /dev/null @@ -1,57 +0,0 @@ -## lagoon add organization project - -Add a project to an Organization - -``` -lagoon add organization project [flags] -``` - -### Options - -``` - --auto-idle uint Auto idle setting of the project - --availability string Availability of the project - --branches string branches - --build-image string Build Image for the project - --deployments-disabled uint Admin only flag for disabling deployments on a project, 1 to disable deployments, 0 to enable - --development-build-priority uint Set the priority of the development build - --development-environments-limit uint How many environments can be deployed at one time - --facts-ui uint Enables the Lagoon insights Facts tab in the UI. Set to 1 to enable, 0 to disable - --git-url string GitURL of the project - -h, --help help for project - -O, --name string Name of the Organization to add the project to - --openshift uint Reference to OpenShift Object this Project should be deployed to - --openshift-project-pattern string Pattern of OpenShift Project/Namespace that should be generated - --org-owner Add the user as an owner of the project - --private-key string Private key to use for the project - --problems-ui uint Enables the Lagoon insights Problems tab in the UI. Set to 1 to enable, 0 to disable - --production-build-priority uint Set the priority of the production build - --production-environment string Production Environment for the project - --pullrequests string Which Pull Requests should be deployed - --router-pattern string Router pattern of the project, e.g. '${service}-${environment}-${project}.lagoon.example.com' - --standby-production-environment string Standby Production Environment for the project - --storage-calc uint Should storage for this environment be calculated - --subfolder string Set if the .lagoon.yml should be found in a subfolder useful if you have multiple Lagoon projects per Git Repository -``` - -### 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 add organization](lagoon_add_organization.md) - Add an organization, or add a group/project to an organization - diff --git a/docs/commands/lagoon_add_organization_user.md b/docs/commands/lagoon_delete_organization-administrator.md similarity index 76% rename from docs/commands/lagoon_add_organization_user.md rename to docs/commands/lagoon_delete_organization-administrator.md index e4c3c674..a5fb4358 100644 --- a/docs/commands/lagoon_add_organization_user.md +++ b/docs/commands/lagoon_delete_organization-administrator.md @@ -1,16 +1,16 @@ -## lagoon add organization user +## lagoon delete organization-administrator -Add a user to an Organization +Remove an administrator from an Organization ``` -lagoon add organization user [flags] +lagoon delete organization-administrator [flags] ``` ### Options ``` -E, --email string Email address of the user - -h, --help help for user + -h, --help help for organization-administrator -O, --name string Name of the organization --owner Set the user as an owner of the organization ``` @@ -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 delete](lagoon_delete.md) - Delete a project, or delete notifications and variables from projects or environments diff --git a/docs/commands/lagoon_delete_organization_deploytarget.md b/docs/commands/lagoon_delete_organization-deploytarget.md similarity index 78% rename from docs/commands/lagoon_delete_organization_deploytarget.md rename to docs/commands/lagoon_delete_organization-deploytarget.md index d0e2f6a6..1f1de984 100644 --- a/docs/commands/lagoon_delete_organization_deploytarget.md +++ b/docs/commands/lagoon_delete_organization-deploytarget.md @@ -1,16 +1,16 @@ -## lagoon delete organization deploytarget +## lagoon delete organization-deploytarget Remove a deploy target from an Organization ``` -lagoon delete organization deploytarget [flags] +lagoon delete organization-deploytarget [flags] ``` ### Options ``` -D, --deploy-target uint ID of DeployTarget - -h, --help help for deploytarget + -h, --help help for organization-deploytarget -O, --name string Name of Organization ``` @@ -33,5 +33,5 @@ lagoon delete organization deploytarget [flags] ### SEE ALSO -* [lagoon delete organization](lagoon_delete_organization.md) - Add an organization, or add a group/project to an organization +* [lagoon delete](lagoon_delete.md) - Delete a project, or delete notifications and variables from projects or environments diff --git a/docs/commands/lagoon_delete_organization_project.md b/docs/commands/lagoon_delete_organization-project.md similarity index 72% rename from docs/commands/lagoon_delete_organization_project.md rename to docs/commands/lagoon_delete_organization-project.md index 91a9385f..46198a2b 100644 --- a/docs/commands/lagoon_delete_organization_project.md +++ b/docs/commands/lagoon_delete_organization-project.md @@ -1,16 +1,16 @@ -## lagoon delete organization project +## lagoon delete organization-project Remove a project from an Organization ``` -lagoon delete organization project [flags] +lagoon delete organization-project [flags] ``` ### Options ``` - -h, --help help for project - -O, --name string Name of the Organization to remove the project from + -h, --help help for organization-project + -O, --organization string Name of the Organization to remove the project from ``` ### Options inherited from parent commands @@ -32,5 +32,5 @@ lagoon delete organization project [flags] ### SEE ALSO -* [lagoon delete organization](lagoon_delete_organization.md) - Add an organization, or add a group/project to an organization +* [lagoon delete](lagoon_delete.md) - Delete a project, or delete notifications and variables from projects or environments diff --git a/docs/commands/lagoon_delete_organization_organization.md b/docs/commands/lagoon_delete_organization_organization.md deleted file mode 100644 index 350a8f44..00000000 --- a/docs/commands/lagoon_delete_organization_organization.md +++ /dev/null @@ -1,36 +0,0 @@ -## lagoon delete organization organization - -Delete an organization - -``` -lagoon delete organization organization [flags] -``` - -### Options - -``` - -h, --help help for organization - -O, --name string Name of the organization to delete -``` - -### 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 delete organization](lagoon_delete_organization.md) - Add an organization, or add a group/project to an organization - diff --git a/docs/commands/lagoon_list_organization_deploytargets.md b/docs/commands/lagoon_list_organization-deploytargets.md similarity index 67% rename from docs/commands/lagoon_list_organization_deploytargets.md rename to docs/commands/lagoon_list_organization-deploytargets.md index d887ed11..deab8f3f 100644 --- a/docs/commands/lagoon_list_organization_deploytargets.md +++ b/docs/commands/lagoon_list_organization-deploytargets.md @@ -1,17 +1,17 @@ -## lagoon list organization deploytargets +## lagoon list organization-deploytargets List deploy targets in an organization ``` -lagoon list organization deploytargets [flags] +lagoon list organization-deploytargets [flags] ``` ### Options ``` - -h, --help help for deploytargets - --id uint ID of the organization to list associated deploy targets for - -O, --name string Name of the organization to list associated deploy targets for + -h, --help help for organization-deploytargets + --id uint ID of the organization to list associated deploy targets for + -O, --organization string Name of the organization to list associated deploy targets for ``` ### Options inherited from parent commands @@ -33,5 +33,5 @@ lagoon list organization deploytargets [flags] ### SEE ALSO -* [lagoon list organization](lagoon_list_organization.md) - List all organizations projects, groups, deploy targets or users +* [lagoon list](lagoon_list.md) - List projects, environments, deployments, variables or notifications diff --git a/docs/commands/lagoon_list_organization_groups.md b/docs/commands/lagoon_list_organization-groups.md similarity index 74% rename from docs/commands/lagoon_list_organization_groups.md rename to docs/commands/lagoon_list_organization-groups.md index a0899f67..d795a175 100644 --- a/docs/commands/lagoon_list_organization_groups.md +++ b/docs/commands/lagoon_list_organization-groups.md @@ -1,16 +1,16 @@ -## lagoon list organization groups +## lagoon list organization-groups List groups in an organization ``` -lagoon list organization groups [flags] +lagoon list organization-groups [flags] ``` ### Options ``` - -h, --help help for groups - -O, --name string Name of the organization to list associated groups for + -h, --help help for organization-groups + -O, --organization string Name of the organization to list associated groups for ``` ### Options inherited from parent commands @@ -32,5 +32,5 @@ lagoon list organization groups [flags] ### SEE ALSO -* [lagoon list organization](lagoon_list_organization.md) - List all organizations projects, groups, deploy targets or users +* [lagoon list](lagoon_list.md) - List projects, environments, deployments, variables or notifications diff --git a/docs/commands/lagoon_list_organization_projects.md b/docs/commands/lagoon_list_organization-projects.md similarity index 73% rename from docs/commands/lagoon_list_organization_projects.md rename to docs/commands/lagoon_list_organization-projects.md index 1747bd3a..bdffd90f 100644 --- a/docs/commands/lagoon_list_organization_projects.md +++ b/docs/commands/lagoon_list_organization-projects.md @@ -1,16 +1,16 @@ -## lagoon list organization projects +## lagoon list organization-projects List projects in an organization ``` -lagoon list organization projects [flags] +lagoon list organization-projects [flags] ``` ### Options ``` - -h, --help help for projects - -O, --name string Name of the organization to list associated projects for + -h, --help help for organization-projects + -O, --organization string Name of the organization to list associated projects for ``` ### Options inherited from parent commands @@ -32,5 +32,5 @@ lagoon list organization projects [flags] ### SEE ALSO -* [lagoon list organization](lagoon_list_organization.md) - List all organizations projects, groups, deploy targets or users +* [lagoon list](lagoon_list.md) - List projects, environments, deployments, variables or notifications diff --git a/docs/commands/lagoon_list_organization_users.md b/docs/commands/lagoon_list_organization-users.md similarity index 74% rename from docs/commands/lagoon_list_organization_users.md rename to docs/commands/lagoon_list_organization-users.md index 54087da5..1b35da23 100644 --- a/docs/commands/lagoon_list_organization_users.md +++ b/docs/commands/lagoon_list_organization-users.md @@ -1,16 +1,16 @@ -## lagoon list organization users +## lagoon list organization-users List users in an organization ``` -lagoon list organization users [flags] +lagoon list organization-users [flags] ``` ### Options ``` - -h, --help help for users - -O, --name string Name of the organization to list associated users for + -h, --help help for organization-users + -O, --organization string Name of the organization to list associated users for ``` ### Options inherited from parent commands @@ -32,5 +32,5 @@ lagoon list organization users [flags] ### SEE ALSO -* [lagoon list organization](lagoon_list_organization.md) - List all organizations projects, groups, deploy targets or users +* [lagoon list](lagoon_list.md) - List projects, environments, deployments, variables or notifications diff --git a/docs/commands/lagoon_list_organization.md b/docs/commands/lagoon_list_organization.md deleted file mode 100644 index 3fd69460..00000000 --- a/docs/commands/lagoon_list_organization.md +++ /dev/null @@ -1,36 +0,0 @@ -## lagoon list organization - -List all organizations projects, groups, deploy targets or users - -### Options - -``` - -h, --help help for organization -``` - -### 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 -* [lagoon list organization deploytargets](lagoon_list_organization_deploytargets.md) - List deploy targets in an organization -* [lagoon list organization groups](lagoon_list_organization_groups.md) - List groups in an organization -* [lagoon list organization organizations](lagoon_list_organization_organizations.md) - List all organizations -* [lagoon list organization projects](lagoon_list_organization_projects.md) - List projects in an organization -* [lagoon list organization users](lagoon_list_organization_users.md) - List users in an organization - diff --git a/docs/commands/lagoon_list_organization_organizations.md b/docs/commands/lagoon_list_organizations.md similarity index 81% rename from docs/commands/lagoon_list_organization_organizations.md rename to docs/commands/lagoon_list_organizations.md index 05c8beb2..f2bc051a 100644 --- a/docs/commands/lagoon_list_organization_organizations.md +++ b/docs/commands/lagoon_list_organizations.md @@ -1,9 +1,9 @@ -## lagoon list organization organizations +## lagoon list organizations List all organizations ``` -lagoon list organization organizations [flags] +lagoon list organizations [flags] ``` ### Options @@ -31,5 +31,5 @@ lagoon list organization organizations [flags] ### SEE ALSO -* [lagoon list organization](lagoon_list_organization.md) - List all organizations projects, groups, deploy targets or users +* [lagoon list](lagoon_list.md) - List projects, environments, deployments, variables or notifications From 703e0cb168db5e7716a5d85cb3f9a4aa7f05a36a Mon Sep 17 00:00:00 2001 From: cgoodwin90 Date: Thu, 11 Apr 2024 14:41:06 +1000 Subject: [PATCH 5/9] Various updates as per comments --- cmd/delete.go | 6 ++--- cmd/deploytarget.go | 26 +++++++++---------- cmd/environment.go | 4 +-- cmd/groups.go | 7 ++--- cmd/list.go | 2 +- cmd/project.go | 4 +-- cmd/shared.go | 2 +- cmd/users.go | 9 ++++--- docs/commands/lagoon_add.md | 2 +- docs/commands/lagoon_add_group.md | 9 +++++-- .../lagoon_add_organization-administrator.md | 4 +++ .../lagoon_add_organization-deploytarget.md | 6 ++--- ...agoon_delete_organization-administrator.md | 2 +- ...lagoon_delete_organization-deploytarget.md | 6 ++--- docs/commands/lagoon_deploy_branch.md | 10 +++---- docs/commands/lagoon_deploy_latest.md | 6 ++--- docs/commands/lagoon_deploy_promote.md | 10 +++---- docs/commands/lagoon_deploy_pullrequest.md | 2 +- docs/commands/lagoon_update_environment.md | 2 +- 19 files changed, 65 insertions(+), 54 deletions(-) diff --git a/cmd/delete.go b/cmd/delete.go index 1c3a25a1..85dea02b 100644 --- a/cmd/delete.go +++ b/cmd/delete.go @@ -35,7 +35,7 @@ func init() { deleteCmd.AddCommand(deleteVariableCmd) deleteCmd.AddCommand(deleteDeployTargetConfigCmd) deleteCmd.AddCommand(deleteOrganizationCmd) - deleteCmd.AddCommand(RemoveDeployTargetFromOrganizationCmd) - deleteCmd.AddCommand(RemoveAdministratorFromOrganizationCmd) - deleteCmd.AddCommand(RemoveProjectFromOrganizationCmd) + deleteCmd.AddCommand(removeDeployTargetFromOrganizationCmd) + deleteCmd.AddCommand(removeAdministratorFromOrganizationCmd) + deleteCmd.AddCommand(removeProjectFromOrganizationCmd) } diff --git a/cmd/deploytarget.go b/cmd/deploytarget.go index aebe72a4..4d7bc93c 100644 --- a/cmd/deploytarget.go +++ b/cmd/deploytarget.go @@ -337,12 +337,12 @@ var addDeployTargetToOrganizationCmd = &cobra.Command{ if err != nil { return err } - deployTarget, err := cmd.Flags().GetUint("deploy-target") + deploytarget, err := cmd.Flags().GetUint("deploytarget") if err != nil { return err } - if err := requiredInputCheck("Organization name", organizationName, "Deploy Target", strconv.Itoa(int(deployTarget))); err != nil { + if err := requiredInputCheck("Organization name", organizationName, "Deploy Target", strconv.Itoa(int(deploytarget))); err != nil { return err } @@ -359,7 +359,7 @@ var addDeployTargetToOrganizationCmd = &cobra.Command{ handleError(err) deployTargetInput := s.AddDeployTargetToOrganizationInput{ - DeployTarget: deployTarget, + DeployTarget: deploytarget, Organization: organization.ID, } @@ -368,7 +368,7 @@ var addDeployTargetToOrganizationCmd = &cobra.Command{ resultData := output.Result{ Result: "success", ResultData: map[string]interface{}{ - "Deploy Target": deployTarget, + "Deploy Target": deploytarget, "Organization Name": deployTargetResponse.Name, }, } @@ -377,7 +377,7 @@ var addDeployTargetToOrganizationCmd = &cobra.Command{ }, } -var RemoveDeployTargetFromOrganizationCmd = &cobra.Command{ +var removeDeployTargetFromOrganizationCmd = &cobra.Command{ Use: "organization-deploytarget", Aliases: []string{"org-dt"}, Short: "Remove a deploy target from an Organization", @@ -395,11 +395,11 @@ var RemoveDeployTargetFromOrganizationCmd = &cobra.Command{ if err := requiredInputCheck("Organization name", organizationName); err != nil { return err } - deployTarget, err := cmd.Flags().GetUint("deploy-target") + deploytarget, err := cmd.Flags().GetUint("deploytarget") if err != nil { return err } - if err := requiredInputCheck("Deploy Target", strconv.Itoa(int(deployTarget))); err != nil { + if err := requiredInputCheck("Deploy Target", strconv.Itoa(int(deploytarget))); err != nil { return err } @@ -416,17 +416,17 @@ var RemoveDeployTargetFromOrganizationCmd = &cobra.Command{ handleError(err) deployTargetInput := s.RemoveDeployTargetFromOrganizationInput{ - DeployTarget: deployTarget, + DeployTarget: deploytarget, Organization: organization.ID, } - if yesNo(fmt.Sprintf("You are attempting to remove deploy target '%d' from organization '%s', are you sure?", deployTarget, organization.Name)) { + if yesNo(fmt.Sprintf("You are attempting to remove deploy target '%d' from organization '%s', are you sure?", deploytarget, organization.Name)) { _, err := l.RemoveDeployTargetFromOrganization(context.TODO(), &deployTargetInput, lc) handleError(err) resultData := output.Result{ Result: "success", ResultData: map[string]interface{}{ - "Deploy Target": deployTarget, + "Deploy Target": deploytarget, "Organization Name": organizationName, }, } @@ -450,13 +450,13 @@ func init() { addDeployTargetCmd.Flags().StringP("build-image", "", "", "DeployTarget build image to use (if different to the default)") addDeployTargetToOrganizationCmd.Flags().StringP("name", "O", "", "Name of Organization") - addDeployTargetToOrganizationCmd.Flags().UintP("deploy-target", "D", 0, "ID of DeployTarget") + addDeployTargetToOrganizationCmd.Flags().UintP("deploytarget", "D", 0, "ID of DeployTarget") deleteDeployTargetCmd.Flags().UintP("id", "", 0, "ID of the DeployTarget") deleteDeployTargetCmd.Flags().StringP("name", "", "", "Name of DeployTarget") - RemoveDeployTargetFromOrganizationCmd.Flags().StringP("name", "O", "", "Name of Organization") - RemoveDeployTargetFromOrganizationCmd.Flags().UintP("deploy-target", "D", 0, "ID of DeployTarget") + removeDeployTargetFromOrganizationCmd.Flags().StringP("name", "O", "", "Name of Organization") + removeDeployTargetFromOrganizationCmd.Flags().UintP("deploytarget", "D", 0, "ID of DeployTarget") updateDeployTargetCmd.Flags().UintP("id", "", 0, "ID of the DeployTarget") updateDeployTargetCmd.Flags().StringP("console-url", "", "", "DeployTarget console URL") diff --git a/cmd/environment.go b/cmd/environment.go index 1625380a..3d1aab96 100644 --- a/cmd/environment.go +++ b/cmd/environment.go @@ -83,7 +83,7 @@ var updateEnvironmentCmd = &cobra.Command{ if err != nil { return err } - openShift, err := cmd.Flags().GetUint("deploy-target") + openShift, err := cmd.Flags().GetUint("deploytarget") if err != nil { return err } @@ -290,7 +290,7 @@ func init() { updateEnvironmentCmd.Flags().String("route", "", "Update the route for the selected environment") updateEnvironmentCmd.Flags().String("routes", "", "Update the routes for the selected environment") updateEnvironmentCmd.Flags().UintVarP(&environmentAutoIdle, "auto-idle", "a", 1, "Auto idle setting of the environment") - updateEnvironmentCmd.Flags().UintP("deploy-target", "d", 0, "Reference to OpenShift Object this Environment should be deployed to") + updateEnvironmentCmd.Flags().UintP("deploytarget", "d", 0, "Reference to OpenShift Object this Environment should be deployed to") updateEnvironmentCmd.Flags().String("environment-type", "", "Update the environment type - production | development") updateEnvironmentCmd.Flags().String("deploy-type", "", "Update the deploy type - branch | pullrequest | promote") } diff --git a/cmd/groups.go b/cmd/groups.go index 2916dd57..0248e547 100644 --- a/cmd/groups.go +++ b/cmd/groups.go @@ -33,7 +33,8 @@ func parseGroup(flags pflag.FlagSet) api.Group { var addGroupCmd = &cobra.Command{ Use: "group", Aliases: []string{"g"}, - Short: "Add a group to lagoon", + Short: "Add a group to lagoon, or add a group to an organization", + Long: "To add a group to an organization, you'll need to include the `organization` flag and provide the name of the organization. You need to be an owner of this organization to do this.\nIf you're the organization owner and want to grant yourself ownership to this group to be able to deploy projects that may be added to it, specify the `owner` flag, otherwise you will still be able to add and remove users without being an owner", PreRunE: func(_ *cobra.Command, _ []string) error { return validateTokenE(lagoonCLIConfig.Current) }, @@ -47,7 +48,7 @@ var addGroupCmd = &cobra.Command{ if err := requiredInputCheck("Group name", groupName); err != nil { return err } - orgOwner, err := cmd.Flags().GetBool("org-owner") + orgOwner, err := cmd.Flags().GetBool("owner") if err != nil { return err } @@ -280,7 +281,7 @@ var deleteGroupCmd = &cobra.Command{ func init() { addGroupCmd.Flags().StringP("name", "N", "", "Name of the group") addGroupCmd.Flags().StringP("organization", "O", "", "Name of the organization") - addGroupCmd.Flags().Bool("org-owner", false, "Flag to add the user to the group as an owner") + addGroupCmd.Flags().Bool("owner", false, "Organization owner only: Flag to grant yourself ownership of this group") addUserToGroupCmd.Flags().StringVarP(&groupName, "name", "N", "", "Name of the group") addUserToGroupCmd.Flags().StringP("role", "R", "", "Role in the group [owner, maintainer, developer, reporter, guest]") addUserToGroupCmd.Flags().StringVarP(&userEmail, "email", "E", "", "Email address of the user") diff --git a/cmd/list.go b/cmd/list.go index 1382f1be..552c0fb0 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -767,7 +767,7 @@ var listOrganizationDeployTargetsCmd = &cobra.Command{ return err } if organizationName == "" && organizationID == 0 { - return fmt.Errorf("Missing arguments: Organization name or ID is not defined") + return fmt.Errorf("missing arguments: Organization name or ID is not defined") } current := lagoonCLIConfig.Current diff --git a/cmd/project.go b/cmd/project.go index d32506ce..c196c546 100644 --- a/cmd/project.go +++ b/cmd/project.go @@ -464,7 +464,7 @@ var deleteProjectMetadataByKey = &cobra.Command{ }, } -var RemoveProjectFromOrganizationCmd = &cobra.Command{ +var removeProjectFromOrganizationCmd = &cobra.Command{ Use: "organization-project", Aliases: []string{"org-p"}, Short: "Remove a project from an Organization", @@ -575,5 +575,5 @@ func init() { getCmd.AddCommand(getProjectMetadata) - RemoveProjectFromOrganizationCmd.Flags().StringP("organization", "O", "", "Name of the Organization to remove the project from") + removeProjectFromOrganizationCmd.Flags().StringP("organization", "O", "", "Name of the Organization to remove the project from") } diff --git a/cmd/shared.go b/cmd/shared.go index c41deda1..aacf4e0f 100644 --- a/cmd/shared.go +++ b/cmd/shared.go @@ -99,7 +99,7 @@ func requiredInputCheck(fieldsAndValues ...string) error { value := fieldsAndValues[i+1] if value == "" || value == "0" { - return fmt.Errorf("Missing argument: %s is not defined", field) + return fmt.Errorf("missing argument: %s is not defined", field) } } return nil diff --git a/cmd/users.go b/cmd/users.go index c5ec8d03..a1535213 100644 --- a/cmd/users.go +++ b/cmd/users.go @@ -370,6 +370,7 @@ var addAdministratorToOrganizationCmd = &cobra.Command{ Use: "organization-administrator", Aliases: []string{"org-admin"}, Short: "Add an administrator to an Organization", + Long: "Add an administrator to an Organization. If the owner flag is not provided users will be added as viewers", PreRunE: func(_ *cobra.Command, _ []string) error { return validateTokenE(lagoonCLIConfig.Current) }, @@ -427,7 +428,7 @@ var addAdministratorToOrganizationCmd = &cobra.Command{ }, } -var RemoveAdministratorFromOrganizationCmd = &cobra.Command{ +var removeAdministratorFromOrganizationCmd = &cobra.Command{ Use: "organization-administrator", Aliases: []string{"org-admin"}, Short: "Remove an administrator from an Organization", @@ -517,7 +518,7 @@ func init() { addAdministratorToOrganizationCmd.Flags().StringP("name", "O", "", "Name of the organization") addAdministratorToOrganizationCmd.Flags().StringP("email", "E", "", "Email address of the user") addAdministratorToOrganizationCmd.Flags().Bool("owner", false, "Set the user as an owner of the organization") - RemoveAdministratorFromOrganizationCmd.Flags().StringP("name", "O", "", "Name of the organization") - RemoveAdministratorFromOrganizationCmd.Flags().StringP("email", "E", "", "Email address of the user") - RemoveAdministratorFromOrganizationCmd.Flags().Bool("owner", false, "Set the user as an owner of the organization") + removeAdministratorFromOrganizationCmd.Flags().StringP("name", "O", "", "Name of the organization") + removeAdministratorFromOrganizationCmd.Flags().StringP("email", "E", "", "Email address of the user") + removeAdministratorFromOrganizationCmd.Flags().Bool("owner", false, "Set the user as an administrator of the organization") } diff --git a/docs/commands/lagoon_add.md b/docs/commands/lagoon_add.md index f5e36774..26664405 100644 --- a/docs/commands/lagoon_add.md +++ b/docs/commands/lagoon_add.md @@ -30,7 +30,7 @@ Add a project, or add notifications and variables to projects or environments * [lagoon](lagoon.md) - Command line integration for Lagoon * [lagoon add deploytarget](lagoon_add_deploytarget.md) - Add a DeployTarget to lagoon * [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 group](lagoon_add_group.md) - Add a group to lagoon, or add a group to an organization * [lagoon add notification](lagoon_add_notification.md) - Add notifications or add notifications to projects * [lagoon add organization](lagoon_add_organization.md) - Add a new organization to Lagoon * [lagoon add organization-administrator](lagoon_add_organization-administrator.md) - Add an administrator to an Organization diff --git a/docs/commands/lagoon_add_group.md b/docs/commands/lagoon_add_group.md index 40079fc5..da71c555 100644 --- a/docs/commands/lagoon_add_group.md +++ b/docs/commands/lagoon_add_group.md @@ -1,6 +1,11 @@ ## lagoon add group -Add a group to lagoon +Add a group to lagoon, or add a group to an organization + +### Synopsis + +To add a group to an organization, you'll need to include the `organization` flag and provide the name of the organization. You need to be an owner of this organization to do this. +If you're the organization owner and want to grant yourself ownership to this group to be able to deploy projects that may be added to it, specify the `owner` flag, otherwise you will still be able to add and remove users without being an owner ``` lagoon add group [flags] @@ -11,8 +16,8 @@ lagoon add group [flags] ``` -h, --help help for group -N, --name string Name of the group - --org-owner Flag to add the user to the group as an owner -O, --organization string Name of the organization + --owner Organization owner only: Flag to grant yourself ownership of this group ``` ### Options inherited from parent commands diff --git a/docs/commands/lagoon_add_organization-administrator.md b/docs/commands/lagoon_add_organization-administrator.md index 68d1d2ce..50cc8f98 100644 --- a/docs/commands/lagoon_add_organization-administrator.md +++ b/docs/commands/lagoon_add_organization-administrator.md @@ -2,6 +2,10 @@ Add an administrator to an Organization +### Synopsis + +Add an administrator to an Organization. If the owner flag is not provided users will be added as viewers + ``` lagoon add organization-administrator [flags] ``` diff --git a/docs/commands/lagoon_add_organization-deploytarget.md b/docs/commands/lagoon_add_organization-deploytarget.md index a9a6d6ee..653d76fc 100644 --- a/docs/commands/lagoon_add_organization-deploytarget.md +++ b/docs/commands/lagoon_add_organization-deploytarget.md @@ -9,9 +9,9 @@ lagoon add organization-deploytarget [flags] ### Options ``` - -D, --deploy-target uint ID of DeployTarget - -h, --help help for organization-deploytarget - -O, --name string Name of Organization + -D, --deploytarget uint ID of DeployTarget + -h, --help help for organization-deploytarget + -O, --name string Name of Organization ``` ### Options inherited from parent commands diff --git a/docs/commands/lagoon_delete_organization-administrator.md b/docs/commands/lagoon_delete_organization-administrator.md index a5fb4358..c4f0118a 100644 --- a/docs/commands/lagoon_delete_organization-administrator.md +++ b/docs/commands/lagoon_delete_organization-administrator.md @@ -12,7 +12,7 @@ lagoon delete organization-administrator [flags] -E, --email string Email address of the user -h, --help help for organization-administrator -O, --name string Name of the organization - --owner Set the user as an owner of the organization + --owner Set the user as an administrator of the organization ``` ### Options inherited from parent commands diff --git a/docs/commands/lagoon_delete_organization-deploytarget.md b/docs/commands/lagoon_delete_organization-deploytarget.md index 1f1de984..caf80014 100644 --- a/docs/commands/lagoon_delete_organization-deploytarget.md +++ b/docs/commands/lagoon_delete_organization-deploytarget.md @@ -9,9 +9,9 @@ lagoon delete organization-deploytarget [flags] ### Options ``` - -D, --deploy-target uint ID of DeployTarget - -h, --help help for organization-deploytarget - -O, --name string Name of Organization + -D, --deploytarget uint ID of DeployTarget + -h, --help help for organization-deploytarget + -O, --name string Name of Organization ``` ### Options inherited from parent commands diff --git a/docs/commands/lagoon_deploy_branch.md b/docs/commands/lagoon_deploy_branch.md index 42c277c4..81ac0548 100644 --- a/docs/commands/lagoon_deploy_branch.md +++ b/docs/commands/lagoon_deploy_branch.md @@ -15,11 +15,11 @@ lagoon deploy branch [flags] ### Options ``` - -b, --branch string Branch name to deploy - -r, --branchRef string Branch ref to deploy - --buildvar strings Add one or more build variables to deployment (--buildvar KEY1=VALUE1 [--buildvar KEY2=VALUE2]) - -h, --help help for branch - --returnData Returns the build name instead of success text + -b, --branch string Branch name to deploy + -r, --branchRef string Branch ref to deploy + --buildvar stringArray Add one or more build variables to deployment (--buildvar KEY1=VALUE1 [--buildvar KEY2=VALUE2]) + -h, --help help for branch + --returnData Returns the build name instead of success text ``` ### Options inherited from parent commands diff --git a/docs/commands/lagoon_deploy_latest.md b/docs/commands/lagoon_deploy_latest.md index 5f56e64f..38edfa69 100644 --- a/docs/commands/lagoon_deploy_latest.md +++ b/docs/commands/lagoon_deploy_latest.md @@ -14,9 +14,9 @@ lagoon deploy latest [flags] ### Options ``` - --buildvar strings Add one or more build variables to deployment (--buildvar KEY1=VALUE1 [--buildvar KEY2=VALUE2]) - -h, --help help for latest - --returnData Returns the build name instead of success text + --buildvar stringArray Add one or more build variables to deployment (--buildvar KEY1=VALUE1 [--buildvar KEY2=VALUE2]) + -h, --help help for latest + --returnData Returns the build name instead of success text ``` ### Options inherited from parent commands diff --git a/docs/commands/lagoon_deploy_promote.md b/docs/commands/lagoon_deploy_promote.md index 475cd35e..1a334238 100644 --- a/docs/commands/lagoon_deploy_promote.md +++ b/docs/commands/lagoon_deploy_promote.md @@ -13,11 +13,11 @@ lagoon deploy promote [flags] ### Options ``` - --buildvar strings Add one or more build variables to deployment (--buildvar KEY1=VALUE1 [--buildvar KEY2=VALUE2]) - -d, --destination string Destination environment name to create - -h, --help help for promote - --returnData Returns the build name instead of success text - -s, --source string Source environment name to use as the base to deploy from + --buildvar stringArray Add one or more build variables to deployment (--buildvar KEY1=VALUE1 [--buildvar KEY2=VALUE2]) + -d, --destination string Destination environment name to create + -h, --help help for promote + --returnData Returns the build name instead of success text + -s, --source string Source environment name to use as the base to deploy from ``` ### Options inherited from parent commands diff --git a/docs/commands/lagoon_deploy_pullrequest.md b/docs/commands/lagoon_deploy_pullrequest.md index 901abc23..260f24d3 100644 --- a/docs/commands/lagoon_deploy_pullrequest.md +++ b/docs/commands/lagoon_deploy_pullrequest.md @@ -16,7 +16,7 @@ lagoon deploy pullrequest [flags] ``` -N, --baseBranchName string Pullrequest base branch name -R, --baseBranchRef string Pullrequest base branch reference hash - --buildvar strings Add one or more build variables to deployment (--buildvar KEY1=VALUE1 [--buildvar KEY2=VALUE2]) + --buildvar stringArray Add one or more build variables to deployment (--buildvar KEY1=VALUE1 [--buildvar KEY2=VALUE2]) -H, --headBranchName string Pullrequest head branch name -M, --headBranchRef string Pullrequest head branch reference hash -h, --help help for pullrequest diff --git a/docs/commands/lagoon_update_environment.md b/docs/commands/lagoon_update_environment.md index 4c204f12..eec81629 100644 --- a/docs/commands/lagoon_update_environment.md +++ b/docs/commands/lagoon_update_environment.md @@ -12,9 +12,9 @@ lagoon update environment [flags] -a, --auto-idle uint Auto idle setting of the environment (default 1) --deploy-base-ref string Updates the deploy base ref for the selected environment --deploy-head-ref string Updates the deploy head ref for the selected environment - -d, --deploy-target uint Reference to OpenShift Object this Environment should be deployed to --deploy-title string Updates the deploy title for the selected environment --deploy-type string Update the deploy type - branch | pullrequest | promote + -d, --deploytarget uint Reference to OpenShift Object this Environment should be deployed to --environment-type string Update the environment type - production | development -h, --help help for environment --namespace string Update the namespace for the selected environment From 15f5d627bb1f76de20e30ccf16131486fd0195e2 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 12 Apr 2024 08:11:13 +1000 Subject: [PATCH 6/9] chore: fix up wording for projects to reflect other changes --- cmd/groups.go | 2 +- cmd/project.go | 8 +++++--- docs/commands/lagoon_add.md | 4 ++-- docs/commands/lagoon_add_group.md | 2 +- docs/commands/lagoon_add_project.md | 9 +++++++-- docs/commands/lagoon_delete_organization-project.md | 5 +++++ 6 files changed, 21 insertions(+), 9 deletions(-) diff --git a/cmd/groups.go b/cmd/groups.go index 0248e547..3bf22a4b 100644 --- a/cmd/groups.go +++ b/cmd/groups.go @@ -33,7 +33,7 @@ func parseGroup(flags pflag.FlagSet) api.Group { var addGroupCmd = &cobra.Command{ Use: "group", Aliases: []string{"g"}, - Short: "Add a group to lagoon, or add a group to an organization", + Short: "Add a group to Lagoon, or add a group to an organization", Long: "To add a group to an organization, you'll need to include the `organization` flag and provide the name of the organization. You need to be an owner of this organization to do this.\nIf you're the organization owner and want to grant yourself ownership to this group to be able to deploy projects that may be added to it, specify the `owner` flag, otherwise you will still be able to add and remove users without being an owner", PreRunE: func(_ *cobra.Command, _ []string) error { return validateTokenE(lagoonCLIConfig.Current) diff --git a/cmd/project.go b/cmd/project.go index c196c546..b6f485aa 100644 --- a/cmd/project.go +++ b/cmd/project.go @@ -66,7 +66,8 @@ var deleteProjectCmd = &cobra.Command{ var addProjectCmd = &cobra.Command{ Use: "project", Aliases: []string{"p"}, - Short: "Add a new project to Lagoon", + Short: "Add a new project to Lagoon, or add a project to an organization", + Long: "To add a project to an organization, you'll need to include the `organization` flag and provide the name of the organization. You need to be an owner of this organization to do this.\nIf you're the organization owner and want to grant yourself ownership to this project to be able to deploy environments, specify the `owner` flag.", PreRunE: func(_ *cobra.Command, _ []string) error { return validateTokenE(lagoonCLIConfig.Current) }, @@ -126,7 +127,7 @@ var addProjectCmd = &cobra.Command{ if err != nil { return err } - orgOwner, err := cmd.Flags().GetBool("org-owner") + orgOwner, err := cmd.Flags().GetBool("owner") if err != nil { return err } @@ -468,6 +469,7 @@ var removeProjectFromOrganizationCmd = &cobra.Command{ Use: "organization-project", Aliases: []string{"org-p"}, Short: "Remove a project from an Organization", + Long: "Removes a project from an Organization, but does not delete the project.\nThis is used by platform administrators to be able to reset a project.", PreRunE: func(_ *cobra.Command, _ []string) error { return validateTokenE(lagoonCLIConfig.Current) }, @@ -558,7 +560,7 @@ func init() { addProjectCmd.Flags().UintP("storageCalc", "C", 0, "Should storage for this environment be calculated") addProjectCmd.Flags().UintP("developmentEnvironmentsLimit", "L", 0, "How many environments can be deployed at one time") addProjectCmd.Flags().UintP("openshift", "S", 0, "Reference to OpenShift Object this Project should be deployed to") - addProjectCmd.Flags().Bool("org-owner", false, "Add the user as an owner of the project") + addProjectCmd.Flags().Bool("owner", false, "Add the user as an owner of the project") addProjectCmd.Flags().StringP("organization", "O", "", "Name of the Organization to add the project to") listCmd.AddCommand(listProjectByMetadata) diff --git a/docs/commands/lagoon_add.md b/docs/commands/lagoon_add.md index 26664405..e600bac5 100644 --- a/docs/commands/lagoon_add.md +++ b/docs/commands/lagoon_add.md @@ -30,12 +30,12 @@ Add a project, or add notifications and variables to projects or environments * [lagoon](lagoon.md) - Command line integration for Lagoon * [lagoon add deploytarget](lagoon_add_deploytarget.md) - Add a DeployTarget to lagoon * [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, or add a group to an organization +* [lagoon add group](lagoon_add_group.md) - Add a group to Lagoon, or add a group to an organization * [lagoon add notification](lagoon_add_notification.md) - Add notifications or add notifications to projects * [lagoon add organization](lagoon_add_organization.md) - Add a new organization to Lagoon * [lagoon add organization-administrator](lagoon_add_organization-administrator.md) - Add an administrator to an Organization * [lagoon add organization-deploytarget](lagoon_add_organization-deploytarget.md) - Add a deploy target to an Organization -* [lagoon add project](lagoon_add_project.md) - Add a new project to Lagoon +* [lagoon add project](lagoon_add_project.md) - Add a new project to Lagoon, or add a project to an organization * [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 * [lagoon add user-group](lagoon_add_user-group.md) - Add a user to a group in lagoon diff --git a/docs/commands/lagoon_add_group.md b/docs/commands/lagoon_add_group.md index da71c555..4ae2528d 100644 --- a/docs/commands/lagoon_add_group.md +++ b/docs/commands/lagoon_add_group.md @@ -1,6 +1,6 @@ ## lagoon add group -Add a group to lagoon, or add a group to an organization +Add a group to Lagoon, or add a group to an organization ### Synopsis diff --git a/docs/commands/lagoon_add_project.md b/docs/commands/lagoon_add_project.md index 7967dc25..cd54961d 100644 --- a/docs/commands/lagoon_add_project.md +++ b/docs/commands/lagoon_add_project.md @@ -1,6 +1,11 @@ ## lagoon add project -Add a new project to Lagoon +Add a new project to Lagoon, or add a project to an organization + +### Synopsis + +To add a project to an organization, you'll need to include the `organization` flag and provide the name of the organization. You need to be an owner of this organization to do this. +If you're the organization owner and want to grant yourself ownership to this project to be able to deploy environments, specify the `owner` flag. ``` lagoon add project [flags] @@ -17,8 +22,8 @@ lagoon add project [flags] -j, --json string JSON string to patch -S, --openshift uint Reference to OpenShift Object this Project should be deployed to -o, --openshiftProjectPattern string Pattern of OpenShift Project/Namespace that should be generated - --org-owner Add the user as an owner of the project -O, --organization string Name of the Organization to add the project to + --owner Add the user as an owner of the project -I, --privateKey string Private key to use for the project -E, --productionEnvironment string Which environment(the name) should be marked as the production environment -m, --pullrequests string Which Pull Requests should be deployed diff --git a/docs/commands/lagoon_delete_organization-project.md b/docs/commands/lagoon_delete_organization-project.md index 46198a2b..c0e5df1e 100644 --- a/docs/commands/lagoon_delete_organization-project.md +++ b/docs/commands/lagoon_delete_organization-project.md @@ -2,6 +2,11 @@ Remove a project from an Organization +### Synopsis + +Removes a project from an Organization, but does not delete the project. +This is used by platform administrators to be able to reset a project. + ``` lagoon delete organization-project [flags] ``` From 2fcc9c741e8a8a7421cd60451aa0694bcd6885ba Mon Sep 17 00:00:00 2001 From: cgoodwin90 Date: Fri, 17 May 2024 14:38:36 +1000 Subject: [PATCH 7/9] Updates error handling --- cmd/deploytarget.go | 24 ++++++++++++++++++------ cmd/get.go | 4 +++- cmd/groups.go | 16 ++++++++++++---- cmd/list.go | 12 +++++++++--- cmd/organization.go | 12 +++++++++--- cmd/project.go | 28 +++++++++++++++++++++------- cmd/shared.go | 9 +++++++++ cmd/users.go | 24 ++++++++++++++++++------ 8 files changed, 99 insertions(+), 30 deletions(-) diff --git a/cmd/deploytarget.go b/cmd/deploytarget.go index 4d7bc93c..527819e0 100644 --- a/cmd/deploytarget.go +++ b/cmd/deploytarget.go @@ -332,7 +332,9 @@ var addDeployTargetToOrganizationCmd = &cobra.Command{ }, RunE: func(cmd *cobra.Command, args []string) error { debug, err := cmd.Flags().GetBool("debug") - handleError(err) + if err != nil { + return err + } organizationName, err := cmd.Flags().GetString("name") if err != nil { return err @@ -356,7 +358,9 @@ var addDeployTargetToOrganizationCmd = &cobra.Command{ debug) organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc) - handleError(err) + if err := handleErr(err); err != nil { + return nil + } deployTargetInput := s.AddDeployTargetToOrganizationInput{ DeployTarget: deploytarget, @@ -364,7 +368,9 @@ var addDeployTargetToOrganizationCmd = &cobra.Command{ } deployTargetResponse, err := l.AddDeployTargetToOrganization(context.TODO(), &deployTargetInput, lc) - handleError(err) + if err := handleErr(err); err != nil { + return nil + } resultData := output.Result{ Result: "success", ResultData: map[string]interface{}{ @@ -386,7 +392,9 @@ var removeDeployTargetFromOrganizationCmd = &cobra.Command{ }, RunE: func(cmd *cobra.Command, args []string) error { debug, err := cmd.Flags().GetBool("debug") - handleError(err) + if err != nil { + return err + } organizationName, err := cmd.Flags().GetString("name") if err != nil { @@ -413,7 +421,9 @@ var removeDeployTargetFromOrganizationCmd = &cobra.Command{ debug) organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc) - handleError(err) + if err := handleErr(err); err != nil { + return nil + } deployTargetInput := s.RemoveDeployTargetFromOrganizationInput{ DeployTarget: deploytarget, @@ -422,7 +432,9 @@ var removeDeployTargetFromOrganizationCmd = &cobra.Command{ if yesNo(fmt.Sprintf("You are attempting to remove deploy target '%d' from organization '%s', are you sure?", deploytarget, organization.Name)) { _, err := l.RemoveDeployTargetFromOrganization(context.TODO(), &deployTargetInput, lc) - handleError(err) + if err := handleErr(err); err != nil { + return nil + } resultData := output.Result{ Result: "success", ResultData: map[string]interface{}{ diff --git a/cmd/get.go b/cmd/get.go index 6f067d99..5e2c1820 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -285,7 +285,9 @@ var getOrganizationCmd = &cobra.Command{ &token, debug) organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc) - handleError(err) + if err != nil { + return err + } if organization.Name == "" { output.RenderInfo(fmt.Sprintf("No organization found for '%s'", organizationName), outputOptions) diff --git a/cmd/groups.go b/cmd/groups.go index 3bf22a4b..c0ac6d9f 100644 --- a/cmd/groups.go +++ b/cmd/groups.go @@ -40,7 +40,9 @@ var addGroupCmd = &cobra.Command{ }, RunE: func(cmd *cobra.Command, args []string) error { debug, err := cmd.Flags().GetBool("debug") - handleError(err) + if err != nil { + return err + } groupName, err := cmd.Flags().GetString("name") if err != nil { return err @@ -68,20 +70,26 @@ var addGroupCmd = &cobra.Command{ if organizationName != "" { organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc) - handleError(err) + if err := handleErr(err); err != nil { + return nil + } groupInput := s.AddGroupToOrganizationInput{ Name: groupName, Organization: organization.ID, AddOrgOwner: orgOwner, } _, err = l.AddGroupToOrganization(context.TODO(), &groupInput, lc) - handleError(err) + if err := handleErr(err); err != nil { + return nil + } } else { groupInput := s.AddGroupInput{ Name: groupName, } _, err = l.AddGroup(context.TODO(), &groupInput, lc) - handleError(err) + if err := handleErr(err); err != nil { + return nil + } } resultData := output.Result{ diff --git a/cmd/list.go b/cmd/list.go index 552c0fb0..1b868ccb 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -779,7 +779,9 @@ var listOrganizationDeployTargetsCmd = &cobra.Command{ &token, debug) deployTargets, err := l.ListDeployTargetsByOrganizationNameOrID(context.TODO(), nullStrCheck(organizationName), nullUintCheck(organizationID), lc) - handleError(err) + if err := handleErr(err); err != nil { + return nil + } if len(*deployTargets) == 0 { outputOptions.Error = fmt.Sprintf("No associated deploy targets found for organization '%s'\n", organizationName) } @@ -834,9 +836,13 @@ var ListOrganizationUsersCmd = &cobra.Command{ &token, debug) organization, err := l.GetOrganizationByName(context.Background(), organizationName, lc) - handleError(err) + if err := handleErr(err); err != nil { + return nil + } users, err := l.UsersByOrganization(context.TODO(), organization.ID, lc) - handleError(err) + if err := handleErr(err); err != nil { + return nil + } data := []output.Data{} for _, user := range *users { diff --git a/cmd/organization.go b/cmd/organization.go index e69587ed..b6e0e1d1 100644 --- a/cmd/organization.go +++ b/cmd/organization.go @@ -80,7 +80,9 @@ var addOrganizationCmd = &cobra.Command{ } org := s.Organization{} err = lc.AddOrganization(context.TODO(), &organizationInput, &org) - handleError(err) + if err := handleErr(err); err != nil { + return nil + } resultData := output.Result{ Result: "success", @@ -123,10 +125,14 @@ var deleteOrganizationCmd = &cobra.Command{ debug) organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc) - handleError(err) + if err := handleErr(err); err != nil { + return nil + } if yesNo(fmt.Sprintf("You are attempting to delete organization '%s', are you sure?", organization.Name)) { _, err := l.DeleteOrganization(context.TODO(), organization.ID, lc) - handleError(err) + if err := handleErr(err); err != nil { + return nil + } resultData := output.Result{ Result: organization.Name, } diff --git a/cmd/project.go b/cmd/project.go index b6f485aa..9ec1c1ac 100644 --- a/cmd/project.go +++ b/cmd/project.go @@ -73,7 +73,9 @@ var addProjectCmd = &cobra.Command{ }, RunE: func(cmd *cobra.Command, args []string) error { debug, err := cmd.Flags().GetBool("debug") - handleError(err) + if err != nil { + return err + } organizationName, err := cmd.Flags().GetString("organization") if err != nil { @@ -169,13 +171,17 @@ var addProjectCmd = &cobra.Command{ if organizationName != "" { organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc) - handleError(err) + if err := handleErr(err); err != nil { + return nil + } projectInput.Organization = organization.ID } project := s.Project{} err = lc.AddProject(context.TODO(), &projectInput, &project) - handleError(err) + if err := handleErr(err); err != nil { + return nil + } resultData := output.Result{ Result: "success", ResultData: map[string]interface{}{ @@ -475,7 +481,9 @@ var removeProjectFromOrganizationCmd = &cobra.Command{ }, RunE: func(cmd *cobra.Command, args []string) error { debug, err := cmd.Flags().GetBool("debug") - handleError(err) + if err != nil { + return err + } organizationName, err := cmd.Flags().GetString("organization") if err != nil { @@ -495,9 +503,13 @@ var removeProjectFromOrganizationCmd = &cobra.Command{ debug) project, err := l.GetMinimalProjectByName(context.TODO(), cmdProjectName, lc) - handleError(err) + if err := handleErr(err); err != nil { + return nil + } organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc) - handleError(err) + if err := handleErr(err); err != nil { + return nil + } projectInput := s.RemoveProjectFromOrganizationInput{ Project: project.ID, @@ -506,7 +518,9 @@ var removeProjectFromOrganizationCmd = &cobra.Command{ if yesNo(fmt.Sprintf("You are attempting to remove project '%s' from organization '%s'. This will return the project to a state where it has no groups or notifications associated, are you sure?", cmdProjectName, organization.Name)) { _, err := l.RemoveProjectFromOrganization(context.TODO(), &projectInput, lc) - handleError(err) + if err := handleErr(err); err != nil { + return nil + } resultData := output.Result{ Result: "success", ResultData: map[string]interface{}{ diff --git a/cmd/shared.go b/cmd/shared.go index 1d28cbc3..8500f653 100644 --- a/cmd/shared.go +++ b/cmd/shared.go @@ -53,6 +53,15 @@ func handleError(err error) { } } +func handleErr(err error) error { + if err != nil { + outputOptions.Error = err.Error() + output.RenderError(outputOptions.Error, outputOptions) + return err + } + return nil +} + func returnNonEmptyString(value string) string { if len(value) == 0 { return "-" diff --git a/cmd/users.go b/cmd/users.go index 965def99..499cdd8b 100644 --- a/cmd/users.go +++ b/cmd/users.go @@ -376,7 +376,9 @@ var addAdministratorToOrganizationCmd = &cobra.Command{ }, RunE: func(cmd *cobra.Command, args []string) error { debug, err := cmd.Flags().GetBool("debug") - handleError(err) + if err != nil { + return err + } organizationName, err := cmd.Flags().GetString("name") if err != nil { @@ -404,7 +406,9 @@ var addAdministratorToOrganizationCmd = &cobra.Command{ debug) organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc) - handleError(err) + if err := handleErr(err); err != nil { + return nil + } userInput := s.AddUserToOrganizationInput{ User: s.UserInput{Email: userEmail}, @@ -414,7 +418,9 @@ var addAdministratorToOrganizationCmd = &cobra.Command{ orgUser := s.Organization{} err = lc.AddUserToOrganization(context.TODO(), &userInput, &orgUser) - handleError(err) + if err := handleErr(err); err != nil { + return nil + } resultData := output.Result{ Result: "success", @@ -437,7 +443,9 @@ var removeAdministratorFromOrganizationCmd = &cobra.Command{ }, RunE: func(cmd *cobra.Command, args []string) error { debug, err := cmd.Flags().GetBool("debug") - handleError(err) + if err != nil { + return err + } organizationName, err := cmd.Flags().GetString("name") if err != nil { @@ -468,7 +476,9 @@ var removeAdministratorFromOrganizationCmd = &cobra.Command{ debug) organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc) - handleError(err) + if err := handleErr(err); err != nil { + return nil + } userInput := s.AddUserToOrganizationInput{ User: s.UserInput{Email: userEmail}, @@ -480,7 +490,9 @@ var removeAdministratorFromOrganizationCmd = &cobra.Command{ if yesNo(fmt.Sprintf("You are attempting to remove user '%s' from organization '%s'. This removes the users ability to view or manage the organizations groups, projects, & notifications, are you sure?", userEmail, organization.Name)) { err = lc.RemoveUserFromOrganization(context.TODO(), &userInput, &orgUser) - handleError(err) + if err := handleErr(err); err != nil { + return nil + } resultData := output.Result{ Result: "success", ResultData: map[string]interface{}{ From d8666407460dd59706caf7ce926b9958be0dc0d2 Mon Sep 17 00:00:00 2001 From: cgoodwin90 Date: Mon, 20 May 2024 16:13:20 +1000 Subject: [PATCH 8/9] Updated err handling --- cmd/deploytarget.go | 21 +++++++++------------ cmd/groups.go | 12 ++++++------ cmd/list.go | 12 ++++++------ cmd/organization.go | 12 ++++++------ cmd/project.go | 20 ++++++++++---------- cmd/shared.go | 9 --------- cmd/users.go | 16 ++++++++-------- 7 files changed, 45 insertions(+), 57 deletions(-) diff --git a/cmd/deploytarget.go b/cmd/deploytarget.go index 527819e0..4737cd30 100644 --- a/cmd/deploytarget.go +++ b/cmd/deploytarget.go @@ -358,8 +358,8 @@ var addDeployTargetToOrganizationCmd = &cobra.Command{ debug) organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc) - if err := handleErr(err); err != nil { - return nil + if err != nil { + return err } deployTargetInput := s.AddDeployTargetToOrganizationInput{ @@ -368,8 +368,8 @@ var addDeployTargetToOrganizationCmd = &cobra.Command{ } deployTargetResponse, err := l.AddDeployTargetToOrganization(context.TODO(), &deployTargetInput, lc) - if err := handleErr(err); err != nil { - return nil + if err != nil { + return err } resultData := output.Result{ Result: "success", @@ -400,14 +400,11 @@ var removeDeployTargetFromOrganizationCmd = &cobra.Command{ if err != nil { return err } - if err := requiredInputCheck("Organization name", organizationName); err != nil { - return err - } deploytarget, err := cmd.Flags().GetUint("deploytarget") if err != nil { return err } - if err := requiredInputCheck("Deploy Target", strconv.Itoa(int(deploytarget))); err != nil { + if err := requiredInputCheck("Organization name", organizationName, "Deploy Target", strconv.Itoa(int(deploytarget))); err != nil { return err } @@ -421,8 +418,8 @@ var removeDeployTargetFromOrganizationCmd = &cobra.Command{ debug) organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc) - if err := handleErr(err); err != nil { - return nil + if err != nil { + return err } deployTargetInput := s.RemoveDeployTargetFromOrganizationInput{ @@ -432,8 +429,8 @@ var removeDeployTargetFromOrganizationCmd = &cobra.Command{ if yesNo(fmt.Sprintf("You are attempting to remove deploy target '%d' from organization '%s', are you sure?", deploytarget, organization.Name)) { _, err := l.RemoveDeployTargetFromOrganization(context.TODO(), &deployTargetInput, lc) - if err := handleErr(err); err != nil { - return nil + if err != nil { + return err } resultData := output.Result{ Result: "success", diff --git a/cmd/groups.go b/cmd/groups.go index c0ac6d9f..dead8180 100644 --- a/cmd/groups.go +++ b/cmd/groups.go @@ -70,8 +70,8 @@ var addGroupCmd = &cobra.Command{ if organizationName != "" { organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc) - if err := handleErr(err); err != nil { - return nil + if err != nil { + return err } groupInput := s.AddGroupToOrganizationInput{ Name: groupName, @@ -79,16 +79,16 @@ var addGroupCmd = &cobra.Command{ AddOrgOwner: orgOwner, } _, err = l.AddGroupToOrganization(context.TODO(), &groupInput, lc) - if err := handleErr(err); err != nil { - return nil + if err != nil { + return err } } else { groupInput := s.AddGroupInput{ Name: groupName, } _, err = l.AddGroup(context.TODO(), &groupInput, lc) - if err := handleErr(err); err != nil { - return nil + if err != nil { + return err } } diff --git a/cmd/list.go b/cmd/list.go index 1b868ccb..06b5f537 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -779,8 +779,8 @@ var listOrganizationDeployTargetsCmd = &cobra.Command{ &token, debug) deployTargets, err := l.ListDeployTargetsByOrganizationNameOrID(context.TODO(), nullStrCheck(organizationName), nullUintCheck(organizationID), lc) - if err := handleErr(err); err != nil { - return nil + if err != nil { + return err } if len(*deployTargets) == 0 { outputOptions.Error = fmt.Sprintf("No associated deploy targets found for organization '%s'\n", organizationName) @@ -836,12 +836,12 @@ var ListOrganizationUsersCmd = &cobra.Command{ &token, debug) organization, err := l.GetOrganizationByName(context.Background(), organizationName, lc) - if err := handleErr(err); err != nil { - return nil + if err != nil { + return err } users, err := l.UsersByOrganization(context.TODO(), organization.ID, lc) - if err := handleErr(err); err != nil { - return nil + if err != nil { + return err } data := []output.Data{} diff --git a/cmd/organization.go b/cmd/organization.go index b6e0e1d1..94fa2f70 100644 --- a/cmd/organization.go +++ b/cmd/organization.go @@ -80,8 +80,8 @@ var addOrganizationCmd = &cobra.Command{ } org := s.Organization{} err = lc.AddOrganization(context.TODO(), &organizationInput, &org) - if err := handleErr(err); err != nil { - return nil + if err != nil { + return err } resultData := output.Result{ @@ -125,13 +125,13 @@ var deleteOrganizationCmd = &cobra.Command{ debug) organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc) - if err := handleErr(err); err != nil { - return nil + if err != nil { + return err } if yesNo(fmt.Sprintf("You are attempting to delete organization '%s', are you sure?", organization.Name)) { _, err := l.DeleteOrganization(context.TODO(), organization.ID, lc) - if err := handleErr(err); err != nil { - return nil + if err != nil { + return err } resultData := output.Result{ Result: organization.Name, diff --git a/cmd/project.go b/cmd/project.go index 9ec1c1ac..86b4e6dc 100644 --- a/cmd/project.go +++ b/cmd/project.go @@ -171,16 +171,16 @@ var addProjectCmd = &cobra.Command{ if organizationName != "" { organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc) - if err := handleErr(err); err != nil { - return nil + if err != nil { + return err } projectInput.Organization = organization.ID } project := s.Project{} err = lc.AddProject(context.TODO(), &projectInput, &project) - if err := handleErr(err); err != nil { - return nil + if err != nil { + return err } resultData := output.Result{ Result: "success", @@ -503,12 +503,12 @@ var removeProjectFromOrganizationCmd = &cobra.Command{ debug) project, err := l.GetMinimalProjectByName(context.TODO(), cmdProjectName, lc) - if err := handleErr(err); err != nil { - return nil + if err != nil { + return err } organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc) - if err := handleErr(err); err != nil { - return nil + if err != nil { + return err } projectInput := s.RemoveProjectFromOrganizationInput{ @@ -518,8 +518,8 @@ var removeProjectFromOrganizationCmd = &cobra.Command{ if yesNo(fmt.Sprintf("You are attempting to remove project '%s' from organization '%s'. This will return the project to a state where it has no groups or notifications associated, are you sure?", cmdProjectName, organization.Name)) { _, err := l.RemoveProjectFromOrganization(context.TODO(), &projectInput, lc) - if err := handleErr(err); err != nil { - return nil + if err != nil { + return err } resultData := output.Result{ Result: "success", diff --git a/cmd/shared.go b/cmd/shared.go index 8500f653..1d28cbc3 100644 --- a/cmd/shared.go +++ b/cmd/shared.go @@ -53,15 +53,6 @@ func handleError(err error) { } } -func handleErr(err error) error { - if err != nil { - outputOptions.Error = err.Error() - output.RenderError(outputOptions.Error, outputOptions) - return err - } - return nil -} - func returnNonEmptyString(value string) string { if len(value) == 0 { return "-" diff --git a/cmd/users.go b/cmd/users.go index 499cdd8b..09b78b78 100644 --- a/cmd/users.go +++ b/cmd/users.go @@ -406,8 +406,8 @@ var addAdministratorToOrganizationCmd = &cobra.Command{ debug) organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc) - if err := handleErr(err); err != nil { - return nil + if err != nil { + return err } userInput := s.AddUserToOrganizationInput{ @@ -418,8 +418,8 @@ var addAdministratorToOrganizationCmd = &cobra.Command{ orgUser := s.Organization{} err = lc.AddUserToOrganization(context.TODO(), &userInput, &orgUser) - if err := handleErr(err); err != nil { - return nil + if err != nil { + return err } resultData := output.Result{ @@ -476,8 +476,8 @@ var removeAdministratorFromOrganizationCmd = &cobra.Command{ debug) organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc) - if err := handleErr(err); err != nil { - return nil + if err != nil { + return err } userInput := s.AddUserToOrganizationInput{ @@ -490,8 +490,8 @@ var removeAdministratorFromOrganizationCmd = &cobra.Command{ if yesNo(fmt.Sprintf("You are attempting to remove user '%s' from organization '%s'. This removes the users ability to view or manage the organizations groups, projects, & notifications, are you sure?", userEmail, organization.Name)) { err = lc.RemoveUserFromOrganization(context.TODO(), &userInput, &orgUser) - if err := handleErr(err); err != nil { - return nil + if err != nil { + return err } resultData := output.Result{ Result: "success", From 4bfbd2007d0453afe09df5ac9fd9cf84da0d0168 Mon Sep 17 00:00:00 2001 From: cgoodwin90 Date: Wed, 29 May 2024 10:38:41 +1000 Subject: [PATCH 9/9] Updated organization flag --- cmd/deploytarget.go | 8 ++++---- cmd/get.go | 4 ++-- cmd/groups.go | 4 ++-- cmd/list.go | 16 ++++++++-------- cmd/organization.go | 12 ++++++------ cmd/project.go | 8 ++++---- cmd/users.go | 8 ++++---- docs/commands/lagoon_add_group.md | 8 ++++---- .../lagoon_add_organization-administrator.md | 8 ++++---- .../lagoon_add_organization-deploytarget.md | 6 +++--- docs/commands/lagoon_add_organization.md | 18 +++++++++--------- docs/commands/lagoon_add_project.md | 2 +- ...lagoon_delete_organization-administrator.md | 8 ++++---- .../lagoon_delete_organization-deploytarget.md | 6 +++--- .../lagoon_delete_organization-project.md | 4 ++-- docs/commands/lagoon_delete_organization.md | 4 ++-- docs/commands/lagoon_get_organization.md | 4 ++-- .../lagoon_list_organization-deploytargets.md | 6 +++--- .../lagoon_list_organization-groups.md | 4 ++-- .../lagoon_list_organization-projects.md | 4 ++-- .../commands/lagoon_list_organization-users.md | 4 ++-- docs/commands/lagoon_update_organization.md | 18 +++++++++--------- 22 files changed, 82 insertions(+), 82 deletions(-) diff --git a/cmd/deploytarget.go b/cmd/deploytarget.go index 4737cd30..b2b7892e 100644 --- a/cmd/deploytarget.go +++ b/cmd/deploytarget.go @@ -335,7 +335,7 @@ var addDeployTargetToOrganizationCmd = &cobra.Command{ if err != nil { return err } - organizationName, err := cmd.Flags().GetString("name") + organizationName, err := cmd.Flags().GetString("organization-name") if err != nil { return err } @@ -396,7 +396,7 @@ var removeDeployTargetFromOrganizationCmd = &cobra.Command{ return err } - organizationName, err := cmd.Flags().GetString("name") + organizationName, err := cmd.Flags().GetString("organization-name") if err != nil { return err } @@ -458,13 +458,13 @@ func init() { addDeployTargetCmd.Flags().StringP("ssh-port", "", "", "DeployTarget ssh port") addDeployTargetCmd.Flags().StringP("build-image", "", "", "DeployTarget build image to use (if different to the default)") - addDeployTargetToOrganizationCmd.Flags().StringP("name", "O", "", "Name of Organization") + addDeployTargetToOrganizationCmd.Flags().StringP("organization-name", "O", "", "Name of Organization") addDeployTargetToOrganizationCmd.Flags().UintP("deploytarget", "D", 0, "ID of DeployTarget") deleteDeployTargetCmd.Flags().UintP("id", "", 0, "ID of the DeployTarget") deleteDeployTargetCmd.Flags().StringP("name", "", "", "Name of DeployTarget") - removeDeployTargetFromOrganizationCmd.Flags().StringP("name", "O", "", "Name of Organization") + removeDeployTargetFromOrganizationCmd.Flags().StringP("organization-name", "O", "", "Name of Organization") removeDeployTargetFromOrganizationCmd.Flags().UintP("deploytarget", "D", 0, "ID of DeployTarget") updateDeployTargetCmd.Flags().UintP("id", "", 0, "ID of the DeployTarget") diff --git a/cmd/get.go b/cmd/get.go index 5e2c1820..d4f38264 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -268,7 +268,7 @@ var getOrganizationCmd = &cobra.Command{ if err != nil { return err } - organizationName, err := cmd.Flags().GetString("name") + organizationName, err := cmd.Flags().GetString("organization-name") if err != nil { return err } @@ -329,5 +329,5 @@ func init() { getProjectKeyCmd.Flags().BoolVarP(&revealValue, "reveal", "", false, "Reveal the variable values") getDeploymentByNameCmd.Flags().StringP("name", "N", "", "The name of the deployment (eg, lagoon-build-abcdef)") getDeploymentByNameCmd.Flags().BoolP("logs", "L", false, "Show the build logs if available") - getOrganizationCmd.Flags().StringP("name", "O", "", "Name of the organization") + getOrganizationCmd.Flags().StringP("organization-name", "O", "", "Name of the organization") } diff --git a/cmd/groups.go b/cmd/groups.go index dead8180..6a1c0622 100644 --- a/cmd/groups.go +++ b/cmd/groups.go @@ -54,7 +54,7 @@ var addGroupCmd = &cobra.Command{ if err != nil { return err } - organizationName, err := cmd.Flags().GetString("organization") + organizationName, err := cmd.Flags().GetString("organization-name") if err != nil { return err } @@ -288,7 +288,7 @@ var deleteGroupCmd = &cobra.Command{ func init() { addGroupCmd.Flags().StringP("name", "N", "", "Name of the group") - addGroupCmd.Flags().StringP("organization", "O", "", "Name of the organization") + addGroupCmd.Flags().StringP("organization-name", "O", "", "Name of the organization") addGroupCmd.Flags().Bool("owner", false, "Organization owner only: Flag to grant yourself ownership of this group") addUserToGroupCmd.Flags().StringVarP(&groupName, "name", "N", "", "Name of the group") addUserToGroupCmd.Flags().StringP("role", "R", "", "Role in the group [owner, maintainer, developer, reporter, guest]") diff --git a/cmd/list.go b/cmd/list.go index 06b5f537..46695b51 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -640,7 +640,7 @@ var listOrganizationProjectsCmd = &cobra.Command{ if err != nil { return err } - organizationName, err := cmd.Flags().GetString("organization") + organizationName, err := cmd.Flags().GetString("organization-name") if err != nil { return err } @@ -699,7 +699,7 @@ var listOrganizationGroupsCmd = &cobra.Command{ if err != nil { return err } - organizationName, err := cmd.Flags().GetString("organization") + organizationName, err := cmd.Flags().GetString("organization-name") if err != nil { return err } @@ -758,7 +758,7 @@ var listOrganizationDeployTargetsCmd = &cobra.Command{ if err != nil { return err } - organizationName, err := cmd.Flags().GetString("organization") + organizationName, err := cmd.Flags().GetString("organization-name") if err != nil { return err } @@ -819,7 +819,7 @@ var ListOrganizationUsersCmd = &cobra.Command{ if err != nil { return err } - organizationName, err := cmd.Flags().GetString("organization") + organizationName, err := cmd.Flags().GetString("organization-name") if err != nil { return err } @@ -941,9 +941,9 @@ func init() { listUsersCmd.Flags().StringVarP(&groupName, "name", "N", "", "Name of the group to list users in") listGroupProjectsCmd.Flags().StringVarP(&groupName, "name", "N", "", "Name of the group to list projects in") listVariablesCmd.Flags().BoolP("reveal", "", false, "Reveal the variable values") - listOrganizationProjectsCmd.Flags().StringP("organization", "O", "", "Name of the organization to list associated projects for") - ListOrganizationUsersCmd.Flags().StringP("organization", "O", "", "Name of the organization to list associated users for") - listOrganizationGroupsCmd.Flags().StringP("organization", "O", "", "Name of the organization to list associated groups for") - listOrganizationDeployTargetsCmd.Flags().StringP("organization", "O", "", "Name of the organization to list associated deploy targets for") + listOrganizationProjectsCmd.Flags().StringP("organization-name", "O", "", "Name of the organization to list associated projects for") + ListOrganizationUsersCmd.Flags().StringP("organization-name", "O", "", "Name of the organization to list associated users for") + listOrganizationGroupsCmd.Flags().StringP("organization-name", "O", "", "Name of the organization to list associated groups for") + listOrganizationDeployTargetsCmd.Flags().StringP("organization-name", "O", "", "Name of the organization to list associated deploy targets for") listOrganizationDeployTargetsCmd.Flags().Uint("id", 0, "ID of the organization to list associated deploy targets for") } diff --git a/cmd/organization.go b/cmd/organization.go index 94fa2f70..7df40439 100644 --- a/cmd/organization.go +++ b/cmd/organization.go @@ -23,7 +23,7 @@ var addOrganizationCmd = &cobra.Command{ if err != nil { return err } - organizationName, err := cmd.Flags().GetString("name") + organizationName, err := cmd.Flags().GetString("organization-name") if err != nil { return err } @@ -107,7 +107,7 @@ var deleteOrganizationCmd = &cobra.Command{ if err != nil { return err } - organizationName, err := cmd.Flags().GetString("name") + organizationName, err := cmd.Flags().GetString("organization-name") if err != nil { return err } @@ -154,7 +154,7 @@ var updateOrganizationCmd = &cobra.Command{ if err != nil { return err } - organizationName, err := cmd.Flags().GetString("name") + organizationName, err := cmd.Flags().GetString("organization-name") if err != nil { return err } @@ -232,7 +232,7 @@ var updateOrganizationCmd = &cobra.Command{ } func init() { - addOrganizationCmd.Flags().StringP("name", "O", "", "Name of the organization") + addOrganizationCmd.Flags().StringP("organization-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") @@ -241,7 +241,7 @@ func init() { addOrganizationCmd.Flags().Int("environment-quota", 0, "Environment quota for the organization") addOrganizationCmd.Flags().Int("route-quota", 0, "Route quota for the organization") - updateOrganizationCmd.Flags().StringP("name", "O", "", "Name of the organization to update") + updateOrganizationCmd.Flags().StringP("organization-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") updateOrganizationCmd.Flags().Int("project-quota", 0, "Project quota for the organization") @@ -250,5 +250,5 @@ func init() { updateOrganizationCmd.Flags().Int("environment-quota", 0, "Environment quota for the organization") updateOrganizationCmd.Flags().Int("route-quota", 0, "Route quota for the organization") - deleteOrganizationCmd.Flags().StringP("name", "O", "", "Name of the organization to delete") + deleteOrganizationCmd.Flags().StringP("organization-name", "O", "", "Name of the organization to delete") } diff --git a/cmd/project.go b/cmd/project.go index 86b4e6dc..45702d1b 100644 --- a/cmd/project.go +++ b/cmd/project.go @@ -77,7 +77,7 @@ var addProjectCmd = &cobra.Command{ return err } - organizationName, err := cmd.Flags().GetString("organization") + organizationName, err := cmd.Flags().GetString("organization-name") if err != nil { return err } @@ -485,7 +485,7 @@ var removeProjectFromOrganizationCmd = &cobra.Command{ return err } - organizationName, err := cmd.Flags().GetString("organization") + organizationName, err := cmd.Flags().GetString("organization-name") if err != nil { return err } @@ -575,7 +575,7 @@ func init() { addProjectCmd.Flags().UintP("developmentEnvironmentsLimit", "L", 0, "How many environments can be deployed at one time") addProjectCmd.Flags().UintP("openshift", "S", 0, "Reference to OpenShift Object this Project should be deployed to") addProjectCmd.Flags().Bool("owner", false, "Add the user as an owner of the project") - addProjectCmd.Flags().StringP("organization", "O", "", "Name of the Organization to add the project to") + addProjectCmd.Flags().StringP("organization-name", "O", "", "Name of the Organization to add the project to") listCmd.AddCommand(listProjectByMetadata) listProjectByMetadata.Flags().StringP("key", "K", "", "The key name of the metadata value you are querying on") @@ -591,5 +591,5 @@ func init() { getCmd.AddCommand(getProjectMetadata) - removeProjectFromOrganizationCmd.Flags().StringP("organization", "O", "", "Name of the Organization to remove the project from") + removeProjectFromOrganizationCmd.Flags().StringP("organization-name", "O", "", "Name of the Organization to remove the project from") } diff --git a/cmd/users.go b/cmd/users.go index 09b78b78..29294a52 100644 --- a/cmd/users.go +++ b/cmd/users.go @@ -380,7 +380,7 @@ var addAdministratorToOrganizationCmd = &cobra.Command{ return err } - organizationName, err := cmd.Flags().GetString("name") + organizationName, err := cmd.Flags().GetString("organization-name") if err != nil { return err } @@ -447,7 +447,7 @@ var removeAdministratorFromOrganizationCmd = &cobra.Command{ return err } - organizationName, err := cmd.Flags().GetString("name") + organizationName, err := cmd.Flags().GetString("organization-name") if err != nil { return err } @@ -550,10 +550,10 @@ func init() { updateUserCmd.Flags().StringVarP(¤tUserEmail, "current-email", "C", "", "Current email address of the user") getUserKeysCmd.Flags().StringP("email", "E", "", "New email address of the user") getAllUserKeysCmd.Flags().StringP("name", "N", "", "Name of the group to list users in (if not specified, will default to all groups)") - addAdministratorToOrganizationCmd.Flags().StringP("name", "O", "", "Name of the organization") + addAdministratorToOrganizationCmd.Flags().StringP("organization-name", "O", "", "Name of the organization") addAdministratorToOrganizationCmd.Flags().StringP("email", "E", "", "Email address of the user") addAdministratorToOrganizationCmd.Flags().Bool("owner", false, "Set the user as an owner of the organization") - removeAdministratorFromOrganizationCmd.Flags().StringP("name", "O", "", "Name of the organization") + removeAdministratorFromOrganizationCmd.Flags().StringP("organization-name", "O", "", "Name of the organization") removeAdministratorFromOrganizationCmd.Flags().StringP("email", "E", "", "Email address of the user") removeAdministratorFromOrganizationCmd.Flags().Bool("owner", false, "Set the user as an administrator of the organization") resetPasswordCmd.Flags().StringVarP(&userEmail, "email", "E", "", "Email address of the user") diff --git a/docs/commands/lagoon_add_group.md b/docs/commands/lagoon_add_group.md index 4ae2528d..71b6aef2 100644 --- a/docs/commands/lagoon_add_group.md +++ b/docs/commands/lagoon_add_group.md @@ -14,10 +14,10 @@ lagoon add group [flags] ### Options ``` - -h, --help help for group - -N, --name string Name of the group - -O, --organization string Name of the organization - --owner Organization owner only: Flag to grant yourself ownership of this group + -h, --help help for group + -N, --name string Name of the group + -O, --organization-name string Name of the organization + --owner Organization owner only: Flag to grant yourself ownership of this group ``` ### Options inherited from parent commands diff --git a/docs/commands/lagoon_add_organization-administrator.md b/docs/commands/lagoon_add_organization-administrator.md index 50cc8f98..038a2f5a 100644 --- a/docs/commands/lagoon_add_organization-administrator.md +++ b/docs/commands/lagoon_add_organization-administrator.md @@ -13,10 +13,10 @@ lagoon add organization-administrator [flags] ### Options ``` - -E, --email string Email address of the user - -h, --help help for organization-administrator - -O, --name string Name of the organization - --owner Set the user as an owner of the organization + -E, --email string Email address of the user + -h, --help help for organization-administrator + -O, --organization-name string Name of the organization + --owner Set the user as an owner of the organization ``` ### Options inherited from parent commands diff --git a/docs/commands/lagoon_add_organization-deploytarget.md b/docs/commands/lagoon_add_organization-deploytarget.md index 653d76fc..34ce6973 100644 --- a/docs/commands/lagoon_add_organization-deploytarget.md +++ b/docs/commands/lagoon_add_organization-deploytarget.md @@ -9,9 +9,9 @@ lagoon add organization-deploytarget [flags] ### Options ``` - -D, --deploytarget uint ID of DeployTarget - -h, --help help for organization-deploytarget - -O, --name string Name of Organization + -D, --deploytarget uint ID of DeployTarget + -h, --help help for organization-deploytarget + -O, --organization-name string Name of Organization ``` ### Options inherited from parent commands diff --git a/docs/commands/lagoon_add_organization.md b/docs/commands/lagoon_add_organization.md index 7d12f397..b7faf987 100644 --- a/docs/commands/lagoon_add_organization.md +++ b/docs/commands/lagoon_add_organization.md @@ -9,15 +9,15 @@ lagoon add organization [flags] ### Options ``` - --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 + --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 + --notification-quota int Notification quota for the organization + -O, --organization-name string Name of the organization + --project-quota int Project quota for the organization + --route-quota int Route quota for the organization ``` ### Options inherited from parent commands diff --git a/docs/commands/lagoon_add_project.md b/docs/commands/lagoon_add_project.md index cd54961d..31699314 100644 --- a/docs/commands/lagoon_add_project.md +++ b/docs/commands/lagoon_add_project.md @@ -22,7 +22,7 @@ lagoon add project [flags] -j, --json string JSON string to patch -S, --openshift uint Reference to OpenShift Object this Project should be deployed to -o, --openshiftProjectPattern string Pattern of OpenShift Project/Namespace that should be generated - -O, --organization string Name of the Organization to add the project to + -O, --organization-name string Name of the Organization to add the project to --owner Add the user as an owner of the project -I, --privateKey string Private key to use for the project -E, --productionEnvironment string Which environment(the name) should be marked as the production environment diff --git a/docs/commands/lagoon_delete_organization-administrator.md b/docs/commands/lagoon_delete_organization-administrator.md index c4f0118a..abf01997 100644 --- a/docs/commands/lagoon_delete_organization-administrator.md +++ b/docs/commands/lagoon_delete_organization-administrator.md @@ -9,10 +9,10 @@ lagoon delete organization-administrator [flags] ### Options ``` - -E, --email string Email address of the user - -h, --help help for organization-administrator - -O, --name string Name of the organization - --owner Set the user as an administrator of the organization + -E, --email string Email address of the user + -h, --help help for organization-administrator + -O, --organization-name string Name of the organization + --owner Set the user as an administrator of the organization ``` ### Options inherited from parent commands diff --git a/docs/commands/lagoon_delete_organization-deploytarget.md b/docs/commands/lagoon_delete_organization-deploytarget.md index caf80014..6a7e2fe9 100644 --- a/docs/commands/lagoon_delete_organization-deploytarget.md +++ b/docs/commands/lagoon_delete_organization-deploytarget.md @@ -9,9 +9,9 @@ lagoon delete organization-deploytarget [flags] ### Options ``` - -D, --deploytarget uint ID of DeployTarget - -h, --help help for organization-deploytarget - -O, --name string Name of Organization + -D, --deploytarget uint ID of DeployTarget + -h, --help help for organization-deploytarget + -O, --organization-name string Name of Organization ``` ### Options inherited from parent commands diff --git a/docs/commands/lagoon_delete_organization-project.md b/docs/commands/lagoon_delete_organization-project.md index c0e5df1e..440bc5f2 100644 --- a/docs/commands/lagoon_delete_organization-project.md +++ b/docs/commands/lagoon_delete_organization-project.md @@ -14,8 +14,8 @@ lagoon delete organization-project [flags] ### Options ``` - -h, --help help for organization-project - -O, --organization string Name of the Organization to remove the project from + -h, --help help for organization-project + -O, --organization-name string Name of the Organization to remove the project from ``` ### Options inherited from parent commands diff --git a/docs/commands/lagoon_delete_organization.md b/docs/commands/lagoon_delete_organization.md index 577187a7..92d88b2c 100644 --- a/docs/commands/lagoon_delete_organization.md +++ b/docs/commands/lagoon_delete_organization.md @@ -9,8 +9,8 @@ lagoon delete organization [flags] ### Options ``` - -h, --help help for organization - -O, --name string Name of the organization to delete + -h, --help help for organization + -O, --organization-name string Name of the organization to delete ``` ### Options inherited from parent commands diff --git a/docs/commands/lagoon_get_organization.md b/docs/commands/lagoon_get_organization.md index b75e28aa..291004de 100644 --- a/docs/commands/lagoon_get_organization.md +++ b/docs/commands/lagoon_get_organization.md @@ -9,8 +9,8 @@ lagoon get organization [flags] ### Options ``` - -h, --help help for organization - -O, --name string Name of the organization + -h, --help help for organization + -O, --organization-name string Name of the organization ``` ### Options inherited from parent commands diff --git a/docs/commands/lagoon_list_organization-deploytargets.md b/docs/commands/lagoon_list_organization-deploytargets.md index deab8f3f..cf41d429 100644 --- a/docs/commands/lagoon_list_organization-deploytargets.md +++ b/docs/commands/lagoon_list_organization-deploytargets.md @@ -9,9 +9,9 @@ lagoon list organization-deploytargets [flags] ### Options ``` - -h, --help help for organization-deploytargets - --id uint ID of the organization to list associated deploy targets for - -O, --organization string Name of the organization to list associated deploy targets for + -h, --help help for organization-deploytargets + --id uint ID of the organization to list associated deploy targets for + -O, --organization-name string Name of the organization to list associated deploy targets for ``` ### Options inherited from parent commands diff --git a/docs/commands/lagoon_list_organization-groups.md b/docs/commands/lagoon_list_organization-groups.md index d795a175..3fbea4f8 100644 --- a/docs/commands/lagoon_list_organization-groups.md +++ b/docs/commands/lagoon_list_organization-groups.md @@ -9,8 +9,8 @@ lagoon list organization-groups [flags] ### Options ``` - -h, --help help for organization-groups - -O, --organization string Name of the organization to list associated groups for + -h, --help help for organization-groups + -O, --organization-name string Name of the organization to list associated groups for ``` ### Options inherited from parent commands diff --git a/docs/commands/lagoon_list_organization-projects.md b/docs/commands/lagoon_list_organization-projects.md index bdffd90f..1cae1f5c 100644 --- a/docs/commands/lagoon_list_organization-projects.md +++ b/docs/commands/lagoon_list_organization-projects.md @@ -9,8 +9,8 @@ lagoon list organization-projects [flags] ### Options ``` - -h, --help help for organization-projects - -O, --organization string Name of the organization to list associated projects for + -h, --help help for organization-projects + -O, --organization-name string Name of the organization to list associated projects for ``` ### Options inherited from parent commands diff --git a/docs/commands/lagoon_list_organization-users.md b/docs/commands/lagoon_list_organization-users.md index 1b35da23..98139840 100644 --- a/docs/commands/lagoon_list_organization-users.md +++ b/docs/commands/lagoon_list_organization-users.md @@ -9,8 +9,8 @@ lagoon list organization-users [flags] ### Options ``` - -h, --help help for organization-users - -O, --organization string Name of the organization to list associated users for + -h, --help help for organization-users + -O, --organization-name string Name of the organization to list associated users for ``` ### Options inherited from parent commands diff --git a/docs/commands/lagoon_update_organization.md b/docs/commands/lagoon_update_organization.md index 5563ecf3..00d77203 100644 --- a/docs/commands/lagoon_update_organization.md +++ b/docs/commands/lagoon_update_organization.md @@ -9,15 +9,15 @@ lagoon update organization [flags] ### Options ``` - --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 to update - --notification-quota int Notification quota for the organization - --project-quota int Project quota for the organization - --route-quota int Route quota for the 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 + --notification-quota int Notification quota for the organization + -O, --organization-name string Name of the organization to update + --project-quota int Project quota for the organization + --route-quota int Route quota for the organization ``` ### Options inherited from parent commands