Better Usage func
This commit is contained in:
@@ -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 {
|
||||
|
||||
30
main.go
30
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] <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])
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user