Skip to content

Commit

Permalink
Remove need of --config, add --no-spinner option
Browse files Browse the repository at this point in the history
  • Loading branch information
eripa authored and Eric Ripa committed May 26, 2016
1 parent d6ff465 commit 7f78eca
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
31 changes: 18 additions & 13 deletions ba_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/mkideal/cli"
)

const toolVersion = "0.5"
const toolVersion = "0.6"

var (
anyLookUpfailed bool
Expand Down Expand Up @@ -47,8 +47,9 @@ func (a endpointSorter) Less(i, j int) bool { return a[i].Endpoint < a[j].Endpoi

type argT struct {
cli.Helper
Config string `cli:"c,config" usage:"JSON config file, see config-example.json"`
Version bool `cli:"version" usage:"Check version"`
Config string `cli:"c,config" usage:"JSON config file, see config-example.json"`
NoSpinner bool `cli:"no-spinner" usage:"Disable spinner animation for cleaner output"`
Version bool `cli:"version" usage:"Check version"`
}

func getMaxWidth(sites []site) (width int) {
Expand All @@ -71,7 +72,7 @@ func numberOfTotalEndpoints(sites []site) (count int) {
return count
}

func checkSites(sites []site) {
func checkSites(sites []site, nospinner bool) {
amountOfEndpoints := numberOfTotalEndpoints(sites)
endpointChan := make(chan *endpoint, amountOfEndpoints)
endpointDone := make(chan bool, amountOfEndpoints)
Expand All @@ -83,8 +84,10 @@ func checkSites(sites []site) {

maxWidth := getMaxWidth(sites)
s := spinner.New(spinner.CharSets[7], 100*time.Millisecond)
s.Prefix = "running tests"
s.Start()
if !nospinner {
s.Prefix = "running tests"
s.Start()
}

for i := range sites {
checkSite(&sites[i], endpointChan)
Expand All @@ -93,7 +96,9 @@ func checkSites(sites []site) {
for i := 0; i < amountOfEndpoints; i++ {
<-endpointDone // wait for one task to complete
}
s.Stop()
if !nospinner {
s.Stop()
}
for _, site := range sites {
printResults(site, maxWidth)
}
Expand Down Expand Up @@ -177,20 +182,20 @@ func main() {
ctx.String("ba_checker v%s\n", toolVersion)
return nil
}
if argv.Config == "" {
return fmt.Errorf("--config <config.json> is required.\n")
if len(os.Args) < 2 {
return fmt.Errorf("<config.json> is required.\n")
}
if _, err := os.Stat(argv.Config); os.IsNotExist(err) {
return fmt.Errorf("Error: %s does not exist", argv.Config)
if _, err := os.Stat(os.Args[1]); os.IsNotExist(err) {
return fmt.Errorf("Error: %s does not exist", os.Args[1])
}
file, _ := os.Open(argv.Config)
file, _ := os.Open(os.Args[1])
decoder := json.NewDecoder(file)
config := configuration{}
err := decoder.Decode(&config)
if err != nil {
fmt.Println("error:", err)
}
checkSites(config.Sites)
checkSites(config.Sites, argv.NoSpinner)
if anyLookUpfailed {
os.Exit(1)
}
Expand Down
29 changes: 15 additions & 14 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,25 @@ export CGO_ENABLED=0
# Build
declare -a TARGETS=(darwin linux freebsd)
export GOARCH=amd64
VERSION=$(git describe --abbrev=0 --tags 2> /dev/null) # this doesn't actually seem to work
# Create a tar-ball for release
if [ "$?" -ne 0 ] ; then
# No tag, use commit hash
HASH=$(git rev-parse HEAD)
VERSION=${HASH:0:7}
fi

for target in "${TARGETS[@]}" ; do
output="${DIR_NAME}-${target}"
output="${DIR_NAME}"
echo "Building for ${target}, output bin/${output}"
export GOOS=${target}
export GOARCH=amd64
go build -o "bin/${output}"
(
cd ..
TARBALL="${DIR_NAME}-${VERSION}-${target}-${GOARCH}.tar.gz"
tar -cf "${TARBALL}" --exclude=.git -z "${DIR_NAME}"
echo "Created: ${PWD}/${TARBALL}"
)
rm -rf "bin/${output}"
done

# Create a tar-ball for release
VERSION=$(git describe --abbrev=0 --tags 2> /dev/null) # this doesn't actually seem to work
if [ "$?" -ne 0 ] ; then
# No tag, use commit hash
HASH=$(git rev-parse HEAD)
VERSION=${HASH:0:7}
fi

cd ../
TARBALL="${DIR_NAME}-${VERSION}.tar.gz"
tar -cf "${TARBALL}" --exclude=.git -vz "${DIR_NAME}"
echo "Created: ${PWD}/${TARBALL}"

0 comments on commit 7f78eca

Please sign in to comment.