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