-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
46 lines (39 loc) · 1.38 KB
/
options.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
package qube
import (
"fmt"
"os"
"time"
"github.com/go-sql-driver/mysql"
"github.com/jackc/pgx/v5"
"github.com/mattn/go-isatty"
)
type Options struct {
AgentOptions
DataOptions
DBConfig
Nagents uint64 `kong:"short='n',default='1',help='Number of agents.'"`
Rate float64 `kong:"short='r',help='Rate limit (qps). \"0\" means unlimited.'"`
Time time.Duration `json:"-" kong:"short='t',help='Maximum execution time of the test. \"0\" means unlimited.'"`
X_Time JSONDuration `json:"Time" kong:"-"` // for report
Progress bool `json:"-" kong:"negatable,help='Show progress report.'"`
Color bool `json:"-" kong:"negatable,short='C',help='Color report JSON.'"`
}
// Kong hook
// see https://github.com/alecthomas/kong#hooks-beforereset-beforeresolve-beforeapply-afterapply-and-the-bind-option
func (options *Options) BeforeApply() error {
options.Color = isatty.IsTerminal(os.Stdout.Fd())
return nil
}
func (options *Options) AfterApply() error {
options.X_Time = JSONDuration(options.Time)
options.NullDBOut = os.Stderr
options.Progress = isatty.IsTerminal(os.Stderr.Fd())
if _, err := mysql.ParseDSN(options.DSN); err == nil {
options.Driver = DBDriverMySQL
} else if _, err := pgx.ParseConfig(options.DSN); err == nil {
options.Driver = DBDriverPostgreSQL
} else {
return fmt.Errorf("cannot parse DSN - %s", options.DSN)
}
return nil
}