forked from raviqqe/muffet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arguments.go
44 lines (32 loc) · 824 Bytes
/
arguments.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"os"
"strconv"
"github.com/docopt/docopt-go"
)
const usage = `Muffet, the web repairgirl
Usage:
muffet [-c <concurrency>] [-v] <url>
Options:
-c, --concurrency <concurrency> Roughly maximum number of concurrent HTTP connections. [default: 512]
-h, --help Show this help.
-v, --verbose Show successful results too.`
type arguments struct {
concurrency int
url string
verbose bool
}
func getArguments(ss []string) (arguments, error) {
if ss == nil {
ss = os.Args[1:]
}
args, err := docopt.ParseArgs(usage, ss, "0.1.0")
if err != nil {
return arguments{}, err
}
c, err := strconv.ParseInt(args["--concurrency"].(string), 10, 32)
if err != nil {
return arguments{}, err
}
return arguments{int(c), args["<url>"].(string), args["--verbose"].(bool)}, nil
}