forked from TekWizely/pre-commit-golang
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgo-lint.sh
More file actions
executable file
·47 lines (41 loc) · 848 Bytes
/
go-lint.sh
File metadata and controls
executable file
·47 lines (41 loc) · 848 Bytes
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
#!/usr/bin/env bash
cmd=(golint -set_exit_status)
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 file in "${FILES[@]}"; do
"${cmd[@]}" "${OPTIONS[@]}" "${file}"
if [ $? -ne 0 ]; then
errCode=1
fi
done
exit $errCode