| 29 | } |
| 30 | |
| 31 | func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Command { |
| 32 | opts := &DeleteOptions{ |
| 33 | IO: f.IOStreams, |
| 34 | HttpClient: f.HttpClient, |
| 35 | Prompter: f.Prompter, |
| 36 | } |
| 37 | |
| 38 | cmd := &cobra.Command{ |
| 39 | Use: "delete [<run-id>]", |
| 40 | Short: "Delete a workflow run", |
| 41 | Example: heredoc.Doc(` |
| 42 | # Interactively select a run to delete |
| 43 | $ gh run delete |
| 44 | |
| 45 | # Delete a specific run |
| 46 | $ gh run delete 12345 |
| 47 | `), |
| 48 | Args: cobra.MaximumNArgs(1), |
| 49 | RunE: func(cmd *cobra.Command, args []string) error { |
| 50 | // support `-R, --repo` override |
| 51 | opts.BaseRepo = f.BaseRepo |
| 52 | |
| 53 | if len(args) > 0 { |
| 54 | opts.RunID = args[0] |
| 55 | } else if !opts.IO.CanPrompt() { |
| 56 | return cmdutil.FlagErrorf("run ID required when not running interactively") |
| 57 | } else { |
| 58 | opts.Prompt = true |
| 59 | } |
| 60 | |
| 61 | if runF != nil { |
| 62 | return runF(opts) |
| 63 | } |
| 64 | |
| 65 | return runDelete(opts) |
| 66 | }, |
| 67 | } |
| 68 | |
| 69 | return cmd |
| 70 | } |
| 71 | |
| 72 | func runDelete(opts *DeleteOptions) error { |
| 73 | httpClient, err := opts.HttpClient() |