Skip to content

Commit

Permalink
Delete organization functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
CGoodwin90 committed Sep 28, 2023
1 parent ccb628f commit a77b506
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ func init() {
deleteCmd.AddCommand(deleteUserFromGroupCmd)
deleteCmd.AddCommand(deleteVariableCmd)
deleteCmd.AddCommand(deleteDeployTargetConfigCmd)
deleteCmd.AddCommand(deleteOrganizationCmd)
}
43 changes: 43 additions & 0 deletions cmd/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"github.com/spf13/cobra"
"github.com/uselagoon/lagoon-cli/pkg/output"
l "github.com/uselagoon/machinery/api/lagoon"
lclient "github.com/uselagoon/machinery/api/lagoon/client"
s "github.com/uselagoon/machinery/api/schema"
"os"
Expand Down Expand Up @@ -59,6 +60,48 @@ var addOrganizationCmd = &cobra.Command{
},
}

var deleteOrganizationCmd = &cobra.Command{
Use: "organization",
Aliases: []string{"o"},
Short: "Delete 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")
organizationId, err := cmd.Flags().GetInt("id")
if err != nil {
return err
}
if organizationId == 0 {
fmt.Println("Missing arguments: Organization ID is not defined")
cmd.Help()
os.Exit(1)
}

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

organization, err := l.GetOrganizationByID(context.TODO(), organizationId, lc)
handleError(err)
if yesNo(fmt.Sprintf("You are attempting to delete organization '%s', are you sure?", organization.Name)) {
_, err := l.DeleteOrganization(context.TODO(), organizationId, lc)
handleError(err)
resultData := output.Result{
Result: organization.Name,
}
output.RenderResult(resultData, outputOptions)
}
return nil
},
}

func init() {
addOrganizationCmd.Flags().String("name", "", "Name of the organization")
deleteOrganizationCmd.Flags().Int("id", 0, "ID of the organization")
}

0 comments on commit a77b506

Please sign in to comment.