MCPcopy Index your code
hub / github.com/coder/coder / start

Method start

cli/start.go:16–141  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14)
15
16func (r *RootCmd) start() *serpent.Command {
17 var (
18 parameterFlags workspaceParameterFlags
19 bflags buildFlags
20
21 noWait bool
22 )
23
24 cmd := &serpent.Command{
25 Annotations: workspaceCommand,
26 Use: "start <workspace>",
27 Short: "Start a workspace",
28 Middleware: serpent.Chain(
29 serpent.RequireNArgs(1),
30 ),
31 Options: serpent.OptionSet{
32 {
33 Flag: "no-wait",
34 Description: "Return immediately after starting the workspace.",
35 Value: serpent.BoolOf(&noWait),
36 Hidden: false,
37 },
38 cliui.SkipPromptOption(),
39 },
40 Handler: func(inv *serpent.Invocation) error {
41 client, err := r.InitClient(inv)
42 if err != nil {
43 return err
44 }
45
46 workspace, err := client.ResolveWorkspace(inv.Context(), inv.Args[0])
47 if err != nil {
48 return err
49 }
50 var build codersdk.WorkspaceBuild
51 switch workspace.LatestBuild.Status {
52 case codersdk.WorkspaceStatusPending:
53 // The above check is technically duplicated in cliutil.WarnmatchedProvisioners
54 // but we still want to avoid users spamming multiple builds that will
55 // not be picked up.
56 _, _ = fmt.Fprintf(
57 inv.Stdout,
58 "\nThe %s workspace is waiting to start!\n",
59 cliui.Keyword(workspace.Name),
60 )
61 cliutil.WarnMatchedProvisioners(inv.Stderr, workspace.LatestBuild.MatchedProvisioners, workspace.LatestBuild.Job)
62 if _, err := cliui.Prompt(inv, cliui.PromptOptions{
63 Text: "Enqueue another start?",
64 IsConfirm: true,
65 Default: cliui.ConfirmNo,
66 }); err != nil {
67 return err
68 }
69 case codersdk.WorkspaceStatusRunning:
70 _, _ = fmt.Fprintf(
71 inv.Stdout, "\nThe %s workspace is already running!\n",
72 cliui.Keyword(workspace.Name),
73 )

Callers 1

CoreSubcommandsMethod · 0.95

Calls 15

InitClientMethod · 0.95
SkipPromptOptionFunction · 0.92
KeywordFunction · 0.92
WarnMatchedProvisionersFunction · 0.92
PromptFunction · 0.92
WorkspaceBuildFunction · 0.92
AsErrorFunction · 0.92
TimestampFunction · 0.92
ResolveWorkspaceMethod · 0.80
CreateWorkspaceBuildMethod · 0.80
allOptionsMethod · 0.80
cliOptionsMethod · 0.80

Tested by

no test coverage detected