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

Method taskDelete

cli/task_delete.go:16–85  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14)
15
16func (r *RootCmd) taskDelete() *serpent.Command {
17 cmd := &serpent.Command{
18 Use: "delete <task> [<task> ...]",
19 Short: "Delete tasks",
20 Long: FormatExamples(
21 Example{
22 Description: "Delete a single task.",
23 Command: "$ coder task delete task1",
24 },
25 Example{
26 Description: "Delete multiple tasks.",
27 Command: "$ coder task delete task1 task2 task3",
28 },
29 Example{
30 Description: "Delete a task without confirmation.",
31 Command: "$ coder task delete task4 --yes",
32 },
33 ),
34 Middleware: serpent.Chain(
35 serpent.RequireRangeArgs(1, -1),
36 ),
37 Options: serpent.OptionSet{
38 cliui.SkipPromptOption(),
39 },
40 Handler: func(inv *serpent.Invocation) error {
41 ctx := inv.Context()
42 client, err := r.InitClient(inv)
43 if err != nil {
44 return err
45 }
46
47 var tasks []codersdk.Task
48 for _, identifier := range inv.Args {
49 task, err := client.TaskByIdentifier(ctx, identifier)
50 if err != nil {
51 return xerrors.Errorf("resolve task %q: %w", identifier, err)
52 }
53 tasks = append(tasks, task)
54 }
55
56 // Confirm deletion of the tasks.
57 var displayList []string
58 for _, task := range tasks {
59 displayList = append(displayList, fmt.Sprintf("%s/%s", task.OwnerName, task.Name))
60 }
61 _, err = cliui.Prompt(inv, cliui.PromptOptions{
62 Text: fmt.Sprintf("Delete these tasks: %s?", pretty.Sprint(cliui.DefaultStyles.Code, strings.Join(displayList, ", "))),
63 IsConfirm: true,
64 Default: cliui.ConfirmNo,
65 })
66 if err != nil {
67 return err
68 }
69
70 for i, task := range tasks {
71 display := displayList[i]
72 if err := client.DeleteTask(ctx, task.OwnerName, task.ID); err != nil {
73 return xerrors.Errorf("delete task %q: %w", display, err)

Callers 1

tasksCommandMethod · 0.95

Calls 9

InitClientMethod · 0.95
SkipPromptOptionFunction · 0.92
PromptFunction · 0.92
TimestampFunction · 0.92
FormatExamplesFunction · 0.85
TaskByIdentifierMethod · 0.80
ContextMethod · 0.65
DeleteTaskMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected