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

Commit517a505

Browse files
committed
feat(cli): add provisioner warning to create/start/stop commands
1 parente1423f5 commit517a505

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

‎cli/create.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/coder/pretty"
1515

1616
"github.com/coder/coder/v2/cli/cliui"
17+
"github.com/coder/coder/v2/cli/cliutil"
1718
"github.com/coder/coder/v2/coderd/util/ptr"
1819
"github.com/coder/coder/v2/coderd/util/slice"
1920
"github.com/coder/coder/v2/codersdk"
@@ -289,7 +290,7 @@ func (r *RootCmd) create() *serpent.Command {
289290
ttlMillis=ptr.Ref(stopAfter.Milliseconds())
290291
}
291292

292-
workspace,err:=client.CreateWorkspace(inv.Context(),template.OrganizationID,workspaceOwner, codersdk.CreateWorkspaceRequest{
293+
workspace,err:=client.CreateUserWorkspace(inv.Context(),workspaceOwner, codersdk.CreateWorkspaceRequest{
293294
TemplateVersionID:templateVersionID,
294295
Name:workspaceName,
295296
AutostartSchedule:schedSpec,
@@ -301,6 +302,8 @@ func (r *RootCmd) create() *serpent.Command {
301302
returnxerrors.Errorf("create workspace: %w",err)
302303
}
303304

305+
cliutil.WarnMatchedProvisioners(inv.Stderr,workspace.LatestBuild.MatchedProvisioners,workspace.LatestBuild.Job)
306+
304307
err=cliui.WorkspaceBuild(inv.Context(),inv.Stdout,client,workspace.LatestBuild.ID)
305308
iferr!=nil {
306309
returnxerrors.Errorf("watch build: %w",err)

‎cli/start.go‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"golang.org/x/xerrors"
99

1010
"github.com/coder/coder/v2/cli/cliui"
11+
"github.com/coder/coder/v2/cli/cliutil"
1112
"github.com/coder/coder/v2/codersdk"
1213
"github.com/coder/serpent"
1314
)
@@ -35,6 +36,23 @@ func (r *RootCmd) start() *serpent.Command {
3536
}
3637
varbuild codersdk.WorkspaceBuild
3738
switchworkspace.LatestBuild.Status {
39+
casecodersdk.WorkspaceStatusPending:
40+
// The above check is technically duplicated in cliutil.WarnmatchedProvisioners
41+
// but we still want to avoid users spamming multiple builds that will
42+
// not be picked up.
43+
_,_=fmt.Fprintf(
44+
inv.Stdout,
45+
"\nThe %s workspace is waiting to start!\n",
46+
cliui.Keyword(workspace.Name),
47+
)
48+
cliutil.WarnMatchedProvisioners(inv.Stderr,workspace.LatestBuild.MatchedProvisioners,workspace.LatestBuild.Job)
49+
if_,err:=cliui.Prompt(inv, cliui.PromptOptions{
50+
Text:"Enqueue another start?",
51+
IsConfirm:true,
52+
Default:cliui.ConfirmNo,
53+
});err!=nil {
54+
returnerr
55+
}
3856
casecodersdk.WorkspaceStatusRunning:
3957
_,_=fmt.Fprintf(
4058
inv.Stdout,"\nThe %s workspace is already running!\n",
@@ -159,6 +177,7 @@ func startWorkspace(inv *serpent.Invocation, client *codersdk.Client, workspace
159177
iferr!=nil {
160178
return codersdk.WorkspaceBuild{},xerrors.Errorf("create workspace build: %w",err)
161179
}
180+
cliutil.WarnMatchedProvisioners(inv.Stderr,build.MatchedProvisioners,build.Job)
162181

163182
returnbuild,nil
164183
}

‎cli/stop.go‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"time"
66

77
"github.com/coder/coder/v2/cli/cliui"
8+
"github.com/coder/coder/v2/cli/cliutil"
89
"github.com/coder/coder/v2/codersdk"
910
"github.com/coder/serpent"
1011
)
@@ -36,6 +37,21 @@ func (r *RootCmd) stop() *serpent.Command {
3637
iferr!=nil {
3738
returnerr
3839
}
40+
ifworkspace.LatestBuild.Job.Status==codersdk.ProvisionerJobPending {
41+
// cliutil.WarnMatchedProvisioners also checks if the job is pending
42+
// but we still want to avoid users spamming multiple builds that will
43+
// not be picked up.
44+
cliui.Warn(inv.Stderr,"The workspace is already stopping!")
45+
cliutil.WarnMatchedProvisioners(inv.Stderr,workspace.LatestBuild.MatchedProvisioners,workspace.LatestBuild.Job)
46+
if_,err:=cliui.Prompt(inv, cliui.PromptOptions{
47+
Text:"Enqueue another stop?",
48+
IsConfirm:true,
49+
Default:cliui.ConfirmNo,
50+
});err!=nil {
51+
returnerr
52+
}
53+
}
54+
3955
wbr:= codersdk.CreateWorkspaceBuildRequest{
4056
Transition:codersdk.WorkspaceTransitionStop,
4157
}
@@ -46,6 +62,7 @@ func (r *RootCmd) stop() *serpent.Command {
4662
iferr!=nil {
4763
returnerr
4864
}
65+
cliutil.WarnMatchedProvisioners(inv.Stderr,build.MatchedProvisioners,build.Job)
4966

5067
err=cliui.WorkspaceBuild(inv.Context(),inv.Stdout,client,build.ID)
5168
iferr!=nil {

‎cli/templatepush.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ func createValidTemplateVersion(inv *serpent.Invocation, args createValidTemplat
416416
iferr!=nil {
417417
returnnil,err
418418
}
419-
cliutil.WarnMatchedProvisioners(inv.Stderr,version)
419+
cliutil.WarnMatchedProvisioners(inv.Stderr,version.MatchedProvisioners,version.Job)
420420
err=cliui.ProvisionerJob(inv.Context(),inv.Stdout, cliui.ProvisionerJobOptions{
421421
Fetch:func() (codersdk.ProvisionerJob,error) {
422422
version,err:=client.TemplateVersion(inv.Context(),version.ID)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp