diff options
author | lorddavidiii <maximillian.bensch@aei.mpg.de> | 2022-04-26 16:08:56 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-26 09:08:56 -0700 |
commit | 3a0aba0835d63082f93ae0a80ccb5a41da67278d (patch) | |
tree | 4e4303569c70fa2ee954802eaff0654362327a28 /lib | |
parent | 254cd624fe00eaffedc08301e7780dad3243465b (diff) | |
download | spack-3a0aba0835d63082f93ae0a80ccb5a41da67278d.tar.gz spack-3a0aba0835d63082f93ae0a80ccb5a41da67278d.tar.bz2 spack-3a0aba0835d63082f93ae0a80ccb5a41da67278d.tar.xz spack-3a0aba0835d63082f93ae0a80ccb5a41da67278d.zip |
spack spec: add '--format' argument (#27908)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/cmd/spec.py | 12 | ||||
-rw-r--r-- | lib/spack/spack/test/cmd/spec.py | 5 |
2 files changed, 14 insertions, 3 deletions
diff --git a/lib/spack/spack/cmd/spec.py b/lib/spack/spack/cmd/spec.py index d908944976..8ad5f777a5 100644 --- a/lib/spack/spack/cmd/spec.py +++ b/lib/spack/spack/cmd/spec.py @@ -34,12 +34,16 @@ for further documentation regarding the spec syntax, see: 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(): diff --git a/lib/spack/spack/test/cmd/spec.py b/lib/spack/spack/test/cmd/spec.py index 74be6f4ca0..3fb25a3ea8 100644 --- a/lib/spack/spack/test/cmd/spec.py +++ b/lib/spack/spack/test/cmd/spec.py @@ -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') |