Skip to content

Commit ed5970a

Browse files
authored
Add ability to list multiple repo types (#22)
* Add ability to list multiple repo types * Fix linting errors
1 parent 6b53e1e commit ed5970a

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

docs/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
## [0.0.7] - 2024-01-21
11+
12+
### Added
13+
14+
- `list` can now accept multiple `--type` parameters to list multiple repository types
15+
1016
## [0.0.6] - 2023-12-10
1117

1218
### Added

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = repo-man
3-
version = 0.0.6
3+
version = 0.0.7
44
description = Manage repositories of different flavors.
55
long_description = file: README.md
66
long_description_content_type = text/markdown

src/repo_man/commands/list_repos.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,29 @@
44
import click
55

66
from repo_man.consts import REPO_TYPES_CFG
7-
from repo_man.utils import get_valid_repo_types, parse_repo_types, pass_config
7+
from repo_man.utils import parse_repo_types, pass_config
88

99

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

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

2020
valid_repo_types = parse_repo_types(config)
21+
found_repos = set()
2122

22-
repos = sorted(valid_repo_types[repo_type])
23+
for repo_type in repo_types:
24+
if repo_type not in valid_repo_types:
25+
repo_list = "\n\t".join(valid_repo_types)
26+
raise click.BadParameter(f"Invalid repository type '{repo_type}'. Valid types are:\n\n\t{repo_list}")
27+
found_repos.update(valid_repo_types[repo_type])
28+
29+
repos = sorted(found_repos)
2330

2431
if len(repos) > 25:
2532
click.echo_via_pager("\n".join(repos))

test/test_list_repos.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,29 @@ def test_list_repos_when_long(mock_echo_via_pager, runner, get_config):
7979
result = runner.invoke(list_repos, ["-t", "all"], obj=config)
8080
assert result.exit_code == 0
8181
mock_echo_via_pager.assert_called_once_with("\n".join(sorted(all_repos.split("\n"))))
82+
83+
84+
def test_list_repos_for_multiple_tags(runner, get_config):
85+
with runner.isolated_filesystem():
86+
with open("repo-man.cfg", "w") as config_file:
87+
config_file.write(
88+
"""[foo]
89+
known =
90+
some-repo
91+
92+
[bar]
93+
known =
94+
some-other-repo
95+
96+
"""
97+
)
98+
99+
config = get_config()
100+
result = runner.invoke(list_repos, ["-t", "foo", "-t", "bar"], obj=config)
101+
assert result.exit_code == 0
102+
assert (
103+
result.output
104+
== """some-other-repo
105+
some-repo
106+
"""
107+
)

0 commit comments

Comments
 (0)