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

Method taskPause

cli/task_pause.go:15–90  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13)
14
15func (r *RootCmd) taskPause() *serpent.Command {
16 cmd := &serpent.Command{
17 Use: "pause <task>",
18 Short: "Pause a task",
19 Long: FormatExamples(
20 Example{
21 Description: "Pause a task by name",
22 Command: "coder task pause my-task",
23 },
24 Example{
25 Description: "Pause another user's task",
26 Command: "coder task pause alice/my-task",
27 },
28 Example{
29 Description: "Pause a task without confirmation",
30 Command: "coder task pause my-task --yes",
31 },
32 ),
33 Middleware: serpent.Chain(
34 serpent.RequireNArgs(1),
35 ),
36 Options: serpent.OptionSet{
37 cliui.SkipPromptOption(),
38 },
39 Handler: func(inv *serpent.Invocation) error {
40 ctx := inv.Context()
41 client, err := r.InitClient(inv)
42 if err != nil {
43 return err
44 }
45
46 task, err := client.TaskByIdentifier(ctx, inv.Args[0])
47 if err != nil {
48 return xerrors.Errorf("resolve task %q: %w", inv.Args[0], err)
49 }
50
51 display := fmt.Sprintf("%s/%s", task.OwnerName, task.Name)
52
53 if task.Status == codersdk.TaskStatusPaused {
54 return xerrors.Errorf("task %q is already paused", display)
55 }
56
57 _, err = cliui.Prompt(inv, cliui.PromptOptions{
58 Text: fmt.Sprintf("Pause task %s?", pretty.Sprint(cliui.DefaultStyles.Code, display)),
59 IsConfirm: true,
60 Default: cliui.ConfirmNo,
61 })
62 if err != nil {
63 return err
64 }
65
66 resp, err := client.PauseTask(ctx, task.OwnerName, task.ID)
67 if err != nil {
68 return xerrors.Errorf("pause task %q: %w", display, err)
69 }
70
71 if resp.WorkspaceBuild == nil {
72 return xerrors.Errorf("pause task %q: no workspace build returned", display)

Callers 1

tasksCommandMethod · 0.95

Calls 11

InitClientMethod · 0.95
SkipPromptOptionFunction · 0.92
PromptFunction · 0.92
WorkspaceBuildFunction · 0.92
KeywordFunction · 0.92
TimestampFunction · 0.92
FormatExamplesFunction · 0.85
TaskByIdentifierMethod · 0.80
PauseTaskMethod · 0.80
ContextMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected