From b5071312c4a92015026aa2f1eb77a2478884a27d Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Tue, 24 Jul 2018 23:57:22 -0700 Subject: spack spec: no extra newline with --yaml; error with no specs - `spack spec` now returns an error if given no specs - removed superfluous trailing newline from `spack spec --yaml` output (only one newline now) --- lib/spack/spack/cmd/spec.py | 11 ++++++++++- lib/spack/spack/test/cmd/spec.py | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/spack/spack/cmd/spec.py b/lib/spack/spack/cmd/spec.py index fec5772776..bac8dd4727 100644 --- a/lib/spack/spack/cmd/spec.py +++ b/lib/spack/spack/cmd/spec.py @@ -25,7 +25,11 @@ from __future__ import print_function import argparse +import sys +import llnl.util.tty as tty + +import spack import spack.cmd import spack.cmd.common.arguments as arguments @@ -66,12 +70,17 @@ def spec(parser, args): 'show_types': args.types, 'install_status': args.install_status} + if not args.specs: + tty.die("spack spec requires at least one spec") + for spec in spack.cmd.parse_specs(args.specs): # With -y, just print YAML to output. if args.yaml: if spec.name in spack.repo.path or spec.virtual: spec.concretize() - print(spec.to_yaml()) + + # use write because to_yaml already has a newline. + sys.stdout.write(spec.to_yaml()) continue kwargs['hashes'] = False # Always False for input spec diff --git a/lib/spack/spack/test/cmd/spec.py b/lib/spack/spack/test/cmd/spec.py index 75d91bcddf..2c7404d28f 100644 --- a/lib/spack/spack/test/cmd/spec.py +++ b/lib/spack/spack/test/cmd/spec.py @@ -88,3 +88,9 @@ def test_spec_deptypes_edges(): assert types['dt-diamond-left'] == ['bl '] assert types['dt-diamond-right'] == ['bl '] assert types['dt-diamond-bottom'] == ['b ', 'blr '] + + +def test_spec_returncode(): + with pytest.raises(spack.main.SpackCommandError): + spec() + assert spec.returncode == 1 -- cgit v1.2.3-60-g2f50