Skip to content

Commit

Permalink
Add --exclude-topic option
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed Jan 21, 2024
1 parent 32ede6e commit b9d0569
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ Options
multiple times to only list repositories with
all of the specified topics.

-T, --exclude-topic TOPIC Only list repositories without the given topic
(case insensitive). This option can be given
multiple times.

--no-topics Only list repositories without any topics

.. _jq: https://jqlang.github.io/jq/
Expand Down
19 changes: 19 additions & 0 deletions src/repolist/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ def filterfunc(r: Repo) -> bool:
return filterfunc


def topic_exclude(topic: str) -> RepoFilter:
topic = topic.lower()

def filterfunc(r: Repo) -> bool:
return topic not in r["topics"]

return filterfunc


def null_filter(_: Repo) -> bool:
return True

Expand Down Expand Up @@ -282,6 +291,13 @@ def show(self, repo: Repo) -> None:
metavar="TOPIC",
multiple=True,
)
@click.option(
"-T",
"--exclude-topic",
help="Only list repositories without the given topic",
metavar="TOPIC",
multiple=True,
)
@click.option(
"--no-topics", is_flag=True, help="Only list repositories without any topics"
)
Expand All @@ -299,6 +315,7 @@ def main(
fork_filter: RepoFilter | None,
language: str | None,
topic: tuple[str, ...],
exclude_topic: tuple[str, ...],
no_topics: bool,
visibility: str | None,
affiliation: str | None,
Expand All @@ -325,6 +342,8 @@ def main(
matcher.add(language_filter(language))
for t in topic:
matcher.add(topic_filter(t))
for t in exclude_topic:
matcher.add(topic_exclude(t))
if no_topics:
matcher.add(field_filter("topics", []))
if visibility is not None and owner:
Expand Down

0 comments on commit b9d0569

Please sign in to comment.