-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrest.go
74 lines (59 loc) · 1.28 KB
/
rest.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
package cli
type RestArgs struct {
Values Value
Name string
Usage Usager
defaultSaved bool
defaultValue string
defaultEmpty bool
}
func newRest(values Value, opts RestOptions) RestArgs {
return RestArgs{
Values: values,
Name: opts.Name,
Usage: opts.Usage,
}
}
func (ra *RestArgs) Type() string {
if ra.Values != nil {
if t, ok := ra.Values.(Typer); ok {
return t.Type()
}
}
return ""
}
func (ra *RestArgs) IsZero() bool {
return ra.Values == nil
}
func (ra *RestArgs) Add(val string) error {
if ra.Values != nil {
if err := ra.Values.Set(val); err != nil {
return err
}
}
return nil
}
func (ra *RestArgs) Default() (v string, empty bool) {
if !ra.defaultSaved {
return "", true
}
return ra.defaultValue, ra.defaultEmpty
}
func (ra *RestArgs) SaveDefault() {
if ra.Values != nil {
ra.defaultValue = ra.Values.String()
if ev, ok := ra.Values.(Emptier); ok {
ra.defaultEmpty = ev.Empty()
} else {
ra.defaultEmpty = ra.defaultValue == ""
}
}
ra.defaultSaved = true
}
func RestVar(register Register, value Value, name string, options ...RestOptionApplyer) error {
var opts RestOptions
opts.applyName(name)
opts.applyRestOptions(options)
return register.RegisterRestArgs(newRest(value, opts))
}
//go:generate python ./generate_rest.py