Skip to content

Commit c33f9b9

Browse files
committed
confirm before stop
1 parent 31ff27d commit c33f9b9

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

cli/update.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,22 @@ func (r *RootCmd) update() *serpent.Command {
3939
// updating. Simply performing a new start transition may not work if the
4040
// template specifies ignore_changes.
4141
if workspace.LatestBuild.Transition == codersdk.WorkspaceTransitionStart {
42-
build, err := stopWorkspace(inv, client, workspace, bflags)
43-
if err != nil {
44-
return xerrors.Errorf("stop workspace: %w", err)
45-
}
46-
// Wait for the stop to complete.
47-
if err := cliui.WorkspaceBuild(inv.Context(), inv.Stdout, client, build.ID); err != nil {
48-
return xerrors.Errorf("wait for stop: %w", err)
42+
// It's polite to ask the user before stopping their workspace.
43+
cliui.Info(inv.Stdout, "Your workspace is currently running. We recommend stopping it before proceeding.")
44+
if _, err := cliui.Prompt(inv, cliui.PromptOptions{
45+
Text: "Confirm stop workspace?",
46+
IsConfirm: true,
47+
}); err != nil {
48+
cliui.Warnf(inv.Stderr, "Updating without stop.")
49+
} else {
50+
build, err := stopWorkspace(inv, client, workspace, bflags)
51+
if err != nil {
52+
return xerrors.Errorf("stop workspace: %w", err)
53+
}
54+
// Wait for the stop to complete.
55+
if err := cliui.WorkspaceBuild(inv.Context(), inv.Stdout, client, build.ID); err != nil {
56+
return xerrors.Errorf("wait for stop: %w", err)
57+
}
4958
}
5059
}
5160

cli/update_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,16 @@ func TestUpdate(t *testing.T) {
7171
inv, root := clitest.New(t, "update", ws.Name)
7272
clitest.SetupConfig(t, member, root)
7373

74-
err = inv.Run()
75-
require.NoError(t, err, "update command failed")
74+
doneCh := make(chan error)
75+
pty := ptytest.New(t).Attach(inv)
76+
go func() {
77+
defer close(doneCh)
78+
doneCh <- inv.Run()
79+
}()
80+
81+
pty.ExpectMatch("Confirm stop workspace?")
82+
pty.WriteLine("yes")
83+
require.NoError(t, testutil.TryReceive(ctx, t, doneCh), "update command failed to run")
7684

7785
// Then: the workspace is no longer 'outdated'
7886
ws, err = member.WorkspaceByOwnerAndName(ctx, codersdk.Me, "my-workspace", codersdk.WorkspaceOptions{})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy