-
Notifications
You must be signed in to change notification settings - Fork 1
add sub-account deletion to the CLI #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,54 @@ | ||||||||||
| package organizations | ||||||||||
|
|
||||||||||
| import ( | ||||||||||
| "context" | ||||||||||
| "fmt" | ||||||||||
|
|
||||||||||
| "github.com/mailtrap/mailtrap-cli/internal/client" | ||||||||||
| "github.com/mailtrap/mailtrap-cli/internal/cmdutil" | ||||||||||
| "github.com/spf13/cobra" | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| func NewCmdDeleteSubAccount(f *cmdutil.Factory) *cobra.Command { | ||||||||||
| var orgID string | ||||||||||
| var subAccountID string | ||||||||||
|
|
||||||||||
| cmd := &cobra.Command{ | ||||||||||
| Use: "delete-sub-account", | ||||||||||
| Short: "Delete a sub-account from an organization", | ||||||||||
| Long: `Delete a sub-account from an organization. Requires sub-account management permissions for the organization. | ||||||||||
|
|
||||||||||
| The deletion is permanent: the sub-account and all of its data are removed and cannot be restored. | ||||||||||
| Deleting the organization's last sub-account also deletes the organization. | ||||||||||
|
|
||||||||||
| A repeated call for the same sub-account returns 404. Rate limit: 10 requests per minute per organization.`, | ||||||||||
| RunE: func(cmd *cobra.Command, args []string) error { | ||||||||||
| if err := cmdutil.RequireFlag("org-id", orgID); err != nil { | ||||||||||
| return err | ||||||||||
| } | ||||||||||
| if err := cmdutil.RequireFlag("sub-account-id", subAccountID); err != nil { | ||||||||||
| return err | ||||||||||
| } | ||||||||||
|
|
||||||||||
| c, err := f.NewClient() | ||||||||||
| if err != nil { | ||||||||||
| return err | ||||||||||
| } | ||||||||||
|
|
||||||||||
| path := fmt.Sprintf("/api/organizations/%s/sub_accounts/%s", orgID, subAccountID) | ||||||||||
|
|
||||||||||
| if err := c.Delete(context.Background(), client.BaseGeneral, path, nil); err != nil { | ||||||||||
| return err | ||||||||||
| } | ||||||||||
|
|
||||||||||
| fmt.Fprintf(f.IOStreams.Out, "Sub-account %s deleted successfully\n", subAccountID) | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🤖 get_repo_knowledge executed:
Length of output: 21813 🏁 Script executed: sed -n '1,140p' internal/commands/organizations/delete_sub_account.go
printf '\n--- related output error handling ---\n'
rg -n -U 'fmt\.Fprintf\(.*IOStreams\.Out|IOStreams\.Out.*Fprintf|return err' internal/commands/organizationsRepository: mailtrap/mailtrap-cli Length of output: 2709 Return the output write error. If Proposed fix- fmt.Fprintf(f.IOStreams.Out, "Sub-account %s deleted successfully\n", subAccountID)
+ if _, err := fmt.Fprintf(f.IOStreams.Out, "Sub-account %s deleted successfully\n", subAccountID); err != nil {
+ return err
+ }📝 Committable suggestion
Suggested change
🧰 Tools🪛 golangci-lint (2.13.2)[error] 44-44: Error return value of (errcheck) 🤖 Prompt for AI AgentsSource: Linters/SAST tools |
||||||||||
|
|
||||||||||
| return nil | ||||||||||
| }, | ||||||||||
| } | ||||||||||
|
|
||||||||||
| cmd.Flags().StringVar(&orgID, "org-id", "", "Organization ID") | ||||||||||
| cmd.Flags().StringVar(&subAccountID, "sub-account-id", "", "Sub-account ID") | ||||||||||
|
|
||||||||||
| return cmd | ||||||||||
| } | ||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Correct the Test Cases total.
The displayed category values sum to 115 test cases, not approximately 108. The endpoint total of 91 is correct.
🤖 Prompt for AI Agents