summaryrefslogtreecommitdiff
path: root/cliff/show.py
diff options
context:
space:
mode:
authorDoug Hellmann <doug.hellmann@dreamhost.com>2012-04-29 19:19:42 -0400
committerDoug Hellmann <doug.hellmann@dreamhost.com>2012-04-29 19:19:42 -0400
commita25a7912180e4f41bb1daf4398d23033036a4386 (patch)
tree62949a0831274e6b30cc70cec47e7f1c75d29d19 /cliff/show.py
parent25c560489b09b58b27032e4ae2694f6e9cc4880c (diff)
downloadcliff-a25a7912180e4f41bb1daf4398d23033036a4386.tar.gz
refactor ShowOne and Lister to share a common base class
Diffstat (limited to 'cliff/show.py')
-rw-r--r--cliff/show.py46
1 files changed, 8 insertions, 38 deletions
diff --git a/cliff/show.py b/cliff/show.py
index 93c48ce..b2c7945 100644
--- a/cliff/show.py
+++ b/cliff/show.py
@@ -3,54 +3,24 @@
import abc
import logging
-import pkg_resources
-
-from .command import Command
+from .display import DisplayCommandBase
LOG = logging.getLogger(__name__)
-class ShowOne(Command):
+class ShowOne(DisplayCommandBase):
"""Command base class for displaying data about a single object.
"""
__metaclass__ = abc.ABCMeta
- def __init__(self, app, app_args):
- super(ShowOne, self).__init__(app, app_args)
- self.load_formatter_plugins()
-
- def load_formatter_plugins(self):
- self.formatters = {}
- for ep in pkg_resources.iter_entry_points('cliff.formatter.show'):
- try:
- self.formatters[ep.name] = ep.load()()
- except Exception as err:
- LOG.error(err)
- if self.app_args.debug:
- raise
+ @property
+ def formatter_namespace(self):
+ return 'cliff.formatter.show'
- def get_parser(self, prog_name):
- parser = super(ShowOne, self).get_parser(prog_name)
- formatter_group = parser.add_argument_group(
- title='output formatters',
- description='List output formatter options',
- )
- formatter_choices = sorted(self.formatters.keys())
- formatter_default = 'table'
- if formatter_default not in formatter_choices:
- formatter_default = formatter_choices[0]
- formatter_group.add_argument(
- '-f', '--format',
- dest='formatter',
- action='store',
- choices=formatter_choices,
- default=formatter_default,
- help='the output format to use, defaults to %s' % formatter_default,
- )
- for name, formatter in sorted(self.formatters.items()):
- formatter.add_argument_group(parser)
- return parser
+ @property
+ def formatter_default(self):
+ return 'table'
@abc.abstractmethod
def get_data(self, parsed_args):