Skip to content

Commit

Permalink
Add ability to list multiple repo types (#22)
Browse files Browse the repository at this point in the history
* Add ability to list multiple repo types

* Fix linting errors
  • Loading branch information
daneah authored Jan 21, 2024
1 parent 6b53e1e commit ed5970a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [0.0.7] - 2024-01-21

### Added

- `list` can now accept multiple `--type` parameters to list multiple repository types

## [0.0.6] - 2023-12-10

### Added
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = repo-man
version = 0.0.6
version = 0.0.7
description = Manage repositories of different flavors.
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
15 changes: 11 additions & 4 deletions src/repo_man/commands/list_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,29 @@
import click

from repo_man.consts import REPO_TYPES_CFG
from repo_man.utils import get_valid_repo_types, parse_repo_types, pass_config
from repo_man.utils import parse_repo_types, pass_config


@click.command(name="list", help="The type of repository to manage")
@click.option("-t", "--type", "repo_type", type=click.Choice(get_valid_repo_types()), show_choices=False, required=True)
@click.option("-t", "--type", "repo_types", multiple=True, show_choices=False, required=True)
@pass_config
def list_repos(config: configparser.ConfigParser, repo_type: str):
def list_repos(config: configparser.ConfigParser, repo_types: list[str]):
"""List matching repositories"""

if not Path(REPO_TYPES_CFG).exists():
click.echo(click.style(f"No {REPO_TYPES_CFG} file found.", fg="red"))
raise SystemExit(1)

valid_repo_types = parse_repo_types(config)
found_repos = set()

repos = sorted(valid_repo_types[repo_type])
for repo_type in repo_types:
if repo_type not in valid_repo_types:
repo_list = "\n\t".join(valid_repo_types)
raise click.BadParameter(f"Invalid repository type '{repo_type}'. Valid types are:\n\n\t{repo_list}")
found_repos.update(valid_repo_types[repo_type])

repos = sorted(found_repos)

if len(repos) > 25:
click.echo_via_pager("\n".join(repos))
Expand Down
26 changes: 26 additions & 0 deletions test/test_list_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,29 @@ def test_list_repos_when_long(mock_echo_via_pager, runner, get_config):
result = runner.invoke(list_repos, ["-t", "all"], obj=config)
assert result.exit_code == 0
mock_echo_via_pager.assert_called_once_with("\n".join(sorted(all_repos.split("\n"))))


def test_list_repos_for_multiple_tags(runner, get_config):
with runner.isolated_filesystem():
with open("repo-man.cfg", "w") as config_file:
config_file.write(
"""[foo]
known =
some-repo
[bar]
known =
some-other-repo
"""
)

config = get_config()
result = runner.invoke(list_repos, ["-t", "foo", "-t", "bar"], obj=config)
assert result.exit_code == 0
assert (
result.output
== """some-other-repo
some-repo
"""
)

0 comments on commit ed5970a

Please sign in to comment.