Skip to content

Instantly share code, notes, and snippets.

@lufia
Last active February 7, 2020 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lufia/5fb563a037d9b39a4743594e3aba626d to your computer and use it in GitHub Desktop.
Save lufia/5fb563a037d9b39a4743594e3aba626d to your computer and use it in GitHub Desktop.
参照パッケージを列挙するコマンド
#!/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