-
Notifications
You must be signed in to change notification settings - Fork 57
/
example_enum.go
332 lines (297 loc) · 8.21 KB
/
example_enum.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
// Code generated by go-enum DO NOT EDIT.
// Version: example
// Revision: example
// Build Date: example
// Built By: example
//go:build example
// +build example
package example
import (
"fmt"
"strings"
)
const (
// MakeToyota is a Make of type Toyota.
MakeToyota Make = iota
// Skipped value.
_
// MakeChevy is a Make of type Chevy.
MakeChevy
// Skipped value.
_
// MakeFord is a Make of type Ford.
MakeFord
// Skipped value.
_
// MakeTesla is a Make of type Tesla.
MakeTesla
// Skipped value.
_
// MakeHyundai is a Make of type Hyundai.
MakeHyundai
// Skipped value.
_
// MakeNissan is a Make of type Nissan.
MakeNissan
// Skipped value.
_
// MakeJaguar is a Make of type Jaguar.
MakeJaguar
// Skipped value.
_
// MakeAudi is a Make of type Audi.
MakeAudi
// Skipped value.
_
// MakeBMW is a Make of type BMW.
MakeBMW
// Skipped value.
_
// MakeMercedesBenz is a Make of type Mercedes-Benz.
MakeMercedesBenz
// Skipped value.
_
// MakeVolkswagon is a Make of type Volkswagon.
MakeVolkswagon
)
var ErrInvalidMake = fmt.Errorf("not a valid Make, try [%s]", strings.Join(_MakeNames, ", "))
const _MakeName = "ToyotaChevyFordTeslaHyundaiNissanJaguarAudiBMWMercedes-BenzVolkswagon"
var _MakeNames = []string{
_MakeName[0:6],
_MakeName[6:11],
_MakeName[11:15],
_MakeName[15:20],
_MakeName[20:27],
_MakeName[27:33],
_MakeName[33:39],
_MakeName[39:43],
_MakeName[43:46],
_MakeName[46:59],
_MakeName[59:69],
}
// MakeNames returns a list of possible string values of Make.
func MakeNames() []string {
tmp := make([]string, len(_MakeNames))
copy(tmp, _MakeNames)
return tmp
}
// MakeValues returns a list of the values for Make
func MakeValues() []Make {
return []Make{
MakeToyota,
MakeChevy,
MakeFord,
MakeTesla,
MakeHyundai,
MakeNissan,
MakeJaguar,
MakeAudi,
MakeBMW,
MakeMercedesBenz,
MakeVolkswagon,
}
}
var _MakeMap = map[Make]string{
MakeToyota: _MakeName[0:6],
MakeChevy: _MakeName[6:11],
MakeFord: _MakeName[11:15],
MakeTesla: _MakeName[15:20],
MakeHyundai: _MakeName[20:27],
MakeNissan: _MakeName[27:33],
MakeJaguar: _MakeName[33:39],
MakeAudi: _MakeName[39:43],
MakeBMW: _MakeName[43:46],
MakeMercedesBenz: _MakeName[46:59],
MakeVolkswagon: _MakeName[59:69],
}
// String implements the Stringer interface.
func (x Make) String() string {
if str, ok := _MakeMap[x]; ok {
return str
}
return fmt.Sprintf("Make(%d)", x)
}
// IsValid provides a quick way to determine if the typed value is
// part of the allowed enumerated values
func (x Make) IsValid() bool {
_, ok := _MakeMap[x]
return ok
}
var _MakeValue = map[string]Make{
_MakeName[0:6]: MakeToyota,
strings.ToLower(_MakeName[0:6]): MakeToyota,
_MakeName[6:11]: MakeChevy,
strings.ToLower(_MakeName[6:11]): MakeChevy,
_MakeName[11:15]: MakeFord,
strings.ToLower(_MakeName[11:15]): MakeFord,
_MakeName[15:20]: MakeTesla,
strings.ToLower(_MakeName[15:20]): MakeTesla,
_MakeName[20:27]: MakeHyundai,
strings.ToLower(_MakeName[20:27]): MakeHyundai,
_MakeName[27:33]: MakeNissan,
strings.ToLower(_MakeName[27:33]): MakeNissan,
_MakeName[33:39]: MakeJaguar,
strings.ToLower(_MakeName[33:39]): MakeJaguar,
_MakeName[39:43]: MakeAudi,
strings.ToLower(_MakeName[39:43]): MakeAudi,
_MakeName[43:46]: MakeBMW,
strings.ToLower(_MakeName[43:46]): MakeBMW,
_MakeName[46:59]: MakeMercedesBenz,
strings.ToLower(_MakeName[46:59]): MakeMercedesBenz,
_MakeName[59:69]: MakeVolkswagon,
strings.ToLower(_MakeName[59:69]): MakeVolkswagon,
}
// ParseMake attempts to convert a string to a Make.
func ParseMake(name string) (Make, error) {
if x, ok := _MakeValue[name]; ok {
return x, nil
}
// Case insensitive parse, do a separate lookup to prevent unnecessary cost of lowercasing a string if we don't need to.
if x, ok := _MakeValue[strings.ToLower(name)]; ok {
return x, nil
}
return Make(0), fmt.Errorf("%s is %w", name, ErrInvalidMake)
}
// MarshalText implements the text marshaller method.
func (x Make) MarshalText() ([]byte, error) {
return []byte(x.String()), nil
}
// UnmarshalText implements the text unmarshaller method.
func (x *Make) UnmarshalText(text []byte) error {
name := string(text)
tmp, err := ParseMake(name)
if err != nil {
return err
}
*x = tmp
return nil
}
// Set implements the Golang flag.Value interface func.
func (x *Make) Set(val string) error {
v, err := ParseMake(val)
*x = v
return err
}
// Get implements the Golang flag.Getter interface func.
func (x *Make) Get() interface{} {
return *x
}
// Type implements the github.com/spf13/pFlag Value interface.
func (x *Make) Type() string {
return "Make"
}
const (
// NoZerosStart is a NoZeros of type Start.
NoZerosStart NoZeros = iota + 20
// NoZerosMiddle is a NoZeros of type Middle.
NoZerosMiddle
// NoZerosEnd is a NoZeros of type End.
NoZerosEnd
// NoZerosPs is a NoZeros of type Ps.
NoZerosPs
// NoZerosPps is a NoZeros of type Pps.
NoZerosPps
// NoZerosPpps is a NoZeros of type Ppps.
NoZerosPpps
)
var ErrInvalidNoZeros = fmt.Errorf("not a valid NoZeros, try [%s]", strings.Join(_NoZerosNames, ", "))
const _NoZerosName = "startmiddleendpsppsppps"
var _NoZerosNames = []string{
_NoZerosName[0:5],
_NoZerosName[5:11],
_NoZerosName[11:14],
_NoZerosName[14:16],
_NoZerosName[16:19],
_NoZerosName[19:23],
}
// NoZerosNames returns a list of possible string values of NoZeros.
func NoZerosNames() []string {
tmp := make([]string, len(_NoZerosNames))
copy(tmp, _NoZerosNames)
return tmp
}
// NoZerosValues returns a list of the values for NoZeros
func NoZerosValues() []NoZeros {
return []NoZeros{
NoZerosStart,
NoZerosMiddle,
NoZerosEnd,
NoZerosPs,
NoZerosPps,
NoZerosPpps,
}
}
var _NoZerosMap = map[NoZeros]string{
NoZerosStart: _NoZerosName[0:5],
NoZerosMiddle: _NoZerosName[5:11],
NoZerosEnd: _NoZerosName[11:14],
NoZerosPs: _NoZerosName[14:16],
NoZerosPps: _NoZerosName[16:19],
NoZerosPpps: _NoZerosName[19:23],
}
// String implements the Stringer interface.
func (x NoZeros) String() string {
if str, ok := _NoZerosMap[x]; ok {
return str
}
return fmt.Sprintf("NoZeros(%d)", x)
}
// IsValid provides a quick way to determine if the typed value is
// part of the allowed enumerated values
func (x NoZeros) IsValid() bool {
_, ok := _NoZerosMap[x]
return ok
}
var _NoZerosValue = map[string]NoZeros{
_NoZerosName[0:5]: NoZerosStart,
strings.ToLower(_NoZerosName[0:5]): NoZerosStart,
_NoZerosName[5:11]: NoZerosMiddle,
strings.ToLower(_NoZerosName[5:11]): NoZerosMiddle,
_NoZerosName[11:14]: NoZerosEnd,
strings.ToLower(_NoZerosName[11:14]): NoZerosEnd,
_NoZerosName[14:16]: NoZerosPs,
strings.ToLower(_NoZerosName[14:16]): NoZerosPs,
_NoZerosName[16:19]: NoZerosPps,
strings.ToLower(_NoZerosName[16:19]): NoZerosPps,
_NoZerosName[19:23]: NoZerosPpps,
strings.ToLower(_NoZerosName[19:23]): NoZerosPpps,
}
// ParseNoZeros attempts to convert a string to a NoZeros.
func ParseNoZeros(name string) (NoZeros, error) {
if x, ok := _NoZerosValue[name]; ok {
return x, nil
}
// Case insensitive parse, do a separate lookup to prevent unnecessary cost of lowercasing a string if we don't need to.
if x, ok := _NoZerosValue[strings.ToLower(name)]; ok {
return x, nil
}
return NoZeros(0), fmt.Errorf("%s is %w", name, ErrInvalidNoZeros)
}
// MarshalText implements the text marshaller method.
func (x NoZeros) MarshalText() ([]byte, error) {
return []byte(x.String()), nil
}
// UnmarshalText implements the text unmarshaller method.
func (x *NoZeros) UnmarshalText(text []byte) error {
name := string(text)
tmp, err := ParseNoZeros(name)
if err != nil {
return err
}
*x = tmp
return nil
}
// Set implements the Golang flag.Value interface func.
func (x *NoZeros) Set(val string) error {
v, err := ParseNoZeros(val)
*x = v
return err
}
// Get implements the Golang flag.Getter interface func.
func (x *NoZeros) Get() interface{} {
return *x
}
// Type implements the github.com/spf13/pFlag Value interface.
func (x *NoZeros) Type() string {
return "NoZeros"
}