-
Notifications
You must be signed in to change notification settings - Fork 0
/
opts.go
72 lines (62 loc) · 1.05 KB
/
opts.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
package plugins
const (
// DefaultLogFormat ...
DefaultLogFormat = "text"
// DefaultLogLevel ...
DefaultLogLevel = "warn"
// DefaultVerbose ...
DefaultVerbose = false
// DefaultDebug ...
DefaultDebug = false
)
// Opts ...
type Opts struct {
// Verbose ...
Verbose bool
// Debug ...
Debug bool
// LogFormat ...
LogFormat string
// LogLevel ...
LogLevel string
// Invocation ...
Invocation string
// Input ...
Input string
}
// Opt ...
type Opt func(*Opts)
// DefaultOpts ...
func NewDefaultOpts() *Opts {
return &Opts{
LogFormat: DefaultLogFormat,
LogLevel: DefaultLogLevel,
Debug: DefaultDebug,
Verbose: DefaultVerbose,
}
}
// New ...
func NewOpts(opts ...Opt) *Opts {
o := NewDefaultOpts()
o.Configure(opts...)
return o
}
// Configure ...
func (s *Opts) Configure(opts ...Opt) error {
for _, o := range opts {
o(s)
}
return nil
}
// WithVerbose ...
func WithVerbose() Opt {
return func(opts *Opts) {
opts.Verbose = true
}
}
// WithDebug ...
func WithDebug() Opt {
return func(opts *Opts) {
opts.Debug = true
}
}