Skip to content
Snippets Groups Projects
Commit ce879b45 authored by Raphaël Gomès's avatar Raphaël Gomès
Browse files

cli: add available subcommands to help

I've forgotten too many times the names of the commands, this makes it
obvious which ones can be called.
parent 6961bdbc
No related branches found
No related tags found
1 merge request!24cli: add available subcommands to help
......@@ -3,4 +3,5 @@
import click
BINARIES = resources.files("poulpe.bin")
......@@ -6,4 +7,30 @@
helptext = """Wrapper around Poulpe binaries for ease of calling.
\b
Available Poulpe commands:
{subcommands}"""
def set_dynamic_help():
"""Dynamically set the helptext to populate with available commands
in `poulpe.bin`."""
# XXX This is kinda bad and manual, but it's the price we pay
# for ensuring we have independent binaries.
# We can do better (completion, factored help, etc.) later.
def decorator(command):
subcommands = ", ".join(
f.name for f in BINARIES.iterdir() if f.is_file()
)
command.help = helptext.format(subcommands=subcommands)
return command
return decorator
@set_dynamic_help()
@click.command(
no_args_is_help=True,
context_settings={
......@@ -14,8 +41,8 @@
@click.argument('subcommand')
@click.argument('subcommand_args', nargs=-1, type=click.UNPROCESSED)
def exec_subcommand(subcommand, subcommand_args):
"""Wrapper around Poulpe binaries for ease of calling"""
subcommand_file = resources.files("poulpe.bin").joinpath(subcommand)
"""Help is set dynamically, see `set_dynamic_help`"""
subcommand_file = BINARIES.joinpath(subcommand)
if not subcommand_file.is_file():
raise click.BadParameter(f"Subcommand `{subcommand}` does not exist.")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment