diff --git a/bin/spack b/bin/spack index b345a5079d2808abc866bf7bcc30735f0cdeea78..626d9d9d11ff7e4aa7c8d9c293f75e19c13c4573 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)) diff --git a/lib/spack/spack/cmd/graph.py b/lib/spack/spack/cmd/graph.py index f8cd18d91f625e017fdc828d1caf079e8243713d..cb93a1b5433fd262141323a455c2d1b0e5bbcf86 100644 --- a/lib/spack/spack/cmd/graph.py +++ b/lib/spack/spack/cmd/graph.py @@ -31,6 +31,8 @@ description = "Generate graphs of package dependency relationships." def setup_parser(subparser): + setup_parser.parser = subparser + method = subparser.add_mutually_exclusive_group() method.add_argument( '--ascii', action='store_true', @@ -50,6 +52,9 @@ def graph(parser, args): specs = spack.cmd.parse_specs( args.specs, normalize=True, concretize=args.concretize) + if not specs: + setup_parser.parser.print_help() + return 1 if args.dot: # Dot graph only if asked for. graph_dot(*specs) diff --git a/lib/spack/spack/cmd/md5.py b/lib/spack/spack/cmd/md5.py index 496835c64b833fccf5a4808f69087758b38a57fb..dfa1be412bfc343f08326c126ecac9425d870478 100644 --- a/lib/spack/spack/cmd/md5.py +++ b/lib/spack/spack/cmd/md5.py @@ -41,6 +41,7 @@ def setup_parser(subparser): def md5(parser, args): if not args.files: setup_parser.parser.print_help() + return 1 for f in args.files: if not os.path.isfile(f):