Allow commands to return error codes.

This commit is contained in:
Todd Gamblin
2015-01-05 02:33:15 -05:00
parent 5d033fbd0a
commit 935eba2357
3 changed files with 15 additions and 1 deletions

View File

@@ -103,7 +103,7 @@ if args.insecure:
# Try to load the particular command asked for and run it
command = spack.cmd.get_command(args.command)
try:
command(parser, args)
return_val = command(parser, args)
except SpackError, e:
if spack.debug:
# In debug mode, raise with a full stack trace.
@@ -116,3 +116,11 @@ except SpackError, e:
except KeyboardInterrupt:
sys.stderr.write('\n')
tty.die("Keyboard interrupt.")
# Allow commands to return values if they want to exit with some ohter code.
if return_val is None:
sys.exit(0)
elif isinstance(return_val, int):
sys.exit(return_val)
else:
tty.die("Bad return value from command %s: %s" % (args.command, return_val))