Skip to content

Commit 81752d1

Browse files
authored
fix(cli/delete): prompt for confirmation after workspace is found (#8579)
1 parent eddaa77 commit 81752d1

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

cli/delete.go

+10-7
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
}

cli/delete_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestDelete(t *testing.T) {
4141
assert.ErrorIs(t, err, io.EOF)
4242
}
4343
}()
44-
pty.ExpectMatch("workspace has been deleted")
44+
pty.ExpectMatch("has been deleted")
4545
<-doneChan
4646
})
4747

@@ -68,7 +68,7 @@ func TestDelete(t *testing.T) {
6868
assert.ErrorIs(t, err, io.EOF)
6969
}
7070
}()
71-
pty.ExpectMatch("workspace has been deleted")
71+
pty.ExpectMatch("has been deleted")
7272
<-doneChan
7373
})
7474

@@ -113,7 +113,7 @@ func TestDelete(t *testing.T) {
113113
assert.ErrorIs(t, err, io.EOF)
114114
}
115115
}()
116-
pty.ExpectMatch("workspace has been deleted")
116+
pty.ExpectMatch("has been deleted")
117117
<-doneChan
118118
})
119119

@@ -145,7 +145,7 @@ func TestDelete(t *testing.T) {
145145
}
146146
}()
147147

148-
pty.ExpectMatch("workspace has been deleted")
148+
pty.ExpectMatch("has been deleted")
149149
<-doneChan
150150

151151
workspace, err = client.Workspace(context.Background(), workspace.ID)

codersdk/workspaces.go

+4
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)