Skip to content

fix(cli/delete): prompt for confirmation after workspace is found #8579

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

Merged
merged 1 commit into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(cli/delete): prompt for confirmation after workspace is found
  • Loading branch information
ammario committed Jul 25, 2023
commit 682af8add2cb3284f29eb513e9a27ed800f947ed
17 changes: 10 additions & 7 deletions cli/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@ func (r *RootCmd) deleteWorkspace() *clibase.Cmd {
r.InitClient(client),
),
Handler: func(inv *clibase.Invocation) error {
_, err := cliui.Prompt(inv, cliui.PromptOptions{
Text: "Confirm delete workspace?",
IsConfirm: true,
Default: cliui.ConfirmNo,
})
workspace, err := namedWorkspace(inv.Context(), client, inv.Args[0])
if err != nil {
return err
}

workspace, err := namedWorkspace(inv.Context(), client, inv.Args[0])
sinceLastUsed := time.Since(workspace.LastUsedAt)
cliui.Infof(inv.Stderr, "%v was last used %.0f days ago", workspace.FullName(), sinceLastUsed.Hours()/24)

_, err = cliui.Prompt(inv, cliui.PromptOptions{
Text: "Confirm delete workspace?",
IsConfirm: true,
Default: cliui.ConfirmNo,
})
if err != nil {
return err
}
Expand All @@ -51,7 +54,7 @@ func (r *RootCmd) deleteWorkspace() *clibase.Cmd {
return err
}

_, _ = 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)))
_, _ = 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)))
return nil
},
}
Expand Down
8 changes: 4 additions & 4 deletions cli/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestDelete(t *testing.T) {
assert.ErrorIs(t, err, io.EOF)
}
}()
pty.ExpectMatch("workspace has been deleted")
pty.ExpectMatch("has been deleted")
<-doneChan
})

Expand All @@ -68,7 +68,7 @@ func TestDelete(t *testing.T) {
assert.ErrorIs(t, err, io.EOF)
}
}()
pty.ExpectMatch("workspace has been deleted")
pty.ExpectMatch("has been deleted")
<-doneChan
})

Expand Down Expand Up @@ -113,7 +113,7 @@ func TestDelete(t *testing.T) {
assert.ErrorIs(t, err, io.EOF)
}
}()
pty.ExpectMatch("workspace has been deleted")
pty.ExpectMatch("has been deleted")
<-doneChan
})

Expand Down Expand Up @@ -145,7 +145,7 @@ func TestDelete(t *testing.T) {
}
}()

pty.ExpectMatch("workspace has been deleted")
pty.ExpectMatch("has been deleted")
<-doneChan

workspace, err = client.Workspace(context.Background(), workspace.ID)
Expand Down
4 changes: 4 additions & 0 deletions codersdk/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ type Workspace struct {
Health WorkspaceHealth `json:"health"`
}

func (w Workspace) FullName() string {
return fmt.Sprintf("%s/%s", w.OwnerName, w.Name)
}

type WorkspaceHealth struct {
Healthy bool `json:"healthy" example:"false"` // Healthy is true if the workspace is healthy.
FailingAgents []uuid.UUID `json:"failing_agents" format:"uuid"` // FailingAgents lists the IDs of the agents that are failing, if any.
Expand Down