| 58 | } |
| 59 | |
| 60 | func deleteRun(ctx context.Context, opts *DeleteOptions) error { |
| 61 | cfg, err := opts.Config() |
| 62 | if err != nil { |
| 63 | return err |
| 64 | } |
| 65 | host, _ := cfg.Authentication().DefaultHost() |
| 66 | |
| 67 | c, err := opts.EventClient(host) |
| 68 | if err != nil { |
| 69 | return err |
| 70 | } |
| 71 | |
| 72 | opts.IO.StartProgressIndicator() |
| 73 | err = c.DeleteSubscription(ctx, opts.ID) |
| 74 | opts.IO.StopProgressIndicator() |
| 75 | if err != nil { |
| 76 | if errors.Is(err, client.ErrSubscriptionNotFound) { |
| 77 | return shared.SubscriptionNotFoundError(opts.ID) |
| 78 | } |
| 79 | return fmt.Errorf("failed to delete subscription: %w", err) |
| 80 | } |
| 81 | |
| 82 | if opts.IO.IsStderrTTY() { |
| 83 | cs := opts.IO.ColorScheme() |
| 84 | fmt.Fprintf(opts.IO.ErrOut, "%s Deleted subscription %s\n", cs.SuccessIconWithColor(cs.Red), opts.ID) |
| 85 | } |
| 86 | return nil |
| 87 | } |