=== modified file 'lava/tool/command.py'
@@ -44,6 +44,12 @@
self.parser = parser
self.args = args
+ def say(self, message, *args, **kwargs):
+ """
+ Handy wrapper for print + format
+ """
+ self.args.dispatcher.say(self, message, *args, **kwargs)
+
def invoke(self):
"""
Invoke command action.
@@ -141,7 +147,7 @@
This method is called around the same time as register_arguments()
would be called for the plain command classes. It loads commands from
the entry point namespace returned by get_namespace() and registeres
- them with a BaseDispatcher class. The parsers used by that dispatcher
+ them with a Dispatcher class. The parsers used by that dispatcher
are linked to the calling dispatcher parser so the new commands enrich
the top-level parser tree.
@@ -149,8 +155,8 @@
defaults. This is useful when one wants to access it later. To a final
command instance it shall be available as self.args.dispatcher.
"""
- from lava.tool.dispatcher import BaseDispatcher
- dispatcher = BaseDispatcher(parser, name=cls.get_name())
+ from lava.tool.dispatcher import Dispatcher
+ dispatcher = Dispatcher(parser, name=cls.get_name())
namespace = cls.get_namespace()
if namespace is not None:
dispatcher.import_commands(namespace)
=== modified file 'lava/tool/dispatcher.py'
@@ -69,7 +69,7 @@
try:
command_cls = entrypoint.load()
except (ImportError, pkg_resources.DistributionNotFound) as exc:
- logging.debug("Unable to load %s: %r", entrypoint, exc)
+ logging.exception("Unable to load command: %s", entrypoint.name)
else:
self.add_command_cls(command_cls)
@@ -102,6 +102,8 @@
sub_parser.set_defaults(
command_cls=command_cls,
parser=sub_parser)
+ # Make sure the sub-parser knows about this dispatcher
+ sub_parser.set_defaults(dispatcher=self)
def dispatch(self, raw_args=None):
"""
@@ -126,8 +128,16 @@
return 1
@classmethod
- def run(cls):
+ def run(cls, args=None):
"""
Dispatch commandsd and exit
"""
- raise SystemExit(cls().dispatch())
+ raise SystemExit(cls().dispatch(args))
+
+ def say(self, command, message, *args, **kwargs):
+ """
+ Handy wrapper for print + format
+ """
+ print "{0} >>> {1}".format(
+ command.get_name(),
+ message.format(*args, **kwargs))