()
| 12 | ) |
| 13 | |
| 14 | func (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 | } |
no test coverage detected