forked from TekWizely/pre-commit-golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
go-vet-pkg.sh
executable file
·49 lines (42 loc) · 893 Bytes
/
go-vet-pkg.sh
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
#!/usr/bin/env bash
cmd=(go vet)
export GO111MODULE=off
OPTIONS=()
# If arg doesn't pass [ -f ] check, then it is assumed to be an option
#
while [ $# -gt 0 ] && [ "$1" != "-" ] && [ "$1" != "--" ] && [ ! -f "$1" ]; do
OPTIONS+=("$1")
shift
done
FILES=()
# Assume start of file list (may still be options)
#
while [ $# -gt 0 ] && [ "$1" != "-" ] && [ "$1" != "--" ]; do
FILES+=("$1")
shift
done
# If '--' next, then files = options
#
if [ $# -gt 0 ]; then
if [ "$1" == "-" ] || [ "$1" == "--" ]; then
shift
# Append to previous options
#
OPTIONS=("${OPTIONS[@]}" "${FILES[@]}")
FILES=()
fi
fi
# Any remaining arguments are assumed to be files
#
while [ $# -gt 0 ]; do
FILES+=("$1")
shift
done
errCode=0
for sub in $(echo "${FILES[@]}" | xargs -n1 dirname | sort -u); do
"${cmd[@]}" "${OPTIONS[@]}" "./${sub}"
if [ $? -ne 0 ]; then
errCode=1
fi
done
exit $errCode