diff options
author | Victor Boivie <victor.boivie@sonyericsson.com> | 2011-09-07 09:43:28 +0200 |
---|---|---|
committer | David Pursehouse <david.pursehouse@sonymobile.com> | 2012-11-16 04:22:10 +0900 |
commit | 88b86728a4451b97a2c6dcae2feb98014c077793 (patch) | |
tree | cd7329765b3a013535a4c8d5290085ec8fda6101 /subcmds | |
parent | e66291f6d0f29938d6671cf8702d0fdab45a1199 (diff) | |
download | git-repo-88b86728a4451b97a2c6dcae2feb98014c077793.tar.gz |
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>
Diffstat (limited to 'subcmds')
-rw-r--r-- | subcmds/forall.py | 15 |
1 files changed, 13 insertions, 2 deletions
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 <command>. | |||
93 | 93 | ||
94 | Unless -p is used, stdin, stdout, stderr are inherited from the | 94 | Unless -p is used, stdin, stdout, stderr are inherited from the |
95 | terminal and are not redirected. | 95 | terminal and are not redirected. |
96 | |||
97 | If -e is used, when a command exits unsuccessfully, '%prog' will abort | ||
98 | without iterating through the remaining projects. | ||
96 | """ | 99 | """ |
97 | 100 | ||
98 | def _Options(self, p): | 101 | def _Options(self, p): |
@@ -105,6 +108,9 @@ terminal and are not redirected. | |||
105 | dest='command', | 108 | dest='command', |
106 | action='callback', | 109 | action='callback', |
107 | callback=cmd) | 110 | callback=cmd) |
111 | p.add_option('-e', '--abort-on-errors', | ||
112 | dest='abort_on_errors', action='store_true', | ||
113 | help='Abort if a command exits unsuccessfully') | ||
108 | 114 | ||
109 | g = p.add_option_group('Output') | 115 | g = p.add_option_group('Output') |
110 | g.add_option('-p', | 116 | g.add_option('-p', |
@@ -255,7 +261,12 @@ terminal and are not redirected. | |||
255 | s.dest.flush() | 261 | s.dest.flush() |
256 | 262 | ||
257 | r = p.wait() | 263 | r = p.wait() |
258 | if r != 0 and r != rc: | 264 | if r != 0: |
259 | rc = r | 265 | if r != rc: |
266 | rc = r | ||
267 | if opt.abort_on_errors: | ||
268 | print("error: %s: Aborting due to previous error" % project.relpath, | ||
269 | file=sys.stderr) | ||
270 | sys.exit(r) | ||
260 | if rc != 0: | 271 | if rc != 0: |
261 | sys.exit(rc) | 272 | sys.exit(rc) |