| 28 | } |
| 29 | |
| 30 | func NewCmdCancel(f *cmdutil.Factory, runF func(*CancelOptions) error) *cobra.Command { |
| 31 | opts := &CancelOptions{ |
| 32 | IO: f.IOStreams, |
| 33 | HttpClient: f.HttpClient, |
| 34 | Prompter: f.Prompter, |
| 35 | } |
| 36 | |
| 37 | cmd := &cobra.Command{ |
| 38 | Use: "cancel [<run-id>]", |
| 39 | Short: "Cancel a workflow run", |
| 40 | Args: cobra.MaximumNArgs(1), |
| 41 | RunE: func(cmd *cobra.Command, args []string) error { |
| 42 | // support `-R, --repo` override |
| 43 | opts.BaseRepo = f.BaseRepo |
| 44 | |
| 45 | if len(args) > 0 { |
| 46 | opts.RunID = args[0] |
| 47 | } else if !opts.IO.CanPrompt() { |
| 48 | return cmdutil.FlagErrorf("run ID required when not running interactively") |
| 49 | } else { |
| 50 | opts.Prompt = true |
| 51 | } |
| 52 | |
| 53 | if runF != nil { |
| 54 | return runF(opts) |
| 55 | } |
| 56 | |
| 57 | return runCancel(opts) |
| 58 | }, |
| 59 | } |
| 60 | |
| 61 | cmd.Flags().BoolVar(&opts.Force, "force", false, "Force cancel a workflow run") |
| 62 | |
| 63 | return cmd |
| 64 | } |
| 65 | |
| 66 | func runCancel(opts *CancelOptions) error { |
| 67 | if opts.RunID != "" { |