| 29 | } |
| 30 | |
| 31 | func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Command { |
| 32 | opts := &ViewOptions{ |
| 33 | IO: f.IOStreams, |
| 34 | Config: f.Config, |
| 35 | EventClient: shared.EventClientFunc(f), |
| 36 | Now: time.Now, |
| 37 | } |
| 38 | |
| 39 | cmd := &cobra.Command{ |
| 40 | Use: "view <id>", |
| 41 | Short: "View an event subscription (preview)", |
| 42 | Example: heredoc.Doc(` |
| 43 | # View a subscription |
| 44 | $ gh event subscription view sub_123 |
| 45 | |
| 46 | # Print when a subscription expires |
| 47 | $ gh event subscription view sub_123 --json expiresAt --jq .expiresAt |
| 48 | `), |
| 49 | Args: cmdutil.ExactArgs(1, "subscription ID required"), |
| 50 | RunE: func(cmd *cobra.Command, args []string) error { |
| 51 | opts.ID = args[0] |
| 52 | |
| 53 | if runF != nil { |
| 54 | return runF(opts) |
| 55 | } |
| 56 | return viewRun(cmd.Context(), opts) |
| 57 | }, |
| 58 | } |
| 59 | |
| 60 | cmdutil.AddJSONFlags(cmd, &opts.Exporter, client.SubscriptionFields) |
| 61 | return cmd |
| 62 | } |
| 63 | |
| 64 | func viewRun(ctx context.Context, opts *ViewOptions) error { |
| 65 | cfg, err := opts.Config() |