Skip to content

Instantly share code, notes, and snippets.

@motemen
Created July 29, 2015 04:47
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 motemen/bb1fca4a92a29bad78dc to your computer and use it in GitHub Desktop.
Save motemen/bb1fca4a92a29bad78dc to your computer and use it in GitHub Desktop.
Poor man's vendoring script for Go
#!/bin/sh
set -e
vendor_root='_vendor'
cmd_save () {
deps="$(go list -f '{{join .Deps "\n"}}' ./...)"
go list -f '{{if (not .Standard)}}{{.ImportPath}}{{"\t"}}{{.Dir}}{{end}}' $deps | sort \
| while IFS="$(printf '\t')" read -r path dir; do
vendor_path="$vendor_root/src/$path"
if [ -d "$vendor_path" ]; then
echo "# exists $path"
else
p="$(dirname "$vendor_path")"
mkdir -p "$p"
echo "cp -R $dir $p"
cp -R "$dir" "$p"
fi
done
}
cmd_list () {
deps="$(go list -f '{{join .Deps "\n"}}' ./...)"
go list -f '{{if (not .Standard)}}{{.ImportPath}}{{end}}' $deps
}
cmd_rm () {
echo rm -rf "$vendor_root"
rm -rf "$vendor_root"
}
cmd_go () {
echo "GOPATH=\$PWD/$vendor_root:\$GOPATH"
echo "go $@"
GOPATH="$PWD/$vendor_root":$GOPATH go "$@"
}
usage () {
echo "usage: $0 {save|list|rm|go}" >&2
exit 1
}
cmd="$1"
shift || usage
case "$cmd" in
save)
cmd_save
;;
list)
cmd_list
;;
rm)
cmd_rm
;;
go)
cmd_go "$@"
;;
*)
usage
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment