-
Notifications
You must be signed in to change notification settings - Fork 123
/
do
executable file
·110 lines (92 loc) · 2.35 KB
/
do
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
declare -A help
binary() {
mkdir -p dist
go build -o dist/gotestsum .
}
binary-static() {
echo "building static binary: dist/gotestsum"
CGO_ENABLED=0 binary
}
update-golden() {
gotestsum -- ./... -update
}
lint() {
golangci-lint run -v --config .project/golangci-lint.yml
}
go-mod-tidy() {
go mod tidy
git diff --stat --exit-code go.mod go.sum
}
help[shell]='Run a shell in a golang docker container.
Env vars:
GOLANG_VERSION - the docker image tag used to build the image.
'
shell() {
local image; image="$(_docker-build-dev)"
docker run \
--tty --interactive --rm \
-v "$PWD:/work" \
-v ~/.cache/go-build:/root/.cache/go-build \
-v ~/go/pkg/mod:/go/pkg/mod \
-w /work \
"$image" \
"${@-bash}"
}
_docker-build-dev() {
set -e
local idfile=".plsdo/docker-build-dev-image-id-${GOLANG_VERSION-default}"
local dockerfile=.project/Dockerfile
local tag=gotest.tools/gotestsum/builder
if [ -f "$idfile" ] && [ "$dockerfile" -ot "$idfile" ]; then
cat "$idfile"
return 0
fi
mkdir -p .plsdo
>&2 docker build \
--iidfile "$idfile" \
--file "$dockerfile" \
--build-arg "UID=$UID" \
--build-arg GOLANG_VERSION \
--target "dev" \
.plsdo
cat "$idfile"
}
help[godoc]="Run godoc locally to preview package documentation."
godoc() {
local url; url="http://localhost:6060/pkg/$(go list)/"
command -v xdg-open && xdg-open "$url" &
command -v open && open "$url" &
command godoc -http=:6060
}
help[list]="Print the list of tasks"
list() {
declare -F | awk '{print $3}' | grep -v '^_'
}
_plsdo_help() {
local topic="${1-}"
# print help for the topic
if [ -n "$topic" ]; then
if ! command -v "$topic" > /dev/null ; then
>&2 echo "No such task: $topic"
return 1
fi
printf "\nUsage:\n %s %s\n\n%s\n" "$0" "$topic" "${help[$topic]-}"
return 0
fi
# print list of tasks and their help line.
[ -n "${banner-}" ] && echo "$banner" && echo
for i in $(list); do
printf "%-12s\t%s\n" "$i" "${help[$i]-}" | head -1
done
}
_plsdo_run() {
case "${1-}" in
""|help)
_plsdo_help "${2-}" ;;
*)
"$@" ;;
esac
}
_plsdo_run "$@"