Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

refactor: restructure organization commands #332

Merged
merged 14 commits into from
Jun 4, 2024
11 changes: 2 additions & 9 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -43,4 +34,6 @@ func init() {
addCmd.AddCommand(addUserSSHKeyCmd)
addCmd.AddCommand(addVariableCmd)
addCmd.AddCommand(addDeployTargetConfigCmd)
addCmd.AddCommand(addDeployTargetToOrganizationCmd)
addCmd.AddCommand(addAdministratorToOrganizationCmd)
}
12 changes: 3 additions & 9 deletions cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -44,4 +35,7 @@ func init() {
deleteCmd.AddCommand(deleteVariableCmd)
deleteCmd.AddCommand(deleteDeployTargetConfigCmd)
deleteCmd.AddCommand(deleteOrganizationCmd)
deleteCmd.AddCommand(removeDeployTargetFromOrganizationCmd)
deleteCmd.AddCommand(removeAdministratorFromOrganizationCmd)
deleteCmd.AddCommand(removeProjectFromOrganizationCmd)
}
69 changes: 37 additions & 32 deletions cmd/deploytarget.go
CGoodwin90 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -324,28 +324,27 @@ 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)
},
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 {
organizationName, err := cmd.Flags().GetString("organization-name")
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("Deploy Target", strconv.Itoa(int(deployTarget))); err != nil {

if err := requiredInputCheck("Organization name", organizationName, "Deploy Target", strconv.Itoa(int(deploytarget))); err != nil {
return err
}

Expand All @@ -359,51 +358,53 @@ var addDeployTargetToOrganizationCmd = &cobra.Command{
debug)

organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc)
handleError(err)
if err != nil {
return err
}

deployTargetInput := s.AddDeployTargetToOrganizationInput{
DeployTarget: deployTarget,
DeployTarget: deploytarget,
Organization: organization.ID,
}

deployTargetResponse, err := l.AddDeployTargetToOrganization(context.TODO(), &deployTargetInput, lc)
handleError(err)

if err != nil {
return 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)
return nil
},
}

var RemoveDeployTargetFromOrganizationCmd = &cobra.Command{
Use: "deploytarget",
Aliases: []string{"dt"},
var removeDeployTargetFromOrganizationCmd = &cobra.Command{
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)
},
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 {

organizationName, err := cmd.Flags().GetString("organization-name")
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("Deploy Target", strconv.Itoa(int(deployTarget))); err != nil {
if err := requiredInputCheck("Organization name", organizationName, "Deploy Target", strconv.Itoa(int(deploytarget))); err != nil {
return err
}

Expand All @@ -417,20 +418,24 @@ var RemoveDeployTargetFromOrganizationCmd = &cobra.Command{
debug)

organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc)
handleError(err)
if err != nil {
return 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)
if err != nil {
return err
}
resultData := output.Result{
Result: "success",
ResultData: map[string]interface{}{
"Deploy Target": deployTarget,
"Deploy Target": deploytarget,
"Organization Name": organizationName,
},
}
Expand All @@ -453,14 +458,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("name", "O", "", "Name of Organization")
addDeployTargetToOrganizationCmd.Flags().UintP("deploy-target", "D", 0, "ID of DeployTarget")
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().UintP("deploy-target", "D", 0, "ID of DeployTarget")
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")
updateDeployTargetCmd.Flags().StringP("console-url", "", "", "DeployTarget console URL")
Expand Down
4 changes: 2 additions & 2 deletions cmd/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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")
}
8 changes: 5 additions & 3 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
Expand Down Expand Up @@ -327,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")
}
Loading
Loading