diff options
-rw-r--r-- | cliff/commandmanager.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/cliff/commandmanager.py b/cliff/commandmanager.py index 65af9ed..bb8bfe2 100644 --- a/cliff/commandmanager.py +++ b/cliff/commandmanager.py @@ -9,6 +9,18 @@ import pkg_resources LOG = logging.getLogger(__name__) +class EntryPointWrapper(object): + """Wrap up a command class already imported to make it look like a plugin. + """ + + def __init__(self, name, command_class): + self.name = name + self.command_class = command_class + + def load(self): + return self.command_class + + class CommandManager(object): """Discovers commands and handles lookup based on argv data. """ @@ -26,6 +38,9 @@ class CommandManager(object): def __iter__(self): return iter(self.commands.items()) + def add_command(self, name, command_class): + self.commands[name] = EntryPointWrapper(name, command_class) + def find_command(self, argv): """Given an argument list, find a command and return the processor and any remaining arguments. @@ -42,5 +57,5 @@ class CommandManager(object): cmd_factory = cmd_ep.load() return (cmd_factory, name, search_args) else: - raise ValueError('Did not find command processor for %r' % + raise ValueError('Unknown command %r' % (argv,)) |