From 88b86728a4451b97a2c6dcae2feb98014c077793 Mon Sep 17 00:00:00 2001 From: Victor Boivie Date: Wed, 7 Sep 2011 09:43:28 +0200 Subject: 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 --- subcmds/forall.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'subcmds/forall.py') diff --git a/subcmds/forall.py b/subcmds/forall.py index 49e725c2..4c1c9ff8 100644 --- a/subcmds/forall.py +++ b/subcmds/forall.py @@ -93,6 +93,9 @@ following . 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 @@ terminal and are not redirected. 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 @@ terminal and are not redirected. 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) -- cgit v1.2.3-54-g00ecf