diff --git a/attack.go b/attack.go index bceabb7..b9de6ba 100644 --- a/attack.go +++ b/attack.go @@ -16,7 +16,7 @@ func attackCmd(args []string) command { targetsf := fs.String("targets", "targets.txt", "Targets file") ordering := fs.String("ordering", "random", "Attack ordering [sequential, random]") duration := fs.Duration("duration", 10*time.Second, "Duration of the test") - output := fs.String("output", "stdout", "Vegeta Results file") + output := fs.String("output", "stdout", "Vegeta data file") fs.Parse(args) return func() error { diff --git a/main.go b/main.go index bd73933..7184bb2 100644 --- a/main.go +++ b/main.go @@ -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] [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]) diff --git a/report.go b/report.go index 69bf5e4..efa953c 100644 --- a/report.go +++ b/report.go @@ -11,7 +11,7 @@ import ( func reportCmd(args []string) command { fs := flag.NewFlagSet("report", flag.ExitOnError) reporter := fs.String("reporter", "text", "Reporter [text, json, plot:timings]") - input := fs.String("input", "stdin", "Vegeta Results file") + input := fs.String("input", "stdin", "Vegeta data file") output := fs.String("output", "stdout", "Output file") fs.Parse(args)