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")
|
targetsf := fs.String("targets", "targets.txt", "Targets file")
|
||||||
ordering := fs.String("ordering", "random", "Attack ordering [sequential, random]")
|
ordering := fs.String("ordering", "random", "Attack ordering [sequential, random]")
|
||||||
duration := fs.Duration("duration", 10*time.Second, "Duration of the test")
|
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)
|
fs.Parse(args)
|
||||||
|
|
||||||
return func() error {
|
return func() error {
|
||||||
|
|||||||
30
main.go
30
main.go
@@ -2,7 +2,9 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -10,17 +12,35 @@ import (
|
|||||||
// builds and returns
|
// builds and returns
|
||||||
type command func() error
|
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() {
|
func main() {
|
||||||
commands := map[string]func([]string) command{
|
commands := map[string]func([]string) command{
|
||||||
"attack": attackCmd,
|
"attack": attackCmd,
|
||||||
"report": reportCmd,
|
"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 {
|
if cmd, ok := commands[args[0]]; !ok {
|
||||||
log.Fatalf("Unknown command: %s", args[0])
|
log.Fatalf("Unknown command: %s", args[0])
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
func reportCmd(args []string) command {
|
func reportCmd(args []string) command {
|
||||||
fs := flag.NewFlagSet("report", flag.ExitOnError)
|
fs := flag.NewFlagSet("report", flag.ExitOnError)
|
||||||
reporter := fs.String("reporter", "text", "Reporter [text, json, plot:timings]")
|
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")
|
output := fs.String("output", "stdout", "Output file")
|
||||||
fs.Parse(args)
|
fs.Parse(args)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user