NewCmdList creates the "discussion list" command.
(f *cmdutil.Factory, runF func(*ListOptions) error)
| 80 | |
| 81 | // NewCmdList creates the "discussion list" command. |
| 82 | func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Command { |
| 83 | opts := &ListOptions{ |
| 84 | IO: f.IOStreams, |
| 85 | Browser: f.Browser, |
| 86 | Now: time.Now, |
| 87 | } |
| 88 | |
| 89 | cmd := &cobra.Command{ |
| 90 | Use: "list [flags]", |
| 91 | Short: "List discussions in a repository (preview)", |
| 92 | Long: heredoc.Doc(` |
| 93 | List discussions in a GitHub repository. By default, only open discussions |
| 94 | are shown. |
| 95 | `), |
| 96 | Example: heredoc.Doc(` |
| 97 | # List open discussions |
| 98 | $ gh discussion list |
| 99 | |
| 100 | # List discussions with a specific category |
| 101 | $ gh discussion list --category General |
| 102 | |
| 103 | # List closed discussions by author |
| 104 | $ gh discussion list --state closed --author monalisa |
| 105 | |
| 106 | # List all discussions (closed or open) by label |
| 107 | $ gh discussion list --state all --label bug,enhancement |
| 108 | |
| 109 | # List answered Q&A discussions as JSON |
| 110 | $ gh discussion list --answered --json number,title,url |
| 111 | |
| 112 | # List unanswered Q&A discussions as JSON |
| 113 | $ gh discussion list --answered=false --json number,title,url |
| 114 | `), |
| 115 | Aliases: []string{"ls"}, |
| 116 | Args: cmdutil.NoArgsQuoteReminder, |
| 117 | RunE: func(cmd *cobra.Command, args []string) error { |
| 118 | opts.BaseRepo = f.BaseRepo |
| 119 | opts.Client = shared.DiscussionClientFunc(f) |
| 120 | |
| 121 | if opts.Limit < 1 { |
| 122 | return cmdutil.FlagErrorf("invalid limit: %v", opts.Limit) |
| 123 | } |
| 124 | |
| 125 | if runF != nil { |
| 126 | return runF(opts) |
| 127 | } |
| 128 | return listRun(opts) |
| 129 | }, |
| 130 | } |
| 131 | |
| 132 | cmdutil.EnableRepoOverride(cmd, f) |
| 133 | |
| 134 | cmd.Flags().StringVarP(&opts.Author, "author", "A", "", "Filter by author") |
| 135 | cmd.Flags().StringVarP(&opts.Category, "category", "c", "", "Filter by category name or slug") |
| 136 | cmd.Flags().StringSliceVarP(&opts.Labels, "label", "l", nil, "Filter by label") |
| 137 | cmdutil.StringEnumFlag(cmd, &opts.State, "state", "s", stateOpen, []string{stateOpen, stateClosed, stateAll}, "Filter by state") |
| 138 | cmd.Flags().IntVarP(&opts.Limit, "limit", "L", defaultLimit, "Maximum number of discussions to fetch") |
| 139 | cmdutil.NilBoolFlag(cmd, &opts.Answered, "answered", "", "Filter by answered state") |