summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
authorTodd Gamblin <gamblin2@llnl.gov>2022-12-09 10:07:54 -0800
committerGitHub <noreply@github.com>2022-12-09 10:07:54 -0800
commitd991ec90e3b5d9ec993dcde0ed99fb6539dd5e14 (patch)
tree7de3c0e6f27798d8ce314fda9a8cdd30368320c3 /share
parent8353d1539f6027c04567daa5ad82309fc5a58178 (diff)
downloadspack-d991ec90e3b5d9ec993dcde0ed99fb6539dd5e14.tar.gz
spack-d991ec90e3b5d9ec993dcde0ed99fb6539dd5e14.tar.bz2
spack-d991ec90e3b5d9ec993dcde0ed99fb6539dd5e14.tar.xz
spack-d991ec90e3b5d9ec993dcde0ed99fb6539dd5e14.zip
new command: `spack pkg grep` to search package files (#34388)
It's very common for us to tell users to grep through the existing Spack packages to find examples of what they want, and it's also very common for package developers to do it. Now, searching packages is even easier. `spack pkg grep` runs grep on all `package.py` files in repos known to Spack. It has no special options other than the search string; all options passed to it are forwarded along to `grep`. ```console > spack pkg grep --help usage: spack pkg grep [--help] ... positional arguments: grep_args arguments for grep options: --help show this help message and exit ``` ```console > spack pkg grep CMakePackage | head -3 /Users/gamblin2/src/spack/var/spack/repos/builtin/packages/3dtk/package.py:class _3dtk(CMakePackage): /Users/gamblin2/src/spack/var/spack/repos/builtin/packages/abseil-cpp/package.py:class AbseilCpp(CMakePackage): /Users/gamblin2/src/spack/var/spack/repos/builtin/packages/accfft/package.py:class Accfft(CMakePackage, CudaPackage): ``` ```console > spack pkg grep -Eho '(\S*)\(PythonPackage\)' | head -3 AwsParallelcluster(PythonPackage) Awscli(PythonPackage) Bueno(PythonPackage) ``` ## Return Value This retains the return value semantics of `grep`: * 0 for found, * 1 for not found * >1 for error ## Choosing a `grep` You can set the ``SPACK_GREP`` environment variable to choose the ``grep`` executable this command should use.
Diffstat (limited to 'share')
-rwxr-xr-xshare/spack/qa/completion-test.sh3
-rwxr-xr-xshare/spack/spack-completion.bash11
2 files changed, 12 insertions, 2 deletions
diff --git a/share/spack/qa/completion-test.sh b/share/spack/qa/completion-test.sh
index 95564e2315..e648a2ba77 100755
--- a/share/spack/qa/completion-test.sh
+++ b/share/spack/qa/completion-test.sh
@@ -42,7 +42,8 @@ do
succeeds _spack_completions "${line[@]}" ''
# Test that completion with flags works
- contains '-h --help' _spack_completions "${line[@]}" -
+ # all commands but spack pkg grep have -h; all have --help
+ contains '--help' _spack_completions "${line[@]}" -
done <<- EOF
$(spack commands --aliases --format=subcommands)
EOF
diff --git a/share/spack/spack-completion.bash b/share/spack/spack-completion.bash
index 5c90b1b5f3..604468aaeb 100755
--- a/share/spack/spack-completion.bash
+++ b/share/spack/spack-completion.bash
@@ -1450,7 +1450,7 @@ _spack_pkg() {
then
SPACK_COMPREPLY="-h --help"
else
- SPACK_COMPREPLY="add list diff added changed removed source hash"
+ SPACK_COMPREPLY="add list diff added changed removed grep source hash"
fi
}
@@ -1508,6 +1508,15 @@ _spack_pkg_removed() {
fi
}
+_spack_pkg_grep() {
+ if $list_options
+ then
+ SPACK_COMPREPLY="--help"
+ else
+ SPACK_COMPREPLY=""
+ fi
+}
+
_spack_pkg_source() {
if $list_options
then