Skip to content

Instantly share code, notes, and snippets.

@eliasgs
Created May 11, 2016 11:23
Show Gist options
  • Save eliasgs/532b80a82ee094fa520e37654894f56f to your computer and use it in GitHub Desktop.
Save eliasgs/532b80a82ee094fa520e37654894f56f to your computer and use it in GitHub Desktop.
#!/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