From 935eba23579af1d64e56fea38ab981846e127645 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 5 Jan 2015 02:33:15 -0500 Subject: Allow commands to return error codes. --- bin/spack | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'bin') diff --git a/bin/spack b/bin/spack index b345a5079d..626d9d9d11 100755 --- a/bin/spack +++ b/bin/spack @@ -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)) -- cgit v1.2.3-70-g09d2