MCPcopy Index your code
hub / github.com/coder/coder / deleteOrganization

Method deleteOrganization

cli/organizationdelete.go:14–65  ·  view source on GitHub ↗
(_ *OrganizationContext)

Source from the content-addressed store, hash-verified

12)
13
14func (r *RootCmd) deleteOrganization(_ *OrganizationContext) *serpent.Command {
15 cmd := &serpent.Command{
16 Use: "delete <organization_name_or_id>",
17 Short: "Delete an organization",
18 Middleware: serpent.Chain(
19 serpent.RequireNArgs(1),
20 ),
21 Options: serpent.OptionSet{
22 cliui.SkipPromptOption(),
23 },
24 Handler: func(inv *serpent.Invocation) error {
25 client, err := r.InitClient(inv)
26 if err != nil {
27 return err
28 }
29
30 orgArg := inv.Args[0]
31 organization, err := client.OrganizationByName(inv.Context(), orgArg)
32 if err != nil {
33 return err
34 }
35
36 if organization.IsDefault {
37 return xerrors.Errorf("cannot delete the default organization %q", organization.Name)
38 }
39
40 _, err = cliui.Prompt(inv, cliui.PromptOptions{
41 Text: fmt.Sprintf("Delete organization %s?", pretty.Sprint(cliui.DefaultStyles.Code, organization.Name)),
42 IsConfirm: true,
43 Default: cliui.ConfirmNo,
44 })
45 if err != nil {
46 return err
47 }
48
49 err = client.DeleteOrganization(inv.Context(), organization.ID.String())
50 if err != nil {
51 return xerrors.Errorf("delete organization %q: %w", organization.Name, err)
52 }
53
54 _, _ = fmt.Fprintf(
55 inv.Stdout,
56 "Deleted organization %s at %s\n",
57 pretty.Sprint(cliui.DefaultStyles.Keyword, organization.Name),
58 cliui.Timestamp(time.Now()),
59 )
60 return nil
61 },
62 }
63
64 return cmd
65}

Callers 3

organizationsMethod · 0.95
deleteOrganizationFunction · 0.45
deleteOrganizationFunction · 0.45

Calls 9

InitClientMethod · 0.95
SkipPromptOptionFunction · 0.92
PromptFunction · 0.92
TimestampFunction · 0.92
OrganizationByNameMethod · 0.80
ContextMethod · 0.65
ErrorfMethod · 0.45
DeleteOrganizationMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected