diff options
-rw-r--r-- | lib/spack/spack/cmd/list.py | 7 | ||||
-rw-r--r-- | lib/spack/spack/test/cmd/list.py | 14 | ||||
-rwxr-xr-x | share/spack/spack-completion.bash | 2 |
3 files changed, 22 insertions, 1 deletions
diff --git a/lib/spack/spack/cmd/list.py b/lib/spack/spack/cmd/list.py index c51c0959c0..54f8e890f4 100644 --- a/lib/spack/spack/cmd/list.py +++ b/lib/spack/spack/cmd/list.py @@ -16,6 +16,7 @@ import sys import llnl.util.tty as tty from llnl.util.tty.colify import colify +import spack.cmd.common.arguments as arguments import spack.dependency import spack.repo from spack.version import VersionList @@ -72,6 +73,7 @@ def setup_parser(subparser): default=False, help="include virtual packages in list", ) + arguments.add_common_arguments(subparser, ["tags"]) def filter_by_name(pkgs, args): @@ -306,6 +308,11 @@ def list(parser, args): # Filter the set appropriately sorted_packages = filter_by_name(pkgs, args) + # If tags have been specified on the command line, filter by tags + if args.tags: + packages_with_tags = spack.repo.path.packages_with_tags(*args.tags) + sorted_packages = [p for p in sorted_packages if p in packages_with_tags] + if args.update: # change output stream if user asked for update if os.path.exists(args.update): diff --git a/lib/spack/spack/test/cmd/list.py b/lib/spack/spack/test/cmd/list.py index 5a4b4b223e..924ef140b3 100644 --- a/lib/spack/spack/test/cmd/list.py +++ b/lib/spack/spack/test/cmd/list.py @@ -84,3 +84,17 @@ def test_list_update(tmpdir, mock_packages): assert update_file.exists() with update_file.open() as f: assert f.read() == "empty\n" + + +def test_list_tags(mock_packages): + output = list("--tag", "tag1") + assert "mpich" in output + assert "mpich2" in output + + output = list("--tag", "tag2") + assert "mpich\n" in output + assert "mpich2" not in output + + output = list("--tag", "tag3") + assert "mpich\n" not in output + assert "mpich2" in output diff --git a/share/spack/spack-completion.bash b/share/spack/spack-completion.bash index bd41619a09..936593d98a 100755 --- a/share/spack/spack-completion.bash +++ b/share/spack/spack-completion.bash @@ -1209,7 +1209,7 @@ _spack_license_update_copyright_year() { _spack_list() { if $list_options then - SPACK_COMPREPLY="-h --help -d --search-description --format --update -v --virtuals" + SPACK_COMPREPLY="-h --help -d --search-description --format --update -v --virtuals -t --tag" else _all_packages fi |