| 187 | } |
| 188 | |
| 189 | func listRun(opts *ListOptions) error { |
| 190 | repo, err := opts.BaseRepo() |
| 191 | if err != nil { |
| 192 | return err |
| 193 | } |
| 194 | |
| 195 | if opts.WebMode { |
| 196 | return openInBrowser(opts, repo) |
| 197 | } |
| 198 | |
| 199 | dc, err := opts.Client() |
| 200 | if err != nil { |
| 201 | return err |
| 202 | } |
| 203 | |
| 204 | var categoryID string |
| 205 | var categorySlug string |
| 206 | if opts.Category != "" { |
| 207 | categories, err := dc.ListCategories(repo) |
| 208 | if err != nil { |
| 209 | return err |
| 210 | } |
| 211 | cat, err := shared.MatchCategory(opts.Category, categories) |
| 212 | if err != nil { |
| 213 | return err |
| 214 | } |
| 215 | categoryID = cat.ID |
| 216 | categorySlug = cat.Slug |
| 217 | } |
| 218 | |
| 219 | state := toFilterState(opts.State) |
| 220 | orderBy, direction := toOrderByAndDirection(opts.Sort, opts.Order) |
| 221 | |
| 222 | var result *client.DiscussionListResult |
| 223 | |
| 224 | useSearch := opts.Author != "" || len(opts.Labels) > 0 || opts.Search != "" |
| 225 | if useSearch { |
| 226 | filters := client.SearchFilters{ |
| 227 | Author: opts.Author, |
| 228 | Labels: opts.Labels, |
| 229 | State: state, |
| 230 | Category: categorySlug, |
| 231 | Answered: opts.Answered, |
| 232 | Keywords: opts.Search, |
| 233 | OrderBy: orderBy, |
| 234 | Direction: direction, |
| 235 | } |
| 236 | result, err = dc.Search(repo, filters, opts.After, opts.Limit) |
| 237 | } else { |
| 238 | filters := client.ListFilters{ |
| 239 | State: state, |
| 240 | CategoryID: categoryID, |
| 241 | Answered: opts.Answered, |
| 242 | OrderBy: orderBy, |
| 243 | Direction: direction, |
| 244 | } |
| 245 | result, err = dc.List(repo, filters, opts.After, opts.Limit) |
| 246 | } |