Better Usage func

This commit is contained in:
Tomás Senart
2013-09-11 00:31:17 +01:00
parent e61ded8e5b
commit ea5764489f
3 changed files with 27 additions and 7 deletions

30
main.go
View File

@@ -2,7 +2,9 @@ package main
import (
"flag"
"fmt"
"log"
"os"
"runtime"
)
@@ -10,17 +12,35 @@ import (
// builds and returns
type command func() error
var usage = fmt.Sprintf(
`Usage: vegeta [globals] <command> [options]
Commands:
attack Hit the targets
report Report the results
Globals:
-cpus=%d Number of CPUs to use
`, runtime.NumCPU())
func init() {
flag.Usage = func() { fmt.Print(usage) }
cpus := flag.Int("cpus", runtime.NumCPU(), "Number of CPUs to use")
flag.Parse()
runtime.GOMAXPROCS(*cpus)
}
func main() {
commands := map[string]func([]string) command{
"attack": attackCmd,
"report": reportCmd,
}
// Global flags
cpus := flag.Int("cpus", runtime.NumCPU(), "Number of CPUs to use")
flag.Parse()
args := flag.Args()
runtime.GOMAXPROCS(*cpus)
args := flag.Args()
if len(args) == 0 {
flag.Usage()
os.Exit(1)
}
if cmd, ok := commands[args[0]]; !ok {
log.Fatalf("Unknown command: %s", args[0])