forked from TekWizely/pre-commit-golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
go-returns.sh
executable file
·49 lines (43 loc) · 905 Bytes
/
go-returns.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=(goreturns -l -d)
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
output=$("${cmd[@]}" "${OPTIONS[@]}" "${file}" 2>&1)
if [ ! -z "${output}" ]; then
echo -n "${output}"
echo "" # newline
errCode=1
fi
done
exit $errCode