Skip to content

Commit 517a505

Browse files
committed
feat(cli): add provisioner warning to create/start/stop commands
1 parent e1423f5 commit 517a505

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
return xerrors.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
if err != nil {
306309
return xerrors.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
var build codersdk.WorkspaceBuild
3738
switch workspace.LatestBuild.Status {
39+
case codersdk.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+
return err
55+
}
3856
case codersdk.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
if err != nil {
160178
return codersdk.WorkspaceBuild{}, xerrors.Errorf("create workspace build: %w", err)
161179
}
180+
cliutil.WarnMatchedProvisioners(inv.Stderr, build.MatchedProvisioners, build.Job)
162181

163182
return build, 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
if err != nil {
3738
return err
3839
}
40+
if workspace.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+
return err
52+
}
53+
}
54+
3955
wbr := codersdk.CreateWorkspaceBuildRequest{
4056
Transition: codersdk.WorkspaceTransitionStop,
4157
}
@@ -46,6 +62,7 @@ func (r *RootCmd) stop() *serpent.Command {
4662
if err != nil {
4763
return err
4864
}
65+
cliutil.WarnMatchedProvisioners(inv.Stderr, build.MatchedProvisioners, build.Job)
4966

5067
err = cliui.WorkspaceBuild(inv.Context(), inv.Stdout, client, build.ID)
5168
if err != 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
if err != nil {
417417
return nil, 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)