From 44dd1bc6a6e42980554ae773d286f27dda3df1d8 Mon Sep 17 00:00:00 2001 From: jpic Date: Sat, 24 Apr 2021 13:35:29 +0200 Subject: [PATCH] Fix output in case of failed command --- shlax/cli.py | 8 ++++++-- shlax/targets/base.py | 22 ++++++++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/shlax/cli.py b/shlax/cli.py index 6e99c7e..9d07cf5 100644 --- a/shlax/cli.py +++ b/shlax/cli.py @@ -60,9 +60,13 @@ class Command(cli2.Command): except ProcFailure: # just output the failure without TB, as command was already # printed anyway - pass + self.exit_code = 1 self['target'].value.output.results(self['target'].value) - return result + + if result and result.status == 'success': + self.exit_code = 0 + else: + self.exit_code = 1 class ActionCommand(cli2.Command): diff --git a/shlax/targets/base.py b/shlax/targets/base.py index f1ab1ab..d4907c3 100644 --- a/shlax/targets/base.py +++ b/shlax/targets/base.py @@ -6,7 +6,7 @@ import re import sys from ..output import Output -from ..proc import Proc +from ..proc import Proc, ProcFailure from ..result import Result, Results @@ -68,13 +68,19 @@ class Target: self.output.fail(action, e) result.status = 'failure' result.exception = e - if reraise: - # nested call, re-raise - raise - else: - import traceback - traceback.print_exception(type(e), e, sys.exc_info()[2]) - return True + + if not isinstance(e, ProcFailure): + # no need to reraise in case of command error + # because the command has been printed + + if reraise: + # nested call, re-raise + raise + else: + import traceback + traceback.print_exception(type(e), e, sys.exc_info()[2]) + + return True # because it failed else: if getattr(action, 'skipped', False): self.output.skip(action)