Created
May 1, 2024 21:35
-
-
Save renier/0beddc56dff9cd27be434200efe7fe6a to your computer and use it in GitHub Desktop.
Lists out the dependencies importing the module you specify all the way up to the project's main module
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/bash | |
home_module="$(go list -m | head -1)" | |
cache="$(mktemp)" | |
gomodule="go@$(go version | cut -d ' ' -f 3 | sed -e 's/^go//' | cut -d '.' -f 1,2)" | |
function explain() { | |
local importers="$(go mod graph | grep " ${1}" | cut -d ' ' -f 1)" | |
local importer; | |
for importer in $importers; do | |
if [[ $importer =~ "$home_module" ]]; then | |
continue | |
fi | |
if [ "$importer" = "$gomodule" ]; then | |
continue | |
fi | |
if grep "$importer" $cache > /dev/null; then | |
continue | |
fi | |
echo "$importer" | tee -a $cache | |
explain "$importer" | |
done | |
} | |
explain "$1" | |
echo "$home_module" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment