Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
---------------------------------------------------------------
commit fcf648f891c27eeb68ebe6bbaf2f600e51f20ae4
Author: Michal Minar <miminar(a)redhat.com>
Date: Sun Jan 19 15:13:32 2014 +0100
terminate with exit code of last command executed
Make sure that return code of triggered command gets propagated to the
application's entry point.
In interactive mode, meta-command shall exit with the return code of the
last command executed. Note that exit is also a command (returning 0 by
default).
Resolves ticket #174
Original commit digest in openlmi-scripts repo:
0580e779fee8bcd21dd00b2374c96902c1b49cf1
---------------------------------------------------------------
cli/lmi/scripts/_metacommand/__init__.py | 5 ++++-
cli/lmi/scripts/common/command/base.py | 4 +++-
cli/lmi/scripts/common/command/session.py | 2 +-
3 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/cli/lmi/scripts/_metacommand/__init__.py
b/cli/lmi/scripts/_metacommand/__init__.py
index e26c1b7..598c0a7 100644
--- a/cli/lmi/scripts/_metacommand/__init__.py
+++ b/cli/lmi/scripts/_metacommand/__init__.py
@@ -204,7 +204,7 @@ class MetaCommand(object):
"""
cmd = TopLevelCommand(self)
try:
- return cmd.run(argv)
+ retval = cmd.run(argv)
except Exception as exc:
trace = True if self.config is None else self.config.trace
if isinstance(exc, errors.LmiError) or not trace:
@@ -212,6 +212,9 @@ class MetaCommand(object):
else:
LOG().exception("fatal")
return 1
+ if isinstance(retval, bool) or not isinstance(retval, (int, long)):
+ return 0 if bool(retval) or retval is None else 1
+ return retval
def main(argv=sys.argv[1:]):
"""
diff --git a/cli/lmi/scripts/common/command/base.py
b/cli/lmi/scripts/common/command/base.py
index dcf40bf..62a1aec 100644
--- a/cli/lmi/scripts/common/command/base.py
+++ b/cli/lmi/scripts/common/command/base.py
@@ -219,7 +219,9 @@ class LmiBaseCommand(object):
:param list args: Arguments passed to the command line that were
not yet parsed. It's the contents of ``sys.argv`` (if in
non-interactive mode) from the current command on.
- :returns: Exit code of application.
+ :returns: Exit code of application. This maybe also be a boolean value
+ or ``None``. ``None`` and ``True`` are treated as a success causing
+ exit code to be 0.
:rtype: integer
"""
raise NotImplementedError("run method must be overriden in subclass")
diff --git a/cli/lmi/scripts/common/command/session.py
b/cli/lmi/scripts/common/command/session.py
index 1be7fec..b65952a 100644
--- a/cli/lmi/scripts/common/command/session.py
+++ b/cli/lmi/scripts/common/command/session.py
@@ -187,5 +187,5 @@ class LmiSessionCommand(LmiEndPointCommand):
return self.execute(connection, *args, **kwargs)
def run_with_args(self, args, kwargs):
- self.process_session(self.app.session, args, kwargs)
+ return self.process_session(self.app.session, args, kwargs)