Created
May 11, 2016 11:23
-
-
Save eliasgs/532b80a82ee094fa520e37654894f56f 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/bash | |
usage () { | |
cat <<-EOF | |
Usage: ${0##*/} (<command> [<args>...] | -h | --help) | |
Manage external golang dependencies. | |
Options: | |
-h, --help Show this help message. | |
Commands: | |
list [<package>] List external dependencies of package. | |
save Add external dependency as git submodule in ./vendor | |
directory. | |
EOF | |
} | |
deps () { | |
go list -f '{{join .Imports "\n"}}' $1 \ | |
| xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}'; | |
} | |
save () { | |
for dep in $(deps); do | |
read -r -p "Add vendor $dep? [y/N] " response | |
response=$(echo $response | awk '{print tolower($0)}') | |
if [[ $response =~ ^(yes|y)$ ]]; then | |
git submodule add https://$dep vendor/$dep | |
fi | |
done | |
} | |
case $1 in | |
save) save;; | |
list) deps $2;; | |
-h|--help) usage && exit 0;; | |
*) usage && exit 1;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment