Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc33f9b9

Browse files
committed
confirm before stop
1 parent31ff27d commitc33f9b9

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
ifworkspace.LatestBuild.Transition==codersdk.WorkspaceTransitionStart {
42-
build,err:=stopWorkspace(inv,client,workspace,bflags)
43-
iferr!=nil {
44-
returnxerrors.Errorf("stop workspace: %w",err)
45-
}
46-
// Wait for the stop to complete.
47-
iferr:=cliui.WorkspaceBuild(inv.Context(),inv.Stdout,client,build.ID);err!=nil {
48-
returnxerrors.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+
iferr!=nil {
52+
returnxerrors.Errorf("stop workspace: %w",err)
53+
}
54+
// Wait for the stop to complete.
55+
iferr:=cliui.WorkspaceBuild(inv.Context(),inv.Stdout,client,build.ID);err!=nil {
56+
returnxerrors.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(chanerror)
75+
pty:=ptytest.New(t).Attach(inv)
76+
gofunc() {
77+
deferclose(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)

[8]ページ先頭

©2009-2025 Movatter.jp