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

Commit56082f3

Browse files
authored
feat(cli): start workspace in no-wait mode (#17087)
Fixes:#16408
1 parentcd19e79 commit56082f3

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

‎cli/start.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ func (r *RootCmd) start() *serpent.Command {
1717
var (
1818
parameterFlagsworkspaceParameterFlags
1919
bflagsbuildFlags
20+
21+
noWaitbool
2022
)
2123

2224
client:=new(codersdk.Client)
@@ -28,7 +30,15 @@ func (r *RootCmd) start() *serpent.Command {
2830
serpent.RequireNArgs(1),
2931
r.InitClient(client),
3032
),
31-
Options: serpent.OptionSet{cliui.SkipPromptOption()},
33+
Options: serpent.OptionSet{
34+
{
35+
Flag:"no-wait",
36+
Description:"Return immediately after starting the workspace.",
37+
Value:serpent.BoolOf(&noWait),
38+
Hidden:false,
39+
},
40+
cliui.SkipPromptOption(),
41+
},
3242
Handler:func(inv*serpent.Invocation)error {
3343
workspace,err:=namedWorkspace(inv.Context(),client,inv.Args[0])
3444
iferr!=nil {
@@ -80,6 +90,11 @@ func (r *RootCmd) start() *serpent.Command {
8090
}
8191
}
8292

93+
ifnoWait {
94+
_,_=fmt.Fprintf(inv.Stdout,"The %s workspace has been started in no-wait mode. Workspace is building in the background.\n",cliui.Keyword(workspace.Name))
95+
returnnil
96+
}
97+
8398
err=cliui.WorkspaceBuild(inv.Context(),inv.Stdout,client,build.ID)
8499
iferr!=nil {
85100
returnerr

‎cli/start_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,3 +441,36 @@ func TestStart_Starting(t *testing.T) {
441441

442442
_=testutil.RequireRecvCtx(ctx,t,doneChan)
443443
}
444+
445+
funcTestStart_NoWait(t*testing.T) {
446+
t.Parallel()
447+
ctx:=testutil.Context(t,testutil.WaitShort)
448+
449+
// Prepare user, template, workspace
450+
client:=coderdtest.New(t,&coderdtest.Options{IncludeProvisionerDaemon:true})
451+
owner:=coderdtest.CreateFirstUser(t,client)
452+
member,_:=coderdtest.CreateAnotherUser(t,client,owner.OrganizationID)
453+
version1:=coderdtest.CreateTemplateVersion(t,client,owner.OrganizationID,nil)
454+
coderdtest.AwaitTemplateVersionJobCompleted(t,client,version1.ID)
455+
template:=coderdtest.CreateTemplate(t,client,owner.OrganizationID,version1.ID)
456+
workspace:=coderdtest.CreateWorkspace(t,member,template.ID)
457+
coderdtest.AwaitWorkspaceBuildJobCompleted(t,client,workspace.LatestBuild.ID)
458+
459+
// Stop the workspace
460+
build:=coderdtest.CreateWorkspaceBuild(t,member,workspace,database.WorkspaceTransitionStop)
461+
coderdtest.AwaitWorkspaceBuildJobCompleted(t,client,build.ID)
462+
463+
// Start in no-wait mode
464+
inv,root:=clitest.New(t,"start",workspace.Name,"--no-wait")
465+
clitest.SetupConfig(t,member,root)
466+
doneChan:=make(chanstruct{})
467+
pty:=ptytest.New(t).Attach(inv)
468+
gofunc() {
469+
deferclose(doneChan)
470+
err:=inv.Run()
471+
assert.NoError(t,err)
472+
}()
473+
474+
pty.ExpectMatch("workspace has been started in no-wait mode")
475+
_=testutil.RequireRecvCtx(ctx,t,doneChan)
476+
}

‎cli/testdata/coder_start_--help.golden

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ OPTIONS:
2222
Set the value of ephemeral parameters defined in the template. The
2323
format is "name=value".
2424

25+
--no-wait bool
26+
Return immediately after starting the workspace.
27+
2528
--parameter string-array, $CODER_RICH_PARAMETER
2629
Rich parameter value in the format "name=value".
2730

‎docs/reference/cli/start.md

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp