diff --git a/pkg/cmd/repo/list/http.go b/pkg/cmd/repo/list/http.go index 765cf8b0c..191ba0d18 100644 --- a/pkg/cmd/repo/list/http.go +++ b/pkg/cmd/repo/list/http.go @@ -23,14 +23,14 @@ type FilterOptions struct { Fork bool Source bool Language string - Topic string + Topic []string Archived bool NonArchived bool Fields []string } func listRepos(client *http.Client, hostname string, limit int, owner string, filter FilterOptions) (*RepositoryList, error) { - if filter.Language != "" || filter.Archived || filter.NonArchived || filter.Topic != "" || filter.Visibility == "internal" { + if filter.Language != "" || filter.Archived || filter.NonArchived || len(filter.Topic) > 0 || filter.Visibility == "internal" { return searchRepos(client, hostname, limit, owner, filter) } @@ -208,7 +208,7 @@ func searchQuery(owner string, filter FilterOptions) string { Fork: fork, Is: []string{filter.Visibility}, Language: filter.Language, - Topic: []string{filter.Topic}, + Topic: filter.Topic, User: owner, }, } diff --git a/pkg/cmd/repo/list/list.go b/pkg/cmd/repo/list/list.go index a7e21e0ee..d6ebd1b0a 100644 --- a/pkg/cmd/repo/list/list.go +++ b/pkg/cmd/repo/list/list.go @@ -31,7 +31,7 @@ type ListOptions struct { Fork bool Source bool Language string - Topic string + Topic []string Archived bool NonArchived bool @@ -92,7 +92,7 @@ func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Comman cmd.Flags().BoolVar(&opts.Source, "source", false, "Show only non-forks") cmd.Flags().BoolVar(&opts.Fork, "fork", false, "Show only forks") cmd.Flags().StringVarP(&opts.Language, "language", "l", "", "Filter by primary coding language") - cmd.Flags().StringVar(&opts.Topic, "topic", "", "Filter by topic") + cmd.Flags().StringSliceVarP(&opts.Topic, "topic", "", nil, "Filter by topic") cmdutil.StringEnumFlag(cmd, &opts.Visibility, "visibility", "", "", []string{"public", "private", "internal"}, "Filter by repository visibility") cmd.Flags().BoolVar(&opts.Archived, "archived", false, "Show only archived repositories") cmd.Flags().BoolVar(&opts.NonArchived, "no-archived", false, "Omit archived repositories") @@ -195,7 +195,7 @@ func listRun(opts *ListOptions) error { fmt.Fprintln(opts.IO.ErrOut, "warning: this query uses the Search API which is capped at 1000 results maximum") } if opts.IO.IsStdoutTTY() { - hasFilters := filter.Visibility != "" || filter.Fork || filter.Source || filter.Language != "" || filter.Topic != "" + hasFilters := filter.Visibility != "" || filter.Fork || filter.Source || filter.Language != "" || len(filter.Topic) > 0 title := listHeader(listResult.Owner, len(listResult.Repositories), listResult.TotalCount, hasFilters) fmt.Fprintf(opts.IO.Out, "\n%s\n\n", title) } diff --git a/pkg/cmd/repo/list/list_test.go b/pkg/cmd/repo/list/list_test.go index 50d0e380d..e6fb918d0 100644 --- a/pkg/cmd/repo/list/list_test.go +++ b/pkg/cmd/repo/list/list_test.go @@ -38,7 +38,7 @@ func TestNewCmdList(t *testing.T) { Fork: false, Source: false, Language: "", - Topic: "", + Topic: []string(nil), Archived: false, NonArchived: false, }, @@ -53,7 +53,7 @@ func TestNewCmdList(t *testing.T) { Fork: false, Source: false, Language: "", - Topic: "", + Topic: []string(nil), Archived: false, NonArchived: false, }, @@ -68,7 +68,7 @@ func TestNewCmdList(t *testing.T) { Fork: false, Source: false, Language: "", - Topic: "", + Topic: []string(nil), Archived: false, NonArchived: false, }, @@ -83,7 +83,7 @@ func TestNewCmdList(t *testing.T) { Fork: false, Source: false, Language: "", - Topic: "", + Topic: []string(nil), Archived: false, NonArchived: false, }, @@ -98,7 +98,7 @@ func TestNewCmdList(t *testing.T) { Fork: false, Source: false, Language: "", - Topic: "", + Topic: []string(nil), Archived: false, NonArchived: false, }, @@ -113,7 +113,7 @@ func TestNewCmdList(t *testing.T) { Fork: true, Source: false, Language: "", - Topic: "", + Topic: []string(nil), Archived: false, NonArchived: false, }, @@ -128,7 +128,7 @@ func TestNewCmdList(t *testing.T) { Fork: false, Source: true, Language: "", - Topic: "", + Topic: []string(nil), Archived: false, NonArchived: false, }, @@ -143,7 +143,7 @@ func TestNewCmdList(t *testing.T) { Fork: false, Source: false, Language: "go", - Topic: "", + Topic: []string(nil), Archived: false, NonArchived: false, }, @@ -158,7 +158,7 @@ func TestNewCmdList(t *testing.T) { Fork: false, Source: false, Language: "", - Topic: "", + Topic: []string(nil), Archived: true, NonArchived: false, }, @@ -173,7 +173,7 @@ func TestNewCmdList(t *testing.T) { Fork: false, Source: false, Language: "", - Topic: "", + Topic: []string(nil), Archived: false, NonArchived: true, }, @@ -188,7 +188,22 @@ func TestNewCmdList(t *testing.T) { Fork: false, Source: false, Language: "", - Topic: "cli", + Topic: []string{"cli"}, + Archived: false, + NonArchived: false, + }, + }, + { + name: "with multiple topic", + cli: "--topic cli --topic multiple-topic", + wants: ListOptions{ + Limit: 30, + Owner: "", + Visibility: "", + Fork: false, + Source: false, + Language: "", + Topic: []string{"cli", "multiple-topic"}, Archived: false, NonArchived: false, },