forked from istio/istio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fmt.sh
executable file
·38 lines (29 loc) · 884 Bytes
/
fmt.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
#!/bin/bash
# Applies requisite code formatters to the source tree
set -e
SCRIPTPATH=$( cd "$(dirname "$0")" ; pwd -P )
ROOTDIR=$SCRIPTPATH/..
cd $ROOTDIR
export GOPATH=$(cd $ROOTDIR/../../..; pwd)
export PATH=$GOPATH/bin:$PATH
if which goimports; then
goimports=`which goimports`
else
go get golang.org/x/tools/cmd/goimports
goimports=${GOPATH}/bin/goimports
fi
PKGS=${PKGS:-"."}
if [[ -z ${GO_FILES} ]];then
GO_FILES=$(find ${PKGS} -type f -name '*.go' ! -name '*.gen.go' ! -name '*.pb.go' ! -name '*mock*.go' | grep -v ./vendor)
fi
UX=$(uname)
#remove blank lines so gofmt / goimports can do their job
for fl in ${GO_FILES}; do
if [[ ${UX} == "Darwin" ]];then
sed -i '' -e "/^import[[:space:]]*(/,/)/{ /^\s*$/d;}" $fl
else
sed -i -e "/^import[[:space:]]*(/,/)/{ /^\s*$/d;}" $fl
fi
done
gofmt -s -w ${GO_FILES}
$goimports -w -local istio.io ${GO_FILES}