diff options
author | Eric Lin <anselor@gmail.com> | 2020-08-12 13:08:59 -0400 |
---|---|---|
committer | anselor <anselor@gmail.com> | 2020-08-12 17:41:20 -0400 |
commit | 774fb39d7e259d0679c573b0d893293f9ed9aed9 (patch) | |
tree | a78a4693e7cca707668eb89b0d8e41c3fedd108e /cmd2/command_definition.py | |
parent | 4d628ea7573ef9016971dbbf7de9126c6d179227 (diff) | |
download | cmd2-git-774fb39d7e259d0679c573b0d893293f9ed9aed9.tar.gz |
Breaking change: Removed cmd2 app as a required second parameter to
CommandSet command functions (do_, complete_, help_).
Renamed install_command_set and uninstall_command_set to
register_command_set and unregister_command_set.
Diffstat (limited to 'cmd2/command_definition.py')
-rw-r--r-- | cmd2/command_definition.py | 35 |
1 files changed, 2 insertions, 33 deletions
diff --git a/cmd2/command_definition.py b/cmd2/command_definition.py index 22d8915e..86f1151a 100644 --- a/cmd2/command_definition.py +++ b/cmd2/command_definition.py @@ -18,36 +18,6 @@ except ImportError: # pragma: no cover pass -def _partial_passthru(func: Callable, *args, **kwargs) -> functools.partial: - """ - Constructs a partial function that passes arguments through to the wrapped function. - Must construct a new type every time so that each wrapped function's __doc__ can be copied correctly. - - :param func: wrapped function - :param args: positional arguments - :param kwargs: keyword arguments - :return: partial function that exposes attributes of wrapped function - """ - def __getattr__(self, item): - return getattr(self.func, item) - - def __setattr__(self, key, value): - return setattr(self.func, key, value) - - def __dir__(self) -> Iterable[str]: - return dir(self.func) - - passthru_type = type('PassthruPartial' + func.__name__, - (functools.partial,), - { - '__getattr__': __getattr__, - '__setattr__': __setattr__, - '__dir__': __dir__, - }) - passthru_type.__doc__ = func.__doc__ - return passthru_type(func, *args, **kwargs) - - def with_default_category(category: str): """ Decorator that applies a category to all ``do_*`` command methods in a class that do not already @@ -78,8 +48,7 @@ class CommandSet(object): ``with_default_category`` can be used to apply a default category to all commands in the CommandSet. - ``do_``, ``help_``, and ``complete_`` functions differ only in that they're now required to accept - a reference to ``cmd2.Cmd`` as the first argument after self. + ``do_``, ``help_``, and ``complete_`` functions differ only in that self is the CommandSet instead of the cmd2 app """ def __init__(self): @@ -98,7 +67,7 @@ class CommandSet(object): else: raise CommandSetRegistrationError('This CommandSet has already been registered') - def on_unregister(self, cmd): + def on_unregister(self): """ Called by ``cmd2.Cmd`` when a CommandSet is unregistered and removed. |