Skip to content

Commit

Permalink
feat: skip workspace removal prompt when target has none (#1271)
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Dagelic <[email protected]>
  • Loading branch information
idagelic authored Oct 18, 2024
1 parent 9aa7180 commit 9b10908
Showing 1 changed file with 38 additions and 15 deletions.
53 changes: 38 additions & 15 deletions pkg/cmd/target/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,50 @@ var targetRemoveCmd = &cobra.Command{
return err
}
} else {
form := huh.NewForm(
huh.NewGroup(
huh.NewConfirm().
Title(fmt.Sprintf("Delete all workspaces within %s?", selectedTargetName)).
Description("You might not be able to easily remove these workspaces later.").
Value(&yesFlag),
),
).WithTheme(views.GetCustomTheme())

err := form.Run()
var targetWorkspaceCount int

workspaceList, res, err := apiClient.WorkspaceAPI.ListWorkspaces(ctx).Execute()
if err != nil {
return err
return apiclient_util.HandleErrorResponse(res, err)
}

if yesFlag {
err := RemoveTargetWorkspaces(ctx, apiClient, selectedTargetName)
for _, workspace := range workspaceList {
if workspace.Target == selectedTargetName {
targetWorkspaceCount++
}
}

if targetWorkspaceCount > 0 {
title := fmt.Sprintf("Delete %d workspaces within %s?", targetWorkspaceCount, selectedTargetName)
description := "You might not be able to easily remove these workspaces later."

if targetWorkspaceCount == 1 {
title = fmt.Sprintf("Delete %d workspace within %s?", targetWorkspaceCount, selectedTargetName)
description = "You might not be able to easily remove this workspace later."
}

form := huh.NewForm(
huh.NewGroup(
huh.NewConfirm().
Title(title).
Description(description).
Value(&yesFlag),
),
).WithTheme(views.GetCustomTheme())

err := form.Run()
if err != nil {
return err
}
} else {
fmt.Println("Proceeding with target removal without deleting workspaces.")

if yesFlag {
err := RemoveTargetWorkspaces(ctx, apiClient, selectedTargetName)
if err != nil {
return err
}
} else {
fmt.Println("Proceeding with target removal without deleting workspaces.")
}
}
}

Expand Down

0 comments on commit 9b10908

Please sign in to comment.