From 86e5fb44c472ef9dae5efc981c8fa5a4e558f5f7 Mon Sep 17 00:00:00 2001 From: cgoodwin90 Date: Mon, 23 Oct 2023 14:47:37 +1100 Subject: [PATCH] Updated add project cmd + various fixes --- cmd/deploytarget.go | 38 ++++++++---- cmd/get.go | 12 ++-- cmd/groups.go | 19 ++++-- cmd/list.go | 50 +++++++++++----- cmd/organization.go | 80 +++++++++++++++----------- cmd/project.go | 137 +++++++++++++++++++++++++++----------------- cmd/shared.go | 6 +- cmd/users.go | 24 +++++--- go.mod | 2 +- go.sum | 2 + 10 files changed, 235 insertions(+), 135 deletions(-) diff --git a/cmd/deploytarget.go b/cmd/deploytarget.go index 9bcdef22..e1025b33 100644 --- a/cmd/deploytarget.go +++ b/cmd/deploytarget.go @@ -333,13 +333,20 @@ var addDeployTargetToOrganizationCmd = &cobra.Command{ debug, err := cmd.Flags().GetBool("debug") handleError(err) - organizationName, err := cmd.Flags().GetString("organization") - requiredInputCheck("Organization name", organizationName) - deployTarget, err := cmd.Flags().GetUint("deployTarget") - requiredInputCheck("Deploy Target", strconv.Itoa(int(deployTarget))) + 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 { + return err + } current := lagoonCLIConfig.Current token := lagoonCLIConfig.Lagoons[current].Token @@ -383,13 +390,20 @@ var RemoveDeployTargetFromOrganizationCmd = &cobra.Command{ debug, err := cmd.Flags().GetBool("debug") handleError(err) - organizationName, err := cmd.Flags().GetString("organization") - requiredInputCheck("Organization name", organizationName) - deployTarget, err := cmd.Flags().GetUint("deployTarget") - requiredInputCheck("Deploy Target", strconv.Itoa(int(deployTarget))) + 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 { + return err + } current := lagoonCLIConfig.Current token := lagoonCLIConfig.Lagoons[current].Token @@ -436,14 +450,14 @@ 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("organization", "O", "", "Name of Organization") - addDeployTargetToOrganizationCmd.Flags().UintP("deployTarget", "D", 0, "ID of DeployTarget") + addDeployTargetToOrganizationCmd.Flags().StringP("name", "O", "", "Name of Organization") + addDeployTargetToOrganizationCmd.Flags().UintP("deploy-target", "D", 0, "ID of DeployTarget") deleteDeployTargetCmd.Flags().UintP("id", "", 0, "ID of the DeployTarget") deleteDeployTargetCmd.Flags().StringP("name", "", "", "Name of DeployTarget") - RemoveDeployTargetFromOrganizationCmd.Flags().StringP("organization", "O", "", "Name of Organization") - RemoveDeployTargetFromOrganizationCmd.Flags().UintP("deployTarget", "D", 0, "ID of DeployTarget") + RemoveDeployTargetFromOrganizationCmd.Flags().StringP("name", "O", "", "Name of Organization") + RemoveDeployTargetFromOrganizationCmd.Flags().UintP("deploy-target", "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/get.go b/cmd/get.go index 082259e0..089ab1e3 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -181,11 +181,13 @@ var getOrganizationCmd = &cobra.Command{ if err != nil { return err } - organizationName, err := cmd.Flags().GetString("organization") - requiredInputCheck("Organization name", organizationName) + organizationName, err := cmd.Flags().GetString("name") if err != nil { return err } + if err := requiredInputCheck("Organization name", organizationName); err != nil { + return err + } current := lagoonCLIConfig.Current token := lagoonCLIConfig.Lagoons[current].Token @@ -199,7 +201,7 @@ var getOrganizationCmd = &cobra.Command{ if organization.Name == "" { output.RenderInfo(fmt.Sprintf("No organization found for '%s'", organizationName), outputOptions) - os.Exit(0) + return nil } data := []output.Data{} @@ -213,7 +215,7 @@ var getOrganizationCmd = &cobra.Command{ }) dataMain := output.Table{ - Header: []string{"ID", "Name", "Description", "quotaProject", "quotaGroup", "quotaNotification"}, + Header: []string{"ID", "Name", "Description", "Project Quota", "Group Quota", "Notification Quota"}, Data: data, } @@ -236,5 +238,5 @@ func init() { getTaskByID.Flags().BoolP("logs", "L", false, "Show the task logs if available") getProjectKeyCmd.Flags().BoolVarP(&revealValue, "reveal", "", false, "Reveal the variable values") getDeploymentCmd.Flags().StringVarP(&remoteID, "remoteid", "R", "", "The remote ID of the deployment") - getOrganizationCmd.Flags().StringP("organization", "O", "", "Name of the organization") + getOrganizationCmd.Flags().StringP("name", "O", "", "Name of the organization") } diff --git a/cmd/groups.go b/cmd/groups.go index be86fad7..1dedda77 100644 --- a/cmd/groups.go +++ b/cmd/groups.go @@ -242,17 +242,24 @@ var addGroupToOrganizationCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { debug, err := cmd.Flags().GetBool("debug") handleError(err) - orgOwner, err := cmd.Flags().GetBool("orgOwner") - organizationName, err := cmd.Flags().GetString("organization") - requiredInputCheck("Organization name", organizationName) + 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") - requiredInputCheck("Group name", groupName) if err != nil { return err } + if err := requiredInputCheck("Group name", groupName); err != nil { + return err + } current := lagoonCLIConfig.Current token := lagoonCLIConfig.Lagoons[current].Token @@ -296,7 +303,7 @@ 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("organization", "O", "", "Name of the organization") + addGroupToOrganizationCmd.Flags().StringP("name", "O", "", "Name of the organization") addGroupToOrganizationCmd.Flags().StringP("group", "G", "", "Name of the group") - addGroupToOrganizationCmd.Flags().Bool("orgOwner", false, "Flag to add the user to the group as an owner") + 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 2d5e9e34..0061fec7 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -457,8 +457,13 @@ var listOrganizationProjectsCmd = &cobra.Command{ if err != nil { return err } - organizationName, err := cmd.Flags().GetString("organization") - requiredInputCheck("Organization name", organizationName) + organizationName, err := cmd.Flags().GetString("name") + if err != nil { + return err + } + if err := requiredInputCheck("Organization name", organizationName); err != nil { + return err + } current := lagoonCLIConfig.Current token := lagoonCLIConfig.Lagoons[current].Token @@ -481,7 +486,7 @@ var listOrganizationProjectsCmd = &cobra.Command{ }) } dataMain := output.Table{ - Header: []string{"ID", "Name", "GroupCount"}, + Header: []string{"ID", "Name", "Group Count"}, Data: data, } output.RenderOutput(dataMain, outputOptions) @@ -501,8 +506,13 @@ var listOrganizationGroupsCmd = &cobra.Command{ if err != nil { return err } - organizationName, err := cmd.Flags().GetString("organization") - requiredInputCheck("Organization name", organizationName) + organizationName, err := cmd.Flags().GetString("name") + if err != nil { + return err + } + if err := requiredInputCheck("Organization name", organizationName); err != nil { + return err + } current := lagoonCLIConfig.Current token := lagoonCLIConfig.Lagoons[current].Token @@ -526,7 +536,7 @@ var listOrganizationGroupsCmd = &cobra.Command{ }) } dataMain := output.Table{ - Header: []string{"ID", "Name", "Type", "MemberCount"}, + Header: []string{"ID", "Name", "Type", "Member Count"}, Data: data, } output.RenderOutput(dataMain, outputOptions) @@ -546,8 +556,13 @@ var listOrganizationDeployTargetsCmd = &cobra.Command{ if err != nil { return err } - organizationName, err := cmd.Flags().GetString("organization") - requiredInputCheck("Organization name", organizationName) + organizationName, err := cmd.Flags().GetString("name") + if err != nil { + return err + } + if err := requiredInputCheck("Organization name", organizationName); err != nil { + return err + } current := lagoonCLIConfig.Current token := lagoonCLIConfig.Lagoons[current].Token @@ -573,7 +588,7 @@ var listOrganizationDeployTargetsCmd = &cobra.Command{ }) } dataMain := output.Table{ - Header: []string{"ID", "Name", "Router Pattern", "ConsoleURL", "Cloud Region", "Cloud Provider", "SSH Host", "SSH Port"}, + Header: []string{"ID", "Name", "Router Pattern", "Console URL", "Cloud Region", "Cloud Provider", "SSH Host", "SSH Port"}, Data: data, } output.RenderOutput(dataMain, outputOptions) @@ -593,8 +608,13 @@ var ListOrganizationUsersCmd = &cobra.Command{ if err != nil { return err } - organizationName, err := cmd.Flags().GetString("organization") - requiredInputCheck("Organization name", organizationName) + organizationName, err := cmd.Flags().GetString("name") + if err != nil { + return err + } + if err := requiredInputCheck("Organization name", organizationName); err != nil { + return err + } current := lagoonCLIConfig.Current token := lagoonCLIConfig.Lagoons[current].Token @@ -651,8 +671,8 @@ func init() { listUsersCmd.Flags().StringVarP(&groupName, "name", "N", "", "Name of the group to list users in (if not specified, will default to all groups)") 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("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") } diff --git a/cmd/organization.go b/cmd/organization.go index d781c081..b5b77b51 100644 --- a/cmd/organization.go +++ b/cmd/organization.go @@ -22,12 +22,14 @@ var addOrgCmd = &cobra.Command{ if err != nil { return err } - organizationName, err := cmd.Flags().GetString("organization") - requiredInputCheck("Organization name", organizationName) + organizationName, err := cmd.Flags().GetString("name") if err != nil { return err } - organizationFriendlyName, err := cmd.Flags().GetString("friendlyName") + if err := requiredInputCheck("Organization name", organizationName); err != nil { + return err + } + organizationFriendlyName, err := cmd.Flags().GetString("friendly-name") if err != nil { return err } @@ -35,23 +37,23 @@ var addOrgCmd = &cobra.Command{ if err != nil { return err } - organizationQuotaProject, err := cmd.Flags().GetUint("quotaProject") + organizationQuotaProject, err := cmd.Flags().GetUint("project-quota") if err != nil { return err } - organizationQuotaGroup, err := cmd.Flags().GetUint("quotaGroup") + organizationQuotaGroup, err := cmd.Flags().GetUint("group-quota") if err != nil { return err } - organizationQuotaNotification, err := cmd.Flags().GetUint("quotaNotification") + organizationQuotaNotification, err := cmd.Flags().GetUint("notification-quota") if err != nil { return err } - organizationQuotaEnvironment, err := cmd.Flags().GetUint("quotaEnvironment") + organizationQuotaEnvironment, err := cmd.Flags().GetUint("environment-quota") if err != nil { return err } - organizationQuotaRoute, err := cmd.Flags().GetUint("quotaRoute") + organizationQuotaRoute, err := cmd.Flags().GetUint("route-quota") if err != nil { return err } @@ -98,11 +100,16 @@ var deleteOrgCmd = &cobra.Command{ }, RunE: func(cmd *cobra.Command, args []string) error { debug, err := cmd.Flags().GetBool("debug") - organizationName, err := cmd.Flags().GetString("organization") - requiredInputCheck("Organization name", organizationName) 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 + } current := lagoonCLIConfig.Current token := lagoonCLIConfig.Lagoons[current].Token @@ -138,12 +145,17 @@ var updateOrganizationCmd = &cobra.Command{ if err != nil { return err } - organizationName, err := cmd.Flags().GetString("organization") - requiredInputCheck("Organization name", organizationName) + organizationName, err := cmd.Flags().GetString("name") + if err != nil { + return err + } + if err := requiredInputCheck("Organization name", organizationName); err != nil { + return err + } if err != nil { return err } - organizationFriendlyName, err := cmd.Flags().GetString("friendlyName") + organizationFriendlyName, err := cmd.Flags().GetString("friendly-name") if err != nil { return err } @@ -151,23 +163,23 @@ var updateOrganizationCmd = &cobra.Command{ if err != nil { return err } - organizationQuotaProject, err := cmd.Flags().GetUint("quotaProject") + organizationQuotaProject, err := cmd.Flags().GetUint("project-quota") if err != nil { return err } - organizationQuotaGroup, err := cmd.Flags().GetUint("quotaGroup") + organizationQuotaGroup, err := cmd.Flags().GetUint("group-quota") if err != nil { return err } - organizationQuotaNotification, err := cmd.Flags().GetUint("quotaNotification") + organizationQuotaNotification, err := cmd.Flags().GetUint("notification-quota") if err != nil { return err } - organizationQuotaEnvironment, err := cmd.Flags().GetUint("quotaEnvironment") + organizationQuotaEnvironment, err := cmd.Flags().GetUint("environment-quota") if err != nil { return err } - organizationQuotaRoute, err := cmd.Flags().GetUint("quotaRoute") + organizationQuotaRoute, err := cmd.Flags().GetUint("route-quota") if err != nil { return err } @@ -216,23 +228,23 @@ func init() { deleteOrganizationCmd.AddCommand(RemoveProjectFromOrganizationCmd) deleteOrganizationCmd.AddCommand(RemoveUserFromOrganization) - addOrgCmd.Flags().StringP("organization", "O", "", "Name of the organization") - addOrgCmd.Flags().String("friendlyName", "", "Friendly name of the organization") + 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().Uint("quotaProject", 0, "Project quota for the organization") - addOrgCmd.Flags().Uint("quotaGroup", 0, "Group quota for the organization") - addOrgCmd.Flags().Uint("quotaNotification", 0, "Notification quota for the organization") - addOrgCmd.Flags().Uint("quotaEnvironment", 0, "Environment quota for the organization") - addOrgCmd.Flags().Uint("quotaRoute", 0, "Route quota for the organization") - - updateOrganizationCmd.Flags().StringP("organization", "O", "", "Name of the organization to update") - updateOrganizationCmd.Flags().String("friendlyName", "", "Friendly name of the organization") + addOrgCmd.Flags().Uint("project-quota", 0, "Project quota for the organization") + addOrgCmd.Flags().Uint("group-quota", 0, "Group quota for the organization") + addOrgCmd.Flags().Uint("notification-quota", 0, "Notification quota for the organization") + addOrgCmd.Flags().Uint("environment-quota", 0, "Environment quota for the organization") + addOrgCmd.Flags().Uint("route-quota", 0, "Route quota for the organization") + + updateOrganizationCmd.Flags().StringP("name", "O", "", "Name of the organization to update") + updateOrganizationCmd.Flags().String("friendly-name", "", "Friendly name of the organization") updateOrganizationCmd.Flags().String("description", "", "Description of the organization") - updateOrganizationCmd.Flags().Uint("quotaProject", 0, "Project quota for the organization") - updateOrganizationCmd.Flags().Uint("quotaGroup", 0, "Group quota for the organization") - updateOrganizationCmd.Flags().Uint("quotaNotification", 0, "Notification quota for the organization") - updateOrganizationCmd.Flags().Uint("quotaEnvironment", 0, "Environment quota for the organization") - updateOrganizationCmd.Flags().Uint("quotaRoute", 0, "Route quota for the organization") + updateOrganizationCmd.Flags().Uint("project-quota", 0, "Project quota for the organization") + updateOrganizationCmd.Flags().Uint("group-quota", 0, "Group quota for the organization") + updateOrganizationCmd.Flags().Uint("notification-quota", 0, "Notification quota for the organization") + updateOrganizationCmd.Flags().Uint("environment-quota", 0, "Environment quota for the organization") + updateOrganizationCmd.Flags().Uint("route-quota", 0, "Route quota for the organization") - deleteOrgCmd.Flags().StringP("organization", "O", "", "Name of the organization to delete") + deleteOrgCmd.Flags().StringP("name", "O", "", "Name of the organization to delete") } diff --git a/cmd/project.go b/cmd/project.go index 6339b08c..d458364c 100644 --- a/cmd/project.go +++ b/cmd/project.go @@ -368,7 +368,6 @@ var deleteProjectMetadataByKey = &cobra.Command{ }, } -// TODO - refactor once machinery is updated var addProjectToOrganizationCmd = &cobra.Command{ Use: "project", Aliases: []string{"p"}, @@ -380,25 +379,38 @@ var addProjectToOrganizationCmd = &cobra.Command{ debug, err := cmd.Flags().GetBool("debug") handleError(err) - requiredInputCheck("Project name", cmdProjectName) - organizationName, err := cmd.Flags().GetString("organization") - requiredInputCheck("Organization name", organizationName) - gitUrl, err := cmd.Flags().GetString("gitUrl") - requiredInputCheck("gitUrl", gitUrl) + 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 } - productionEnvironment, err := cmd.Flags().GetString("productionEnvironment") - requiredInputCheck("Production Environment", productionEnvironment) + 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") - requiredInputCheck("openshift", strconv.Itoa(int(openshift))) if err != nil { return err } - standbyProductionEnvironment, err := cmd.Flags().GetString("standbyProductionEnvironment") + 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 } @@ -410,19 +422,19 @@ var addProjectToOrganizationCmd = &cobra.Command{ if err != nil { return err } - openshiftProjectPattern, err := cmd.Flags().GetString("openshiftProjectPattern") + openshiftProjectPattern, err := cmd.Flags().GetString("openshift-project-pattern") if err != nil { return err } - developmentEnvironmentsLimit, err := cmd.Flags().GetUint("developmentEnvironmentsLimit") + developmentEnvironmentsLimit, err := cmd.Flags().GetUint("development-environments-limit") if err != nil { return err } - storageCalc, err := cmd.Flags().GetUint("storageCalc") + storageCalc, err := cmd.Flags().GetUint("storage-calc") if err != nil { return err } - autoIdle, err := cmd.Flags().GetUint("autoIdle") + autoIdle, err := cmd.Flags().GetUint("auto-idle") if err != nil { return err } @@ -430,15 +442,15 @@ var addProjectToOrganizationCmd = &cobra.Command{ if err != nil { return err } - privateKey, err := cmd.Flags().GetString("privateKey") + privateKey, err := cmd.Flags().GetString("private-key") if err != nil { return err } - orgOwner, err := cmd.Flags().GetBool("orgOwner") + orgOwner, err := cmd.Flags().GetBool("org-owner") if err != nil { return err } - buildImage, err := cmd.Flags().GetString("buildImage") + buildImage, err := cmd.Flags().GetString("build-image") if err != nil { return err } @@ -446,23 +458,30 @@ var addProjectToOrganizationCmd = &cobra.Command{ if err != nil { return err } - - //factsUi, err := cmd.Flags().GetUint("factsUi") - //if err != nil { - // return err - //} - //problemsUi, err := cmd.Flags().GetUint("problemsUi") - //if err != nil { - // return err - //} - //routerPattern, err := cmd.Flags().GetString("routerPattern") - //if err != nil { - // return err - //} - //deploymentsDisabled, err := cmd.Flags().GetUint("deploymentsDisabled") - //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 @@ -493,6 +512,12 @@ var addProjectToOrganizationCmd = &cobra.Command{ 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) @@ -521,12 +546,16 @@ var RemoveProjectFromOrganizationCmd = &cobra.Command{ debug, err := cmd.Flags().GetBool("debug") handleError(err) - organizationName, err := cmd.Flags().GetString("organization") - requiredInputCheck("Organization name", organizationName) - requiredInputCheck("Project", cmdProjectName) + 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 + } current := lagoonCLIConfig.Current token := lagoonCLIConfig.Lagoons[current].Token @@ -617,24 +646,30 @@ func init() { getCmd.AddCommand(getProjectMetadata) - addProjectToOrganizationCmd.Flags().String("buildImage", "", "Build Image for the project") + addProjectToOrganizationCmd.Flags().String("build-image", "", "Build Image for the project") addProjectToOrganizationCmd.Flags().String("availability", "", "Availability of the project") - addProjectToOrganizationCmd.Flags().String("gitUrl", "", "GitURL of the project") - addProjectToOrganizationCmd.Flags().String("productionEnvironment", "", "Production Environment for the project") - addProjectToOrganizationCmd.Flags().String("standbyProductionEnvironment", "", "Standby Production Environment for 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("privateKey", "", "Private key to use for the project") + 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("organization", "O", "", "Organization to add the project to") - addProjectToOrganizationCmd.Flags().String("openshiftProjectPattern", "", "Pattern of OpenShift Project/Namespace that should be generated") + 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("autoIdle", 0, "Auto idle setting of the project") - addProjectToOrganizationCmd.Flags().Uint("storageCalc", 0, "Should storage for this environment be calculated") - addProjectToOrganizationCmd.Flags().Uint("developmentEnvironmentsLimit", 0, "How many environments can be deployed at one time") - - addProjectToOrganizationCmd.Flags().Bool("orgOwner", false, "Add the user as an owner of the project") - - RemoveProjectFromOrganizationCmd.Flags().StringP("organization", "O", "", "Organization to remove the project from") + 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") + + 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 6dea07a3..7f1adfed 100644 --- a/cmd/shared.go +++ b/cmd/shared.go @@ -106,9 +106,9 @@ func nullUintCheck(i uint) *uint { return &i } -func requiredInputCheck(field string, value string) { +func requiredInputCheck(field string, value string) error { if value == "" || value == "0" { - fmt.Println(fmt.Sprintf("Missing argument: %s is not defined", field)) - os.Exit(1) + return fmt.Errorf(fmt.Sprintf("Missing argument: %s is not defined", field)) } + return nil } diff --git a/cmd/users.go b/cmd/users.go index a648b2be..9339cd1c 100644 --- a/cmd/users.go +++ b/cmd/users.go @@ -282,16 +282,20 @@ var addUserToOrganizationCmd = &cobra.Command{ debug, err := cmd.Flags().GetBool("debug") handleError(err) - organizationName, err := cmd.Flags().GetString("organization") - requiredInputCheck("Organization name", organizationName) + organizationName, err := cmd.Flags().GetString("name") if err != nil { return err } + if err := requiredInputCheck("Organization name", organizationName); err != nil { + return err + } userEmail, err := cmd.Flags().GetString("email") - requiredInputCheck("User email", userEmail) if err != nil { return err } + if err := requiredInputCheck("User email", userEmail); err != nil { + return err + } owner, err := cmd.Flags().GetBool("owner") if err != nil { return err @@ -341,16 +345,20 @@ var RemoveUserFromOrganization = &cobra.Command{ debug, err := cmd.Flags().GetBool("debug") handleError(err) - organizationName, err := cmd.Flags().GetString("organization") - requiredInputCheck("Organization name", organizationName) + organizationName, err := cmd.Flags().GetString("name") if err != nil { return err } + if err := requiredInputCheck("Organization name", organizationName); err != nil { + return err + } userEmail, err := cmd.Flags().GetString("email") - requiredInputCheck("User email", userEmail) if err != nil { return err } + if err := requiredInputCheck("User email", userEmail); err != nil { + return err + } owner, err := cmd.Flags().GetBool("owner") if err != nil { return err @@ -414,11 +422,11 @@ func init() { getUserKeysCmd.Flags().StringVarP(&groupName, "name", "N", "", "Name of the group to check users in (if not specified, will default to all groups)") getAllUserKeysCmd.Flags().StringVarP(&groupName, "name", "N", "", "Name of the group to list users in (if not specified, will default to all groups)") - addUserToOrganizationCmd.Flags().StringP("organization", "O", "", "Name of the organization") + 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("organization", "O", "", "Name 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") } diff --git a/go.mod b/go.mod index 4f335ab1..e38f3792 100644 --- a/go.mod +++ b/go.mod @@ -30,7 +30,7 @@ require ( github.com/guregu/null v4.0.0+incompatible // workaround for https://github.com/manifoldco/promptui/issues/98 github.com/nicksnyder/go-i18n v1.10.1 // indirect - github.com/uselagoon/machinery v0.0.12-0.20231020044620-78ab64a18d9d + github.com/uselagoon/machinery v0.0.12-0.20231023034503-73831e83e104 golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 // indirect golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20191105091915-95d230a53780 // indirect diff --git a/go.sum b/go.sum index 339c9821..d06a7b30 100644 --- a/go.sum +++ b/go.sum @@ -127,6 +127,8 @@ github.com/uselagoon/machinery v0.0.12-0.20231020030557-4ea384607fc3 h1:2a/j1S+w github.com/uselagoon/machinery v0.0.12-0.20231020030557-4ea384607fc3/go.mod h1:h/qeMWQR4Qqu33x+8AulNDeolEwvb/G+aIsn/jyUtwk= github.com/uselagoon/machinery v0.0.12-0.20231020044620-78ab64a18d9d h1:fEQ80pWiPLZWCGiecuMhkRGq0PXfWkQP7ACCfDiUx4E= github.com/uselagoon/machinery v0.0.12-0.20231020044620-78ab64a18d9d/go.mod h1:h/qeMWQR4Qqu33x+8AulNDeolEwvb/G+aIsn/jyUtwk= +github.com/uselagoon/machinery v0.0.12-0.20231023034503-73831e83e104 h1:4U+8Re8V0AY8jBuWAiGu7d07+LiKky9tDcfZBpgd/NU= +github.com/uselagoon/machinery v0.0.12-0.20231023034503-73831e83e104/go.mod h1:h/qeMWQR4Qqu33x+8AulNDeolEwvb/G+aIsn/jyUtwk= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=