-
Notifications
You must be signed in to change notification settings - Fork 1
/
usage.go
149 lines (134 loc) · 5.9 KB
/
usage.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package main
import (
"fmt"
"os"
"time"
docopt "github.com/docopt/docopt-go"
"github.com/mitchellh/mapstructure"
"github.com/FuzzyMonkeyCo/monkey/pkg/as"
"github.com/FuzzyMonkeyCo/monkey/pkg/code"
)
type params struct {
Env, Fmt, Fuzz, Lint, Logs, Schema bool
Pastseed bool
Update, Version bool
Exec, Start, Reset, Stop, Repl bool
FmtW bool `mapstructure:"-w"`
ShowSpec bool `mapstructure:"--show-spec"`
Seed []byte `mapstructure:"--seed"`
EnvVars []string `mapstructure:"VAR"`
Labels []string `mapstructure:"--label"`
N uint32 `mapstructure:"--intensity"`
Verbosity uint8 `mapstructure:"-v"`
LogOffset uint64 `mapstructure:"--previous"`
File string `mapstructure:"--file"`
Progress string `mapstructure:"--progress"`
ValidateAgainst string `mapstructure:"--validate-against"`
Tags *string `mapstructure:"--tags"`
TagsExcluded *string `mapstructure:"--exclude-tags"`
OverallBudgetTime time.Duration `mapstructure:"--time-budget-overall"`
}
func usage() (args *params, ret int) {
B := as.ColorNFO.Sprintf(binName)
// TODO: B [-vvv] init [--with-magic] Auto fill-in schemas from random API calls
// TODO: B [-vvv] login [--user=USER] Authenticate on fuzzymonkey.co as USER
// TODO: B [-vvv] exec (start | reset | stop) [RESETTER]
// TODO: B [-vvv] schema [--validate-against=REF] [MODELER]
// TODO: B [-vvv] docs
// TODO: separate repl from exec ...
usage := binTitle + `
Usage:
` + B + ` [-vvv] env [VAR ...]
` + B + ` [-vvv] [-f STAR] fmt [-w]
` + B + ` [-vvv] [-f STAR] lint [--show-spec]
` + B + ` [-vvv] [-f STAR] exec (repl | start | reset | stop)
` + B + ` [-vvv] [-f STAR] schema [--validate-against=REF]
` + B + ` [-vvv] [-f STAR] fuzz [--intensity=N] [--seed=SEED]
[--label=KV]...
[--tags=TAGS | --exclude-tags=TAGS]
[--no-shrinking]
[--progress=PROGRESS]
[--time-budget-overall=DURATION]
[--only=REGEX]... [--except=REGEX]...
[--calls-with-input=SCHEMA]... [--calls-without-input=SCHEMA]...
[--calls-with-output=SCHEMA]... [--calls-without-output=SCHEMA]...
` + B + ` [-f STAR] pastseed
` + B + ` [-f STAR] logs [--previous=N]
` + B + ` [-vvv] update
` + B + ` version | --version
` + B + ` help | --help | -h
` +
// From http://docopt.org/
// Note, writing --input ARG (as opposed to --input=ARG) is ambiguous, meaning it is not
// possible to tell whether ARG is option's argument or a positional argument. In usage patterns this
// will be interpreted as an option with argument only if a description (covered below) for that option
// is provided. Otherwise it will be interpreted as an option and separate positional argument.
`
Options:
-v, -vv, -vvv Debug verbosity level
-f STAR, --file=STAR Name of the fuzzymonkey.star file
version Show the version string
update Ensures ` + B + ` is the latest version
--intensity=N The higher the more complex the tests [default: 10]
--time-budget-overall=DURATION Stop testing after DURATION (e.g. '30s' or '5h')
--seed=SEED Use specific parameters for the Random Number Generator
--label=KV Labels that can help classification (format: key=value)
--tags=TAGS Only run checks whose tags match at least one of these (comma separated)
--exclude-tags=TAGS Skip running checks whose tags match at least one of these (comma separated)
--progress=PROGRESS dots, bar, ci (defaults: dots)
--only=REGEX Only test matching calls
--except=REGEX Do not test these calls
--calls-with-input=SCHEMA Test calls which can take schema PTR as input
--calls-without-output=SCHEMA Test calls which never output schema PTR
--validate-against=REF Validate STDIN payload against given schema $ref
--previous=N Select logs from Nth previous run [default: 1]
Try:
export FUZZYMONKEY_API_KEY=fm_42
export FUZZYMONKEY_SSL_NO_VERIFY=1
` + B + ` update
` + B + ` -f fm.star exec reset
` + B + ` fuzz --only /pets --calls-without-input=NewPet --seed=$(monkey pastseed)
echo '"kitty"' | ` + B + ` schema --validate-against=#/components/schemas/PetKind`
opts, err := docopt.ParseDoc(usage)
if err != nil {
// Usage shown: bad args
as.ColorERR.Println(err)
ret = code.Failed
return
}
if opts["help"].(bool) {
fmt.Println(usage)
ret = code.OK
return
}
args = ¶ms{}
cfg := &mapstructure.DecoderConfig{
Result: &args,
WeaklyTypedInput: true,
DecodeHook: mapstructure.ComposeDecodeHookFunc(
mapstructure.StringToTimeDurationHookFunc(),
),
}
d, err := mapstructure.NewDecoder(cfg)
if err != nil {
as.ColorERR.Println(err)
return nil, code.Failed
}
if err := d.Decode(opts); err != nil {
as.ColorERR.Println(err)
return nil, code.Failed
}
if opts["--version"].(bool) {
args.Version = true
}
if args.File == "" {
for _, arg := range os.Args {
if arg == "--file" || arg == "-f" {
as.ColorERR.Println("Given argument --file is missing STAR path parameter")
return nil, code.Failed
}
}
args.File = "fuzzymonkey.star"
}
return
}