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

Method stop

cli/stop.go:13–66  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11)
12
13func (r *RootCmd) stop() *serpent.Command {
14 var bflags buildFlags
15 cmd := &serpent.Command{
16 Annotations: workspaceCommand,
17 Use: "stop <workspace>",
18 Short: "Stop a workspace",
19 Middleware: serpent.Chain(
20 serpent.RequireNArgs(1),
21 ),
22 Options: serpent.OptionSet{
23 cliui.SkipPromptOption(),
24 },
25 Handler: func(inv *serpent.Invocation) error {
26 client, err := r.InitClient(inv)
27 if err != nil {
28 return err
29 }
30
31 _, err = cliui.Prompt(inv, cliui.PromptOptions{
32 Text: "Confirm stop workspace?",
33 IsConfirm: true,
34 })
35 if err != nil {
36 return err
37 }
38
39 workspace, err := client.ResolveWorkspace(inv.Context(), inv.Args[0])
40 if err != nil {
41 return err
42 }
43
44 build, err := stopWorkspace(inv, client, workspace, bflags)
45 if err != nil {
46 return err
47 }
48
49 err = cliui.WorkspaceBuild(inv.Context(), inv.Stdout, client, build.ID)
50 if err != nil {
51 return err
52 }
53
54 _, _ = fmt.Fprintf(
55 inv.Stdout,
56 "\nThe %s workspace has been stopped at %s!\n",
57 cliui.Keyword(workspace.Name),
58 cliui.Timestamp(time.Now()),
59 )
60 return nil
61 },
62 }
63 cmd.Options = append(cmd.Options, bflags.cliOptions()...)
64
65 return cmd
66}
67
68func stopWorkspace(inv *serpent.Invocation, client *codersdk.Client, workspace codersdk.Workspace, bflags buildFlags) (codersdk.WorkspaceBuild, error) {
69 if workspace.LatestBuild.Job.Status == codersdk.ProvisionerJobPending {

Callers 1

CoreSubcommandsMethod · 0.95

Calls 10

InitClientMethod · 0.95
cliOptionsMethod · 0.95
SkipPromptOptionFunction · 0.92
PromptFunction · 0.92
WorkspaceBuildFunction · 0.92
KeywordFunction · 0.92
TimestampFunction · 0.92
ResolveWorkspaceMethod · 0.80
stopWorkspaceFunction · 0.70
ContextMethod · 0.65

Tested by

no test coverage detected