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

Method groupDelete

enterprise/cli/groupdelete.go:14–54  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12)
13
14func (r *RootCmd) groupDelete() *serpent.Command {
15 orgContext := agpl.NewOrganizationContext()
16 cmd := &serpent.Command{
17 Use: "delete <name>",
18 Short: "Delete a user group",
19 Middleware: serpent.Chain(
20 serpent.RequireNArgs(1),
21 ),
22 Handler: func(inv *serpent.Invocation) error {
23 var (
24 ctx = inv.Context()
25 groupName = inv.Args[0]
26 )
27 client, err := r.InitClient(inv)
28 if err != nil {
29 return err
30 }
31
32 org, err := orgContext.Selected(inv, client)
33 if err != nil {
34 return xerrors.Errorf("current organization: %w", err)
35 }
36
37 group, err := client.GroupByOrgAndName(ctx, org.ID, groupName)
38 if err != nil {
39 return xerrors.Errorf("group by org and name: %w", err)
40 }
41
42 err = client.DeleteGroup(ctx, group.ID)
43 if err != nil {
44 return xerrors.Errorf("delete group: %w", err)
45 }
46
47 _, _ = fmt.Fprintf(inv.Stdout, "Successfully deleted group %s!\n", pretty.Sprint(cliui.DefaultStyles.Keyword, group.Name))
48 return nil
49 },
50 }
51 orgContext.AttachOptions(cmd)
52
53 return cmd
54}

Callers 1

groupsMethod · 0.95

Calls 7

InitClientMethod · 0.95
SelectedMethod · 0.95
AttachOptionsMethod · 0.95
GroupByOrgAndNameMethod · 0.80
DeleteGroupMethod · 0.80
ContextMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected