-
Notifications
You must be signed in to change notification settings - Fork 5
CLI: Update SDK to v0.37.0 and add profiles list params #118
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
Changes from all commits
ba1640c
d36bb6c
256b8e3
0394312
74ca985
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 |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import ( | |
| "github.com/pterm/pterm" | ||
| "github.com/samber/lo" | ||
| "github.com/spf13/cobra" | ||
| "golang.org/x/sync/errgroup" | ||
| ) | ||
|
|
||
| var appCmd = &cobra.Command{ | ||
|
|
@@ -25,7 +26,14 @@ var appListCmd = &cobra.Command{ | |
| RunE: runAppList, | ||
| } | ||
|
|
||
| // --- app history subcommand (scaffold) | ||
| var appDeleteCmd = &cobra.Command{ | ||
| Use: "delete <app_name>", | ||
| Short: "Delete an app and all its deployments", | ||
| Long: "Deletes all deployments for an application. Use --version to scope deletion to a specific version.", | ||
| Args: cobra.ExactArgs(1), | ||
| RunE: runAppDelete, | ||
| } | ||
|
|
||
| var appHistoryCmd = &cobra.Command{ | ||
| Use: "history <app_name>", | ||
| Short: "Show deployment history for an application", | ||
|
|
@@ -36,8 +44,13 @@ var appHistoryCmd = &cobra.Command{ | |
| func init() { | ||
| // register subcommands under app | ||
| appCmd.AddCommand(appListCmd) | ||
| appCmd.AddCommand(appDeleteCmd) | ||
| appCmd.AddCommand(appHistoryCmd) | ||
|
|
||
| // Flags for delete | ||
| appDeleteCmd.Flags().String("version", "", "Only delete deployments for this version (default: all versions)") | ||
| appDeleteCmd.Flags().BoolP("yes", "y", false, "Skip confirmation prompt") | ||
|
|
||
| // Add optional filters for list | ||
| appListCmd.Flags().String("name", "", "Filter by application name") | ||
| appListCmd.Flags().String("version", "", "Filter by version label") | ||
|
|
@@ -206,6 +219,76 @@ func runAppList(cmd *cobra.Command, args []string) error { | |
| return nil | ||
| } | ||
|
|
||
| func runAppDelete(cmd *cobra.Command, args []string) error { | ||
| client := getKernelClient(cmd) | ||
| appName := args[0] | ||
| version, _ := cmd.Flags().GetString("version") | ||
| skipConfirm, _ := cmd.Flags().GetBool("yes") | ||
|
|
||
| params := kernel.DeploymentListParams{ | ||
| AppName: kernel.Opt(appName), | ||
| Limit: kernel.Opt(int64(100)), | ||
| Offset: kernel.Opt(int64(0)), | ||
| } | ||
| if version != "" { | ||
| params.AppVersion = kernel.Opt(version) | ||
| } | ||
|
|
||
| initial, err := client.Deployments.List(cmd.Context(), params) | ||
| if err != nil { | ||
| return util.CleanedUpSdkError{Err: err} | ||
| } | ||
| if initial == nil || len(initial.Items) == 0 { | ||
| pterm.Info.Printf("No deployments found for app '%s'\n", appName) | ||
| return nil | ||
| } | ||
|
|
||
| if !skipConfirm { | ||
| scope := "all versions" | ||
| if version != "" { | ||
| scope = fmt.Sprintf("version '%s'", version) | ||
| } | ||
| msg := fmt.Sprintf("Delete all deployments for app '%s' (%s)? This cannot be undone.", appName, scope) | ||
| pterm.DefaultInteractiveConfirm.DefaultText = msg | ||
| ok, _ := pterm.DefaultInteractiveConfirm.Show() | ||
| if !ok { | ||
| pterm.Info.Println("Deletion cancelled") | ||
| return nil | ||
| } | ||
| } | ||
|
|
||
| spinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Deleting deployments for app '%s'...", appName)) | ||
| deleted := 0 | ||
|
|
||
| for { | ||
| page, err := client.Deployments.List(cmd.Context(), params) | ||
| if err != nil { | ||
| spinner.Fail("Failed to list deployments") | ||
| return util.CleanedUpSdkError{Err: err} | ||
| } | ||
| items := page.Items | ||
| if len(items) == 0 { | ||
| break | ||
| } | ||
|
|
||
| g, gctx := errgroup.WithContext(cmd.Context()) | ||
|
Contributor
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. nit: no concurrency limit on the errgroup — this fires up to 100 parallel deletes per page. |
||
| for _, dep := range items { | ||
| g.Go(func() error { | ||
| return client.Deployments.Delete(gctx, dep.ID) | ||
| }) | ||
|
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. Batch delete missing not-found handling causes unnecessary failuresMedium Severity The batch delete goroutines in |
||
| } | ||
|
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. Unbounded parallel deletes may overwhelm the APIMedium Severity The |
||
| if err := g.Wait(); err != nil { | ||
|
Contributor
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. if one delete in the batch fails, |
||
| spinner.Fail("Failed to delete deployments") | ||
| return util.CleanedUpSdkError{Err: err} | ||
| } | ||
|
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. Batch delete error discards partial progress countMedium Severity When |
||
| deleted += len(items) | ||
| spinner.UpdateText(fmt.Sprintf("Deleted %d deployment(s) so far...", deleted)) | ||
| } | ||
|
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. Deletion loop may infinite-loop on async deletesHigh Severity The deletion loop always re-lists deployments at Additional Locations (1) |
||
|
|
||
| spinner.Success(fmt.Sprintf("Deleted %d deployment(s) for app '%s'", deleted, appName)) | ||
| return nil | ||
| } | ||
|
|
||
| func runAppHistory(cmd *cobra.Command, args []string) error { | ||
| client := getKernelClient(cmd) | ||
| appName := args[0] | ||
|
|
||


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.
nit: this initial list fetch is only used as an existence check and then thrown away — the deletion loop re-lists from offset 0 anyway. could skip this entirely and just check
deleted == 0after the loop to print "no deployments found"