diff --git a/fedora_distro_aliases/cli.py b/fedora_distro_aliases/cli.py new file mode 100644 index 0000000..a5d0e2b --- /dev/null +++ b/fedora_distro_aliases/cli.py @@ -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)) diff --git a/setup.py b/setup.py index 456210b..6ca5f6e 100644 --- a/setup.py +++ b/setup.py @@ -20,6 +20,7 @@ install_requires = [ "munch", "requests", + "Click", # for the CLI and GH Action ] __description__ = "Aliases for active Fedora releases" @@ -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' + ], + }, )