-
Notifications
You must be signed in to change notification settings - Fork 56
/
orgs_delete.go
76 lines (59 loc) · 1.54 KB
/
orgs_delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"context"
"flag"
"fmt"
"github.com/sourcegraph/src-cli/internal/api"
)
func init() {
usage := `
Examples:
Delete an organization by ID:
$ src orgs delete -id=VXNlcjox
Delete an organization by name:
$ src orgs delete -id=$(src orgs get -f='{{.ID}}' -name=abc-org)
Delete all organizations that match the query
$ src orgs list -f='{{.ID}}' -query=abc-org | xargs -n 1 -I ORGID src orgs delete -id=ORGID
`
flagSet := flag.NewFlagSet("delete", flag.ExitOnError)
usageFunc := func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage of 'src orgs %s':\n", flagSet.Name())
flagSet.PrintDefaults()
fmt.Println(usage)
}
var (
orgIDFlag = flagSet.String("id", "", `The ID of the organization to delete.`)
apiFlags = api.NewFlags(flagSet)
)
handler := func(args []string) error {
if err := flagSet.Parse(args); err != nil {
return err
}
client := cfg.apiClient(apiFlags, flagSet.Output())
query := `mutation DeleteOrganization(
$organization: ID!
) {
deleteOrganization(
organization: $organization
) {
alwaysNil
}
}`
var result struct {
DeleteOrganization struct{}
}
if ok, err := client.NewRequest(query, map[string]interface{}{
"organization": *orgIDFlag,
}).Do(context.Background(), &result); err != nil || !ok {
return err
}
fmt.Printf("Organization with ID %q deleted.\n", *orgIDFlag)
return nil
}
// Register the command.
orgsCommands = append(orgsCommands, &command{
flagSet: flagSet,
handler: handler,
usageFunc: usageFunc,
})
}