aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWine93 <wine93.info@gmail.com>2019-04-30 03:23:20 +0000
committerWine93 <wine93.info@gmail.com>2019-04-30 03:23:20 +0000
commit6cba139458543b1d26494f96c74a23284031be6f (patch)
tree7d8dd5b21eed57cbe67f38cd67bff5f93145f862
parent32f93fb09e76cc89c14b33bb049f8427f99baa9e (diff)
downloadseaweedfs-6cba139458543b1d26494f96c74a23284031be6f.tar.xz
seaweedfs-6cba139458543b1d26494f96c74a23284031be6f.zip
util: added gostd script
-rwxr-xr-xutil/gostd98
1 files changed, 98 insertions, 0 deletions
diff --git a/util/gostd b/util/gostd
new file mode 100755
index 000000000..e9fc783d1
--- /dev/null
+++ b/util/gostd
@@ -0,0 +1,98 @@
+#!/usr/bin/env bash
+
+############################ GLOBAL VARIABLES
+regex=' '
+branch="master"
+max_length=150
+
+REGEX_SUFFIX_GO=".+\.go$"
+
+############################ FUNCTIONS
+msg() {
+ printf '%b' "$1" >&2
+}
+
+die() {
+ msg "\33[31m[✘]\33[0m ${1}${2}"
+ exit 1
+}
+
+succ() {
+ msg "\33[34m[√]\33[0m ${1}${2}"
+}
+
+gostd() {
+ local branch=$1
+ local reg4exclude=$2
+ local max_length=$3
+
+ for file in `git diff $branch --name-only`
+ do
+ if ! [[ $file =~ $REGEX_SUFFIX_GO ]] || [[ $file =~ $reg4exclude ]]; then
+ continue
+ fi
+
+ error=`go fmt $file 2>&1`
+ if ! [ $? -eq 0 ]; then
+ die "go fmt $file:" "$error"
+ fi
+
+ succ "$file\n"
+
+ grep -n -E --color=always ".{$max_length}" $file | awk '{ printf ("%4s %s\n", "", $0) }'
+ done
+}
+
+get_options() {
+ while getopts "b:e:hl:" opts
+ do
+ case $opts in
+ b)
+ branch=$OPTARG
+ ;;
+ e)
+ regex=$OPTARG
+ ;;
+ h)
+ usage
+ exit 0
+ ;;
+ l)
+ max_length=$OPTARG
+ ;;
+ \?)
+ usage
+ exit 1
+ ;;
+ esac
+ done
+}
+
+usage () {
+ cat << _EOC_
+Usage:
+ gostd [options]
+
+Options:
+ -b <branch/commit> Specify the git diff branch or commit.
+ (default: master)
+ -e <regex> Regex for excluding file or directory.
+ -h Print this usage.
+ -l <length> Show files that exceed the limit line length.
+ (default: 150)
+
+Examples:
+ gostd
+ gostd -b master -l 100
+ gostd -b 59d532a -e weed/pb -l 100
+_EOC_
+}
+
+main() {
+ get_options "$@"
+
+ gostd "$branch" "$regex" "$max_length"
+}
+
+############################ MAIN()
+main "$@"