-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathcancel.go
More file actions
40 lines (32 loc) · 892 Bytes
/
Copy pathcancel.go
File metadata and controls
40 lines (32 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"fmt"
"strconv"
"github.com/spf13/cobra"
)
func cancelCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "cancel <job_id>",
Short: "Cancel a queued or running review job",
Long: `Cancel a review job by ID.
Only jobs that are still queued or running can be canceled; jobs that have
already finished (done, failed, canceled, etc.) cannot.`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if err := ensureDaemon(); err != nil {
return fmt.Errorf("daemon not running: %w", err)
}
jobID, err := strconv.ParseInt(args[0], 10, 64)
if err != nil || jobID <= 0 {
return fmt.Errorf("invalid job_id: %s", args[0])
}
ep := getDaemonEndpoint()
if err := cancelJob(ep.BaseURL(), jobID); err != nil {
return err
}
fmt.Printf("Job %d canceled\n", jobID)
return nil
},
}
return cmd
}