Skip to content
This repository was archived by the owner on Aug 17, 2020. It is now read-only.

Commit e1d42dc

Browse files
Use a different flag parser for “nicer” flags
1 parent de56e6e commit e1d42dc

File tree

3 files changed

+43
-40
lines changed

3 files changed

+43
-40
lines changed

README.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,24 @@ Goad will read your credentials from `~/.aws/credentials` or from the `AWS_ACCES
6262

6363
```sh
6464
# Get help:
65-
$ goad -h
66-
Usage of goad:
67-
-c uint
68-
number of concurrent requests (default 10)
69-
-m string
70-
HTTP method (default "GET")
71-
-n uint
72-
number of total requests to make (default 1000)
73-
-r string
74-
AWS regions to run in (comma separated, no spaces) (default "us-east-1")
75-
-t uint
76-
request timeout in seconds (default 15)
77-
-u string
78-
URL to load test (required)
79-
-H string
80-
HTTP Header to add to the request. This option can be set multiple times.
65+
$ goad --help
66+
usage: goad --url=URL [<flags>]
67+
68+
A command-line chat application.
69+
70+
Flags:
71+
-h, --help Show context-sensitive help (also try --help-long and --help-man).
72+
-u, --url=URL URL to load test
73+
-m, --method="GET" HTTP method
74+
-b, --body=BODY HTTP request body
75+
-c, --concurrency=10 Number of concurrent requests
76+
-n, --requests=10 Total number of requests to make
77+
-t, --timeout=15 Request timeout in seconds
78+
-r, --regions="us-east-1,eu-west-1,ap-northeast-1"
79+
AWS regions to run in (comma separated, no spaces)
80+
-p, --aws-profile=AWS-PROFILE AWS named profile to use
81+
-H, --headers=HEADERS ... List of headers
82+
--version Show application version.
8183

8284
# For example:
8385
$ goad -n 1000 -c 5 -u https://example.com

cli/cli.go

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"flag"
54
"fmt"
65
"os"
76
"os/signal"
@@ -11,6 +10,8 @@ import (
1110
"syscall"
1211
"time"
1312

13+
"gopkg.in/alecthomas/kingpin.v2"
14+
1415
"github.com/dustin/go-humanize"
1516
"github.com/goadapp/goad"
1617
"github.com/goadapp/goad/helpers"
@@ -20,6 +21,7 @@ import (
2021
)
2122

2223
var (
24+
app = kingpin.New("goad", "A command-line chat application.")
2325
url string
2426
concurrency uint
2527
requests uint
@@ -34,30 +36,24 @@ var (
3436
const coldef = termbox.ColorDefault
3537
const nano = 1000000000
3638

37-
func main() {
38-
var printVersion bool
39-
40-
flag.StringVar(&url, "u", "", "URL to load test (required)")
41-
flag.StringVar(&method, "m", "GET", "HTTP method")
42-
flag.StringVar(&body, "b", "", "HTTP request body")
43-
flag.UintVar(&concurrency, "c", 10, "number of concurrent requests")
44-
flag.UintVar(&requests, "n", 1000, "number of total requests to make")
45-
flag.UintVar(&timeout, "t", 15, "request timeout in seconds")
46-
flag.StringVar(&regions, "r", "us-east-1,eu-west-1,ap-northeast-1", "AWS regions to run in (comma separated, no spaces)")
47-
flag.StringVar(&awsProfile, "p", "", "AWS named profile to use")
48-
flag.Var(&headers, "H", "List of headers")
49-
flag.BoolVar(&printVersion, "version", false, "print the current Goad version")
50-
flag.Parse()
51-
52-
if printVersion {
53-
fmt.Println(version.Version)
54-
os.Exit(0)
55-
}
39+
func init() {
40+
app.HelpFlag.Short('h')
5641

57-
if url == "" {
58-
flag.Usage()
59-
os.Exit(0)
60-
}
42+
url = *app.Flag("url", "URL to load test").Short('u').Required().String()
43+
method = *app.Flag("method", "HTTP method").Short('m').Default("GET").String()
44+
body = *app.Flag("body", "HTTP request body").Short('b').String()
45+
concurrency = *app.Flag("concurrency", "Number of concurrent requests").Short('c').Default("10").Uint()
46+
requests = *app.Flag("requests", "Total number of requests to make").Short('n').Default("10").Uint()
47+
timeout = *app.Flag("timeout", "Request timeout in seconds").Short('t').Default("15").Uint()
48+
regions = *app.Flag("regions", "AWS regions to run in (comma separated, no spaces)").Short('r').Default("us-east-1,eu-west-1,ap-northeast-1").String()
49+
awsProfile = *app.Flag("aws-profile", "AWS named profile to use").Short('p').String()
50+
app.Flag("headers", "List of headers").Short('H').SetValue(&headers)
51+
52+
app.Version(version.Version)
53+
}
54+
55+
func main() {
56+
kingpin.MustParse(app.Parse(os.Args[1:]))
6157

6258
test, testerr := goad.NewTest(&goad.TestConfig{
6359
URL: url,

helpers/stringsliceflag.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ func (s *StringsliceFlag) Set(value string) error {
1414
*s = append(*s, value)
1515
return nil
1616
}
17+
18+
// IsCumulative indicates to Kingpin that the flag is repeatable
19+
func (s *StringsliceFlag) IsCumulative() bool {
20+
return true
21+
}

0 commit comments

Comments
 (0)