Merge "command: make run() return take_action() value"

This commit is contained in:
Jenkins 2016-07-14 14:06:43 +00:00 committed by Gerrit Code Review
commit 5fcd470fd4
2 changed files with 11 additions and 3 deletions

View File

@ -40,6 +40,8 @@ class Command(object):
@abc.abstractmethod
def take_action(self, parsed_args):
"""Override to do something useful.
The returned value will be returned by the program.
"""
def run(self, parsed_args):
@ -51,6 +53,7 @@ class Command(object):
Developers creating new command base classes (such as
:class:`Lister` and :class:`ShowOne`) should override this
method to wrap :meth:`take_action`.
Return the value returned by :method:`take_action` or 0.
"""
self.take_action(parsed_args)
return 0
return self.take_action(parsed_args) or 0

View File

@ -7,7 +7,7 @@ class TestCommand(Command):
"""
def take_action(self, parsed_args):
return
return 42
def test_get_description():
@ -25,3 +25,8 @@ def test_get_parser():
def test_get_name():
cmd = TestCommand(None, None, cmd_name='object action')
assert cmd.cmd_name == 'object action'
def test_run_return():
cmd = TestCommand(None, None, cmd_name='object action')
assert cmd.run(None) == 42