2020-12-07 12:24:04 +00:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2023-09-08 01:40:02 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-12-07 12:24:04 +00:00
|
|
|
|
|
|
|
package organizations
|
|
|
|
|
|
|
|
import (
|
2020-12-16 16:18:10 +00:00
|
|
|
"fmt"
|
2020-12-07 12:24:04 +00:00
|
|
|
|
2021-06-22 14:23:09 +00:00
|
|
|
"code.gitea.io/tea/cmd/flags"
|
2020-12-15 17:38:22 +00:00
|
|
|
"code.gitea.io/tea/modules/context"
|
2020-12-07 12:24:04 +00: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 14:23:09 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
&flags.LoginFlag,
|
|
|
|
&flags.RemoteFlag,
|
|
|
|
},
|
2020-12-07 12:24:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RunOrganizationDelete delete user organization
|
2020-12-15 17:38:22 +00:00
|
|
|
func RunOrganizationDelete(cmd *cli.Context) error {
|
|
|
|
ctx := context.InitCommand(cmd)
|
2020-12-07 12:24:04 +00:00
|
|
|
|
2020-12-15 17:38:22 +00:00
|
|
|
client := ctx.Login.Client()
|
2020-12-07 12:24:04 +00:00
|
|
|
|
|
|
|
if ctx.Args().Len() < 1 {
|
2020-12-16 16:18:10 +00:00
|
|
|
return fmt.Errorf("You have to specify the organization name you want to delete")
|
2020-12-07 12:24:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
response, err := client.DeleteOrg(ctx.Args().First())
|
|
|
|
if response != nil && response.StatusCode == 404 {
|
2020-12-16 16:18:10 +00:00
|
|
|
return fmt.Errorf("The given organization does not exist")
|
2020-12-07 12:24:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|