Skip to content

Instantly share code, notes, and snippets.

@pblocz
Last active March 14, 2018 21:04
Show Gist options
  • Save pblocz/380e922abf7bce37f2319ebc0f93a879 to your computer and use it in GitHub Desktop.
Save pblocz/380e922abf7bce37f2319ebc0f93a879 to your computer and use it in GitHub Desktop.
import functools
import click
class Command:
def __init__(self, f, args, kwargs):
self.f = f
self.args = args
self.kwargs = kwargs
self.cmd = click.command(*args, **kwargs)(f)
functools.update_wrapper(self, f)
def register_to(self, grp):
grp.add_command(self.cmd)
class Blueprint:
def __init__(self):
self._commands = []
def register_to(self, group):
for cmd in self._commands:
cmd.register_to(group)
def command(self, *args, **kwargs):
def _decorator(f):
cmd = Command(f, args, kwargs)
self._commands.append(cmd)
return cmd
return _decorator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment