Created
October 25, 2022 19:28
-
-
Save maxsei/6214f0a3d1416a65ec12279dcf93f1ad to your computer and use it in GitHub Desktop.
list out all the local golang files that depend on a package
This file contains hidden or 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
| PKG_PATH="./path/relative/to/your/go/pkg" | |
| go list -f '{{ with $modstr := (printf "%v" $.Module) -}} | |
| {{ range $_, $dep := $.Deps -}} | |
| {{ if ne (slice (printf "%v%v" (module $dep) $modstr) 0 (len $modstr)) $modstr -}} | |
| {{ continue -}} | |
| {{ end -}} | |
| {{ println $dep -}} | |
| {{ end -}} | |
| {{ end -}} | |
| {{ .Dir -}}' $PKG_PATH | xargs -L 1 go list -f '{{ range .GoFiles -}} | |
| {{ printf "%s/%s\n" $.Dir . -}} | |
| {{ end -}}' | xargs -L 1 realpath |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment