Closed
Description
I like to use the class-based API for commands. Group(commands=)
takes a dict mapping name to command. So I end up writing:
#!/usr/bin env python3
import click
def f(*a, **kw):
print(a, kw)
commands = [click.Command("cmd1", callback=f), click.Command("cmd2", callback=f)]
cli = click.Group(commands={c.name: c for c in commands})
if __name__ == "__main__":
cli()
It's a bit annoying to need the dict comprehension outside, so I'm wondering if you might take an addition in __init__
, like
if isinstance(commands, collections.abc.Sequence):
commands = {command.name: command for command in commands}
so that I could write
click.Group(commands=commands)
instead of
click.Group(commands={c.name: c for c in commands})
in all my scripts.
Metadata
Metadata
Assignees
Labels
No labels