summaryrefslogtreecommitdiff
path: root/cliff/display.py
diff options
context:
space:
mode:
Diffstat (limited to 'cliff/display.py')
-rw-r--r--cliff/display.py28
1 files changed, 12 insertions, 16 deletions
diff --git a/cliff/display.py b/cliff/display.py
index 44da7e1..edea1f3 100644
--- a/cliff/display.py
+++ b/cliff/display.py
@@ -3,7 +3,7 @@
import abc
import logging
-import pkg_resources
+import stevedore
from .command import Command
@@ -18,7 +18,7 @@ class DisplayCommandBase(Command):
def __init__(self, app, app_args):
super(DisplayCommandBase, self).__init__(app, app_args)
- self.load_formatter_plugins()
+ self.formatters = self._load_formatter_plugins()
@abc.abstractproperty
def formatter_namespace(self):
@@ -28,16 +28,12 @@ class DisplayCommandBase(Command):
def formatter_default(self):
"String specifying the name of the default formatter."
- def load_formatter_plugins(self):
- self.formatters = {}
- for ep in pkg_resources.iter_entry_points(self.formatter_namespace):
- try:
- self.formatters[ep.name] = ep.load()()
- except Exception as err:
- LOG.error(err)
- if self.app_args.debug:
- raise
- return
+ def _load_formatter_plugins(self):
+ # Here so tests can override
+ return stevedore.ExtensionManager(
+ self.formatter_namespace,
+ invoke_on_load=True,
+ )
def get_parser(self, prog_name):
parser = super(DisplayCommandBase, self).get_parser(prog_name)
@@ -45,7 +41,7 @@ class DisplayCommandBase(Command):
title='output formatters',
description='output formatter options',
)
- formatter_choices = sorted(self.formatters.keys())
+ formatter_choices = sorted(self.formatters.names())
formatter_default = self.formatter_default
if formatter_default not in formatter_choices:
formatter_default = formatter_choices[0]
@@ -65,8 +61,8 @@ class DisplayCommandBase(Command):
metavar='COLUMN',
help='specify the column(s) to include, can be repeated',
)
- for name, formatter in sorted(self.formatters.items()):
- formatter.add_argument_group(parser)
+ for formatter in self.formatters:
+ formatter.obj.add_argument_group(parser)
return parser
@abc.abstractmethod
@@ -80,7 +76,7 @@ class DisplayCommandBase(Command):
"""
def run(self, parsed_args):
- self.formatter = self.formatters[parsed_args.formatter]
+ self.formatter = self.formatters[parsed_args.formatter].obj
column_names, data = self.take_action(parsed_args)
self.produce_output(parsed_args, column_names, data)
return 0