diff --git a/main.go b/main.go index 3f76d54..a1034d4 100644 --- a/main.go +++ b/main.go @@ -29,6 +29,7 @@ var ( NameRegex string `flag:"name-regex" default:".*" description:"Regex to match the name against"` Output string `flag:"out,o" default:"-" description:"File to write to (- = stdout)"` Template string `flag:"template" default:"" description:"Template file to use for rendering" validate:"nonzero"` + TopicFilter []string `flag:"topic,t" default:"" description:"Filter by topic (Format: 'topic' to include, '-topic' to exclude)"` VersionAndExit bool `flag:"version" default:"false" description:"Prints current version and exits"` }{} @@ -77,6 +78,10 @@ func main() { continue } + if !matchTopicFilter(repo) { + continue + } + skip := false for _, f := range cfg.Filters { @@ -165,6 +170,25 @@ func fetchRepos() ([]*github.Repository, error) { return repos, nil } +func matchTopicFilter(repo *github.Repository) bool { + for _, topic := range cfg.TopicFilter { + if topic == "" { + continue + } + + negate := topic[0] == '-' + if negate { + topic = topic[1:len(topic)] + } + + if str.StringInSlice(topic, repo.Topics) != negate { + return true + } + } + + return false +} + func render(repo *github.Repository) error { var outFile io.Writer if cfg.Output == "-" {