()
| 12 | ) |
| 13 | |
| 14 | func (r *RootCmd) taskResume() *serpent.Command { |
| 15 | var noWait bool |
| 16 | |
| 17 | cmd := &serpent.Command{ |
| 18 | Use: "resume <task>", |
| 19 | Short: "Resume a task", |
| 20 | Long: FormatExamples( |
| 21 | Example{ |
| 22 | Description: "Resume a task by name", |
| 23 | Command: "coder task resume my-task", |
| 24 | }, |
| 25 | Example{ |
| 26 | Description: "Resume another user's task", |
| 27 | Command: "coder task resume alice/my-task", |
| 28 | }, |
| 29 | Example{ |
| 30 | Description: "Resume a task without confirmation", |
| 31 | Command: "coder task resume my-task --yes", |
| 32 | }, |
| 33 | ), |
| 34 | Middleware: serpent.Chain( |
| 35 | serpent.RequireNArgs(1), |
| 36 | ), |
| 37 | Options: serpent.OptionSet{ |
| 38 | { |
| 39 | Flag: "no-wait", |
| 40 | Description: "Return immediately after resuming the task.", |
| 41 | Value: serpent.BoolOf(&noWait), |
| 42 | }, |
| 43 | cliui.SkipPromptOption(), |
| 44 | }, |
| 45 | Handler: func(inv *serpent.Invocation) error { |
| 46 | ctx := inv.Context() |
| 47 | client, err := r.InitClient(inv) |
| 48 | if err != nil { |
| 49 | return err |
| 50 | } |
| 51 | |
| 52 | task, err := client.TaskByIdentifier(ctx, inv.Args[0]) |
| 53 | if err != nil { |
| 54 | return xerrors.Errorf("resolve task %q: %w", inv.Args[0], err) |
| 55 | } |
| 56 | |
| 57 | display := fmt.Sprintf("%s/%s", task.OwnerName, task.Name) |
| 58 | |
| 59 | if task.Status == codersdk.TaskStatusError || task.Status == codersdk.TaskStatusUnknown { |
| 60 | return xerrors.Errorf("task %q is in %s state and cannot be resumed; check the workspace build logs and agent status for details", display, task.Status) |
| 61 | } else if task.Status != codersdk.TaskStatusPaused { |
| 62 | return xerrors.Errorf("task %q cannot be resumed (current status: %s)", display, task.Status) |
| 63 | } |
| 64 | |
| 65 | _, err = cliui.Prompt(inv, cliui.PromptOptions{ |
| 66 | Text: fmt.Sprintf("Resume task %s?", pretty.Sprint(cliui.DefaultStyles.Code, display)), |
| 67 | IsConfirm: true, |
| 68 | Default: cliui.ConfirmNo, |
| 69 | }) |
| 70 | if err != nil { |
| 71 | return err |
no test coverage detected