Skip to content

Commit

Permalink
Add CLI
Browse files Browse the repository at this point in the history
Related to rpm-software-management#6

Signed-off-by: Matej Focko <[email protected]>
  • Loading branch information
mfocko committed Sep 11, 2024
1 parent 378ac29 commit be9ff85
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
42 changes: 42 additions & 0 deletions fedora_distro_aliases/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import click

from fedora_distro_aliases import get_distro_aliases

GETTERS = {
"namever": lambda x: x.namever,
"branch": lambda x: x.branch,
"version": lambda x: x.version,
}


@click.command()
@click.option(
"-o",
"--output-type",
type=click.Choice(("namever", "branch", "version"), case_sensitive=False),
default="namever",
help="""Choose the output format of the script.
Available options:\n
* namever — e.g., ‹fedora-40›\n
* branch — e.g., ‹f40›\n
* version — e.g., ‹40›
"""
)
@click.argument("aliases", required=True, nargs=-1)
def cli(aliases: list[str], output_type: str):
"""Resolve the requested aliases.
Resolve each of the ALIASES and print them out.
This script prints out only unique aliases i.e., it is not possible to
obtain the same alias twice in the output.
"""
getter = GETTERS[output_type]
distro_aliases = get_distro_aliases()

resolved_aliases: set[str] = set()
for alias in aliases:
resolved_aliases.update(getter(x) for x in distro_aliases[alias])

print(" ".join(resolved_aliases))
7 changes: 7 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
install_requires = [
"munch",
"requests",
"Click", # for the CLI and GH Action
]

__description__ = "Aliases for active Fedora releases"
Expand All @@ -43,4 +44,10 @@
packages=find_packages(),
include_package_data=True,
zip_safe=False,
py_modules=["cli"],
entry_points={
"console_scripts": [
'resolve-fedora-aliases = fedora_distro_aliases.cli:cli'
],
},
)

0 comments on commit be9ff85

Please sign in to comment.