| 24 | } |
| 25 | |
| 26 | func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Command { |
| 27 | opts := &DeleteOptions{ |
| 28 | IO: f.IOStreams, |
| 29 | Config: f.Config, |
| 30 | EventClient: shared.EventClientFunc(f), |
| 31 | } |
| 32 | |
| 33 | cmd := &cobra.Command{ |
| 34 | Use: "delete <id>", |
| 35 | Short: "Delete an event subscription (preview)", |
| 36 | Long: heredoc.Doc(` |
| 37 | Delete an event subscription before it expires, which frees a place under the limit of |
| 38 | subscriptions of your account. |
| 39 | |
| 40 | Event streams that are already open on the subscription are not guaranteed to close. |
| 41 | `), |
| 42 | Example: heredoc.Doc(` |
| 43 | # Delete a subscription |
| 44 | $ gh event subscription delete sub_123 |
| 45 | `), |
| 46 | Args: cmdutil.ExactArgs(1, "subscription ID required"), |
| 47 | RunE: func(cmd *cobra.Command, args []string) error { |
| 48 | opts.ID = args[0] |
| 49 | |
| 50 | if runF != nil { |
| 51 | return runF(opts) |
| 52 | } |
| 53 | return deleteRun(cmd.Context(), opts) |
| 54 | }, |
| 55 | } |
| 56 | |
| 57 | return cmd |
| 58 | } |
| 59 | |
| 60 | func deleteRun(ctx context.Context, opts *DeleteOptions) error { |
| 61 | cfg, err := opts.Config() |