Skip to content

Commit

Permalink
feat: add delete workspace confirmation prompt
Browse files Browse the repository at this point in the history
Signed-off-by: tarunrajput <[email protected]>
  • Loading branch information
tarunrajput committed Apr 11, 2024
1 parent 0c1706f commit 8e15952
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions pkg/cmd/workspace/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,36 @@ var DeleteCmd = &cobra.Command{
return
}

res, err := apiClient.WorkspaceAPI.RemoveWorkspace(ctx, *workspace.Id).Execute()
if err != nil {
log.Fatal(apiclient.HandleErrorResponse(res, err))
}

err = config.RemoveWorkspaceSshEntries(activeProfile.Id, *workspace.Id)
if err != nil {
var confirmDeletionFlag bool

form := huh.NewForm(
huh.NewGroup(
huh.NewConfirm().
Title("Delete workspace?").
Description("Are you sure you want to delete this workspace?").
Value(&confirmDeletionFlag),
),
).WithTheme(views.GetCustomTheme())

if err := form.Run(); err != nil {
log.Fatal(err)
}

util.RenderInfoMessage(fmt.Sprintf("Workspace %s successfully deleted", *workspace.Name))
if confirmDeletionFlag {
res, err := apiClient.WorkspaceAPI.RemoveWorkspace(ctx, *workspace.Id).Execute()
if err != nil {
log.Fatal(apiclient.HandleErrorResponse(res, err))
}

err = config.RemoveWorkspaceSshEntries(activeProfile.Id, *workspace.Id)
if err != nil {
log.Fatal(err)
}

util.RenderInfoMessage(fmt.Sprintf("Workspace %s successfully deleted", *workspace.Name))
} else {
fmt.Println("Operation canceled.")
}
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) > 0 {
Expand Down

0 comments on commit 8e15952

Please sign in to comment.