Add option to abort on error in forall
Add a new option (-e, --abort-on-errors) which will cause forall to
abort without iterating through remaining projects if a command
exits unsuccessfully.
Bug: Issue 17
Change-Id: Ibea405e0d98b575ad3bda719d511f6982511c19c
Signed-off-by: Victor Boivie <victor.boivie@sonyericsson.com>
diff --git a/subcmds/forall.py b/subcmds/forall.py
index 49e725c..4c1c9ff 100644
--- a/subcmds/forall.py
+++ b/subcmds/forall.py
@@ -93,6 +93,9 @@
Unless -p is used, stdin, stdout, stderr are inherited from the
terminal and are not redirected.
+
+If -e is used, when a command exits unsuccessfully, '%prog' will abort
+without iterating through the remaining projects.
"""
def _Options(self, p):
@@ -105,6 +108,9 @@
dest='command',
action='callback',
callback=cmd)
+ p.add_option('-e', '--abort-on-errors',
+ dest='abort_on_errors', action='store_true',
+ help='Abort if a command exits unsuccessfully')
g = p.add_option_group('Output')
g.add_option('-p',
@@ -255,7 +261,12 @@
s.dest.flush()
r = p.wait()
- if r != 0 and r != rc:
- rc = r
+ if r != 0:
+ if r != rc:
+ rc = r
+ if opt.abort_on_errors:
+ print("error: %s: Aborting due to previous error" % project.relpath,
+ file=sys.stderr)
+ sys.exit(r)
if rc != 0:
sys.exit(rc)