Skip to content

Commit e0fd5af

Browse files
committed
fix(cli/delete): prompt confirmation after workspace found
1 parent 98164f6 commit e0fd5af

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

cli/delete.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,19 @@ func (r *RootCmd) deleteWorkspace() *clibase.Cmd {
2222
r.InitClient(client),
2323
),
2424
Handler: func(inv *clibase.Invocation) error {
25-
_, err := cliui.Prompt(inv, cliui.PromptOptions{
26-
Text: "Confirm delete workspace?",
27-
IsConfirm: true,
28-
Default: cliui.ConfirmNo,
29-
})
25+
workspace, err := namedWorkspace(inv.Context(), client, inv.Args[0])
3026
if err != nil {
3127
return err
3228
}
3329

34-
workspace, err := namedWorkspace(inv.Context(), client, inv.Args[0])
30+
sinceLastUsed := time.Since(workspace.LastUsedAt)
31+
cliui.Infof(inv.Stderr, "%v was last used %.0f days ago", workspace.FullName(), sinceLastUsed.Hours()/24)
32+
33+
_, err = cliui.Prompt(inv, cliui.PromptOptions{
34+
Text: "Confirm delete workspace?",
35+
IsConfirm: true,
36+
Default: cliui.ConfirmNo,
37+
})
3538
if err != nil {
3639
return err
3740
}
@@ -51,7 +54,7 @@ func (r *RootCmd) deleteWorkspace() *clibase.Cmd {
5154
return err
5255
}
5356

54-
_, _ = fmt.Fprintf(inv.Stdout, "\nThe %s workspace has been deleted at %s!\n", cliui.DefaultStyles.Keyword.Render(workspace.Name), cliui.DefaultStyles.DateTimeStamp.Render(time.Now().Format(time.Stamp)))
57+
_, _ = fmt.Fprintf(inv.Stdout, "\n%s has been deleted at %s!\n", cliui.DefaultStyles.Keyword.Render(workspace.FullName()), cliui.DefaultStyles.DateTimeStamp.Render(time.Now().Format(time.Stamp)))
5558
return nil
5659
},
5760
}

codersdk/workspaces.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ type Workspace struct {
4848
Health WorkspaceHealth `json:"health"`
4949
}
5050

51+
func (w Workspace) FullName() string {
52+
return fmt.Sprintf("%s/%s", w.OwnerName, w.Name)
53+
}
54+
5155
type WorkspaceHealth struct {
5256
Healthy bool `json:"healthy" example:"false"` // Healthy is true if the workspace is healthy.
5357
FailingAgents []uuid.UUID `json:"failing_agents" format:"uuid"` // FailingAgents lists the IDs of the agents that are failing, if any.

0 commit comments

Comments
 (0)