-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
193 lines (155 loc) · 3.53 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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package hledger
import "fmt"
type Options struct {
account string
accountType string
accountDepth int
accountDrop int
startDate string
endDate string
outputCSV bool
layout LayoutType
sortAmount bool
invertAmount bool
period PeriodType
pretty bool
description string
average bool
tree bool
valuation bool
percent bool
}
type (
LayoutType string
PeriodType string
)
const (
LayoutBare LayoutType = "bare"
PeriodDaily PeriodType = "--daily"
PeriodWeekly PeriodType = "--weekly"
PeriodMonthly PeriodType = "--monthly"
PeriodQuarterly PeriodType = "--quarterly"
PeriodYearly PeriodType = "--yearly"
)
func NewOptions() Options { return Options{} }
func (o Options) WithAverage(average bool) Options {
o.average = average
return o
}
func (o Options) WithDescription(description string) Options {
o.description = description
return o
}
func (o Options) WithPretty(pretty bool) Options {
o.pretty = pretty
return o
}
func (o Options) WithAccount(account string) Options {
o.account = account
return o
}
func (o Options) WithAccountType(accountType string) Options {
o.accountType = accountType
return o
}
func (o Options) WithAccountDepth(depth int) Options {
o.accountDepth = depth
return o
}
func (o Options) WithAccountDrop(drop int) Options {
o.accountDrop = drop
return o
}
func (o Options) WithStartDate(startDate string) Options {
o.startDate = startDate
return o
}
func (o Options) WithEndDate(endDate string) Options {
o.endDate = endDate
return o
}
func (o Options) WithOutputCSV(outputCSV bool) Options {
o.outputCSV = outputCSV
return o
}
func (o Options) WithLayout(layout LayoutType) Options {
o.layout = layout
return o
}
func (o Options) WithSortAmount(sortAmount bool) Options {
o.sortAmount = sortAmount
return o
}
func (o Options) WithInvertAmount(invertAmount bool) Options {
o.invertAmount = invertAmount
return o
}
func (o Options) WithPeriod(period PeriodType) Options {
o.period = period
return o
}
func (o Options) WithTree(tree bool) Options {
o.tree = tree
return o
}
func (o Options) WithValuation(valuation bool) Options {
o.valuation = valuation
return o
}
func (o Options) WithPercent(percent bool) Options {
o.percent = percent
return o
}
func (o Options) Build() []string {
var options []string
if o.account != "" {
options = append(options, "acct:"+o.account)
}
if o.accountType != "" {
options = append(options, "type:"+o.accountType)
}
if o.accountDepth > 0 {
options = append(options, fmt.Sprintf("--depth=%d", o.accountDepth))
}
if o.accountDrop > 0 {
options = append(options, fmt.Sprintf("--drop=%d", o.accountDrop))
}
if o.startDate != "" || o.endDate != "" {
date := fmt.Sprintf("%s..%s", o.startDate, o.endDate)
options = append(options, "date:"+date)
}
if o.layout != "" {
options = append(options, "--layout", string(o.layout))
}
if o.sortAmount {
options = append(options, "--sort-amount")
}
if o.invertAmount {
options = append(options, "--invert")
}
if o.period != "" {
options = append(options, string(o.period))
}
if o.pretty {
options = append(options, "--pretty")
}
if o.description != "" {
options = append(options, "desc:"+o.description)
}
if o.average {
options = append(options, "--average")
}
if o.outputCSV {
options = append(options, "-O", "csv")
}
if o.tree {
options = append(options, "--tree")
}
if o.valuation {
options = append(options, "--market")
}
if o.percent {
options = append(options, "-%")
}
return options
}