-
Notifications
You must be signed in to change notification settings - Fork 0
/
format.go
62 lines (53 loc) · 1.17 KB
/
format.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
package options
type FormatOptions interface {
FormatJson() FormatOptions
FormatText() FormatOptions
FormatReadable() FormatOptions
FormatOneline() FormatOptions
FormatMessageRowLimit(row uint) FormatOptions
FormatMessageRowUnlimit() FormatOptions
apply(*controller) *controller
}
type formatOptions struct {
json bool
readable bool
msgRowsLimit int
}
func NewFormatOption() formatOptions {
return formatOptions{
json: true,
readable: true,
msgRowsLimit: -1,
}
}
func (o formatOptions) FormatJson() FormatOptions {
o.json = true
return o
}
func (o formatOptions) FormatText() FormatOptions {
o.json = false
return o
}
func (o formatOptions) FormatReadable() FormatOptions {
o.readable = true
return o
}
func (o formatOptions) FormatOneline() FormatOptions {
o.readable = false
return o
}
func (o formatOptions) FormatMessageRowLimit(row uint) FormatOptions {
o.msgRowsLimit = int(row)
return o
}
func (o formatOptions) FormatMessageRowUnlimit() FormatOptions {
o.msgRowsLimit = -1
return o
}
func (o formatOptions) apply(parent *controller) *controller {
if parent == nil {
parent = &controller{}
}
parent.format = o
return parent
}