Last active
March 14, 2018 21:04
-
-
Save pblocz/380e922abf7bce37f2319ebc0f93a879 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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