diff options
author | Doug Hellmann <doug.hellmann@gmail.com> | 2013-11-12 18:14:37 -0500 |
---|---|---|
committer | Doug Hellmann <doug.hellmann@gmail.com> | 2013-11-12 18:14:37 -0500 |
commit | 1192cf679b105a00785f8ee3e360afb36f8e9e03 (patch) | |
tree | e96975a92b5b6a8bc9af347400fb1f45d1c16f20 /cliff/complete.py | |
parent | 9b77b62a687359ff9a7f35f50b13ec78b6cb8ae8 (diff) | |
download | cliff-1192cf679b105a00785f8ee3e360afb36f8e9e03.tar.gz |
use entry points for completion plugins
Diffstat (limited to 'cliff/complete.py')
-rw-r--r-- | cliff/complete.py | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/cliff/complete.py b/cliff/complete.py index 340eb7f..fa1dd5c 100644 --- a/cliff/complete.py +++ b/cliff/complete.py @@ -5,6 +5,8 @@ import logging import six +import stevedore + from cliff import command @@ -134,6 +136,12 @@ class CompleteCommand(command.Command): log = logging.getLogger(__name__ + '.CompleteCommand') + def __init__(self, app, app_args): + super(CompleteCommand, self).__init__(app, app_args) + self._formatters = stevedore.ExtensionManager( + namespace='cliff.formatter.completion', + ) + def get_parser(self, prog_name): parser = super(CompleteCommand, self).get_parser(prog_name) parser.add_argument( @@ -146,7 +154,7 @@ class CompleteCommand(command.Command): "--shell", default='bash', metavar='<shell>', - choices=['bash', 'none'], + choices=sorted(self._formatters.names()), help="Shell being used. Use none for data only (default: bash)" ) return parser @@ -165,14 +173,12 @@ class CompleteCommand(command.Command): def take_action(self, parsed_args): self.log.debug('take_action(%s)' % parsed_args) - if parsed_args.name: - name = parsed_args.name - else: - name = self.app.NAME - if parsed_args.shell == "none": - shell = CompleteNoCode(name, self.app.stdout) - else: - shell = CompleteBash(name, self.app.stdout) + name = parsed_args.name or self.app.NAME + try: + shell_factory = self._formatters[parsed_args.shell].plugin + except KeyError: + raise RuntimeError('Unknown shell syntax %r' % parsed_args.shell) + shell = shell_factory(name, self.app.stdout) dicto = CompleteDictionary() for cmd in self.app.command_manager: |