Last active
February 7, 2020 06:02
-
-
Save lufia/5fb563a037d9b39a4743594e3aba626d to your computer and use it in GitHub Desktop.
参照パッケージを列挙するコマンド
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -eu | |
list_pkgs() | |
{ | |
local f | |
f=$(cat <<-'END' | |
{{range .Imports}}{{.}} | |
{{end}} | |
END | |
) | |
go list -f "$f" "$@" | | |
sort -u | | |
awk -F/ '/\./' | |
} | |
if [[ $# = 0 ]] | |
then | |
echo "usage: $(basename $0) pattern [path ...]" >&2 | |
exit 2 | |
fi | |
pattern="$1" | |
shift | |
for i in "$@" | |
do | |
echo searching $i >&2 | |
pkgs=$(list_pkgs "$i") | |
for pkg in $pkgs | |
do | |
if [[ $pkg =~ $pattern ]] | |
then | |
echo $pattern $i | |
fi | |
done | |
sh $0 "$pattern" $pkgs | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment