aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Paris <[email protected]>2015-09-23 15:37:00 -0400
committerEric Paris <[email protected]>2015-09-23 16:19:34 -0400
commitb02994d092faae574c4b87f516f6d7928f739da2 (patch)
tree014098de374523548d92dd8173d155b60d0a2f6a
parent5a13a75b13d132dc7d07dd19fd260257cd9c0290 (diff)
Add more CI checks forcing code cleanliness
-rw-r--r--.travis.yml9
-rw-r--r--flag.go8
-rw-r--r--golangflag.go3
-rwxr-xr-xverify/all.sh69
-rwxr-xr-xverify/gofmt.sh19
-rwxr-xr-xverify/golint.sh15
6 files changed, 119 insertions, 4 deletions
diff --git a/.travis.yml b/.travis.yml
index c4d88e3..c40fb69 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,3 +6,12 @@ go:
- 1.3
- 1.4
- tip
+
+install:
+ - go get github.com/golang/lint/golint
+ - export PATH=$GOPATH/bin:$PATH
+ - go install ./...
+
+script:
+ - verify/all.sh
+ - go test ./...
diff --git a/flag.go b/flag.go
index 57d9339..fd91440 100644
--- a/flag.go
+++ b/flag.go
@@ -315,9 +315,9 @@ func (f *FlagSet) MarkDeprecated(name string, usageMessage string) error {
return nil
}
-// Mark the shorthand of a flag deprecated in your program. It will
-// continue to function but will not show up in help or usage messages. Using
-// this flag will also print the given usageMessage.
+// MarkShorthandDeprecated will mark the shorthand of a flag deprecated in your
+// program. It will continue to function but will not show up in help or usage
+// messages. Using this flag will also print the given usageMessage.
func (f *FlagSet) MarkShorthandDeprecated(name string, usageMessage string) error {
flag := f.Lookup(name)
if flag == nil {
@@ -821,7 +821,7 @@ func NewFlagSet(name string, errorHandling ErrorHandling) *FlagSet {
return f
}
-// SetIntersperesed sets whether to support interspersed option/non-option arguments.
+// SetInterspersed sets whether to support interspersed option/non-option arguments.
func (f *FlagSet) SetInterspersed(interspersed bool) {
f.interspersed = interspersed
}
diff --git a/golangflag.go b/golangflag.go
index 5213dc3..a8c24ef 100644
--- a/golangflag.go
+++ b/golangflag.go
@@ -60,6 +60,7 @@ func (v *flagValueWrapper) Type() string {
return v.flagType
}
+// PFlagFromGoFlag will return a *pflag.Flag given a *flag.Flag
func PFlagFromGoFlag(goflag *goflag.Flag) *Flag {
// Remember the default value as a string; it won't change.
flag := &Flag{
@@ -76,6 +77,7 @@ func PFlagFromGoFlag(goflag *goflag.Flag) *Flag {
return flag
}
+// AddGoFlag will add the given *flag.Flag to the pflag.FlagSet
func (f *FlagSet) AddGoFlag(goflag *goflag.Flag) {
if f.Lookup(goflag.Name) != nil {
return
@@ -84,6 +86,7 @@ func (f *FlagSet) AddGoFlag(goflag *goflag.Flag) {
f.AddFlag(newflag)
}
+// AddGoFlagSet will add the given *flag.FlagSet to the pflag.FlagSet
func (f *FlagSet) AddGoFlagSet(newSet *goflag.FlagSet) {
if newSet == nil {
return
diff --git a/verify/all.sh b/verify/all.sh
new file mode 100755
index 0000000..739f89c
--- /dev/null
+++ b/verify/all.sh
@@ -0,0 +1,69 @@
+#!/bin/bash
+
+set -o errexit
+set -o nounset
+set -o pipefail
+
+ROOT=$(dirname "${BASH_SOURCE}")/..
+
+# Some useful colors.
+if [[ -z "${color_start-}" ]]; then
+ declare -r color_start="\033["
+ declare -r color_red="${color_start}0;31m"
+ declare -r color_yellow="${color_start}0;33m"
+ declare -r color_green="${color_start}0;32m"
+ declare -r color_norm="${color_start}0m"
+fi
+
+SILENT=true
+
+function is-excluded {
+ for e in $EXCLUDE; do
+ if [[ $1 -ef ${BASH_SOURCE} ]]; then
+ return
+ fi
+ if [[ $1 -ef "$ROOT/hack/$e" ]]; then
+ return
+ fi
+ done
+ return 1
+}
+
+while getopts ":v" opt; do
+ case $opt in
+ v)
+ SILENT=false
+ ;;
+ \?)
+ echo "Invalid flag: -$OPTARG" >&2
+ exit 1
+ ;;
+ esac
+done
+
+if $SILENT ; then
+ echo "Running in the silent mode, run with -v if you want to see script logs."
+fi
+
+EXCLUDE="all.sh"
+
+ret=0
+for t in `ls $ROOT/verify/*.sh`
+do
+ if is-excluded $t ; then
+ echo "Skipping $t"
+ continue
+ fi
+ if $SILENT ; then
+ echo -e "Verifying $t"
+ if bash "$t" &> /dev/null; then
+ echo -e "${color_green}SUCCESS${color_norm}"
+ else
+ echo -e "${color_red}FAILED${color_norm}"
+ ret=1
+ fi
+ else
+ bash "$t" || ret=1
+ fi
+done
+exit $ret
diff --git a/verify/gofmt.sh b/verify/gofmt.sh
new file mode 100755
index 0000000..f66acf8
--- /dev/null
+++ b/verify/gofmt.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+set -o errexit
+set -o nounset
+set -o pipefail
+
+ROOT=$(dirname "${BASH_SOURCE}")/..
+
+pushd "${ROOT}" > /dev/null
+
+GOFMT=${GOFMT:-"gofmt"}
+bad_files=$(find . -name '*.go' | xargs $GOFMT -s -l)
+if [[ -n "${bad_files}" ]]; then
+ echo "!!! '$GOFMT' needs to be run on the following files: "
+ echo "${bad_files}"
+ exit 1
+fi
+
+# ex: ts=2 sw=2 et filetype=sh
diff --git a/verify/golint.sh b/verify/golint.sh
new file mode 100755
index 0000000..685c177
--- /dev/null
+++ b/verify/golint.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+ROOT=$(dirname "${BASH_SOURCE}")/..
+GOLINT=${GOLINT:-"golint"}
+
+pushd "${ROOT}" > /dev/null
+ bad_files=$($GOLINT -min_confidence=0.9 ./...)
+ if [[ -n "${bad_files}" ]]; then
+ echo "!!! '$GOLINT' problems: "
+ echo "${bad_files}"
+ exit 1
+ fi
+popd > /dev/null
+
+# ex: ts=2 sw=2 et filetype=sh