| 46 | } |
| 47 | |
| 48 | func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Command { |
| 49 | opts := &ListOptions{ |
| 50 | IO: f.IOStreams, |
| 51 | HttpClient: f.HttpClient, |
| 52 | Config: f.Config, |
| 53 | Browser: f.Browser, |
| 54 | Now: time.Now, |
| 55 | } |
| 56 | |
| 57 | var appAuthor string |
| 58 | |
| 59 | cmd := &cobra.Command{ |
| 60 | Use: "list", |
| 61 | Short: "List issues in a repository", |
| 62 | // TODO advancedIssueSearchCleanup |
| 63 | // Update the links and remove the mention at GHES 3.17 version. |
| 64 | Long: heredoc.Docf(` |
| 65 | List issues in a GitHub repository. By default, this only lists open issues. |
| 66 | |
| 67 | The search query syntax is documented here: |
| 68 | <https://docs.github.com/en/search-github/searching-on-github/searching-issues-and-pull-requests> |
| 69 | |
| 70 | On supported GitHub hosts, advanced issue search syntax can be used in the |
| 71 | %[1]s--search%[1]s query. For more information about advanced issue search, see: |
| 72 | <https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/filtering-and-searching-issues-and-pull-requests#building-advanced-filters-for-issues> |
| 73 | `, "`"), |
| 74 | Example: heredoc.Doc(` |
| 75 | $ gh issue list --label "bug" --label "help wanted" |
| 76 | $ gh issue list --author monalisa |
| 77 | $ gh issue list --app dependabot |
| 78 | $ gh issue list --assignee "@me" |
| 79 | $ gh issue list --milestone "The big 1.0" |
| 80 | $ gh issue list --search "error no:assignee sort:created-asc" |
| 81 | $ gh issue list --state all |
| 82 | $ gh issue list --type Bug |
| 83 | `), |
| 84 | Aliases: []string{"ls"}, |
| 85 | Args: cmdutil.NoArgsQuoteReminder, |
| 86 | RunE: func(cmd *cobra.Command, args []string) error { |
| 87 | // support `-R, --repo` override |
| 88 | opts.BaseRepo = f.BaseRepo |
| 89 | |
| 90 | if opts.LimitResults < 1 { |
| 91 | return cmdutil.FlagErrorf("invalid limit: %v", opts.LimitResults) |
| 92 | } |
| 93 | |
| 94 | if cmd.Flags().Changed("author") && cmd.Flags().Changed("app") { |
| 95 | return cmdutil.FlagErrorf("specify only `--author` or `--app`") |
| 96 | } |
| 97 | |
| 98 | if cmd.Flags().Changed("app") { |
| 99 | opts.Author = fmt.Sprintf("app/%s", appAuthor) |
| 100 | } |
| 101 | |
| 102 | if runF != nil { |
| 103 | return runF(opts) |
| 104 | } |
| 105 | return listRun(opts) |