spack spec: add '--format' argument (#27908)
This commit is contained in:
@@ -34,12 +34,16 @@ def setup_parser(subparser):
|
||||
arguments.add_common_arguments(
|
||||
subparser, ['long', 'very_long', 'install_status']
|
||||
)
|
||||
subparser.add_argument(
|
||||
format_group = subparser.add_mutually_exclusive_group()
|
||||
format_group.add_argument(
|
||||
'-y', '--yaml', action='store_const', dest='format', default=None,
|
||||
const='yaml', help='print concrete spec as YAML')
|
||||
subparser.add_argument(
|
||||
format_group.add_argument(
|
||||
'-j', '--json', action='store_const', dest='format', default=None,
|
||||
const='json', help='print concrete spec as JSON')
|
||||
format_group.add_argument(
|
||||
'--format', action='store', default=None,
|
||||
help='print concrete spec with the specified format string')
|
||||
subparser.add_argument(
|
||||
'-c', '--cover', action='store',
|
||||
default='nodes', choices=['nodes', 'edges', 'paths'],
|
||||
@@ -98,8 +102,10 @@ def spec(parser, args):
|
||||
if args.format == 'yaml':
|
||||
# use write because to_yaml already has a newline.
|
||||
sys.stdout.write(output.to_yaml(hash=hash_type))
|
||||
else:
|
||||
elif args.format == 'json':
|
||||
print(output.to_json(hash=hash_type))
|
||||
else:
|
||||
print(output.format(args.format))
|
||||
continue
|
||||
|
||||
with tree_context():
|
||||
|
@@ -79,6 +79,11 @@ def test_spec_json():
|
||||
assert 'mpich' in mpileaks
|
||||
|
||||
|
||||
def test_spec_format(database, config):
|
||||
output = spec('--format', '{name}-{^mpi.name}', 'mpileaks^mpich')
|
||||
assert output.rstrip('\n') == "mpileaks-mpich"
|
||||
|
||||
|
||||
def _parse_types(string):
|
||||
"""Parse deptypes for specs from `spack spec -t` output."""
|
||||
lines = string.strip().split('\n')
|
||||
|
Reference in New Issue
Block a user