Merge "command: make run() return take_action() value"
This commit is contained in:
commit
5fcd470fd4
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue