2020-12-07 13:24:04 +01:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2023-09-08 03:40:02 +02:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-12-07 13:24:04 +01:00
|
|
|
|
|
|
|
package organizations
|
|
|
|
|
|
|
|
import (
|
2020-12-16 17:18:10 +01:00
|
|
|
"fmt"
|
2020-12-07 13:24:04 +01:00
|
|
|
|
2021-06-22 16:23:09 +02:00
|
|
|
"code.gitea.io/tea/cmd/flags"
|
2020-12-15 18:38:22 +01:00
|
|
|
"code.gitea.io/tea/modules/context"
|
2020-12-07 13:24:04 +01:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CmdOrganizationDelete represents a sub command of organizations to delete a given user organization
|
|
|
|
var CmdOrganizationDelete = cli.Command{
|
|
|
|
Name: "delete",
|
|
|
|
Aliases: []string{"rm"},
|
|
|
|
Usage: "Delete users Organizations",
|
|
|
|
Description: "Delete users organizations",
|
|
|
|
ArgsUsage: "<organization name>",
|
|
|
|
Action: RunOrganizationDelete,
|
2021-06-22 16:23:09 +02:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
&flags.LoginFlag,
|
|
|
|
&flags.RemoteFlag,
|
|
|
|
},
|
2020-12-07 13:24:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// RunOrganizationDelete delete user organization
|
2020-12-15 18:38:22 +01:00
|
|
|
func RunOrganizationDelete(cmd *cli.Context) error {
|
|
|
|
ctx := context.InitCommand(cmd)
|
2020-12-07 13:24:04 +01:00
|
|
|
|
2020-12-15 18:38:22 +01:00
|
|
|
client := ctx.Login.Client()
|
2020-12-07 13:24:04 +01:00
|
|
|
|
|
|
|
if ctx.Args().Len() < 1 {
|
2020-12-16 17:18:10 +01:00
|
|
|
return fmt.Errorf("You have to specify the organization name you want to delete")
|
2020-12-07 13:24:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
response, err := client.DeleteOrg(ctx.Args().First())
|
|
|
|
if response != nil && response.StatusCode == 404 {
|
2020-12-16 17:18:10 +01:00
|
|
|
return fmt.Errorf("The given organization does not exist")
|
2020-12-07 13:24:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|