Abstract command building and setup with closures

This commit is contained in:
Tomás Senart
2013-09-11 00:10:35 +01:00
parent 4bbc7a0296
commit e61ded8e5b
3 changed files with 54 additions and 44 deletions

View File

@@ -1,12 +1,27 @@
package main
import (
"flag"
vegeta "github.com/tsenart/vegeta/lib"
"io"
"log"
"os"
)
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")
output := fs.String("output", "stdout", "Output file")
fs.Parse(args)
return func() error {
return report(*reporter, *input, *output)
}
}
// report validates the report arguments, sets up the required resources
// and writes the report
func report(reporter, input, output string) error {
var rep vegeta.Reporter
switch reporter {