-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
93 lines (74 loc) · 1.91 KB
/
types.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
package proteus
import (
"github.com/simplesurance/proteus/sources"
)
type config map[string]paramSet
func (c config) getParam(setName, paramName string) (ret paramSetField, exists bool) {
if set, ok := c[setName]; ok {
if ret, ok := set.fields[paramName]; ok {
return ret, true
}
}
return ret, false
}
// paramInfo returns information about the required parameter, including the
// names of the parameters and some additional information that providers
// may need. Special parameters (like --help) are optionally included.
func (c config) paramInfo(includeSpecial bool) sources.Parameters {
ret := make(sources.Parameters, len(c))
for fsName, fs := range c {
paramIDs := make(map[string]sources.ParameterInfo, len(fs.fields))
for paramName, info := range fs.fields {
if info.isSpecial && !includeSpecial {
continue
}
paramIDs[paramName] = sources.ParameterInfo{
IsBool: info.boolean,
}
}
ret[fsName] = paramIDs
}
return ret
}
type paramSet struct {
desc string
fields map[string]paramSetField
}
type paramSetField struct {
typ string
optional bool
secret bool
paramSet bool
desc string
boolean bool
path string
// isSpecial specifies that the parameter cannot be specified by all
// providers, like --help or --version.
isSpecial bool
isXtype bool // implements the types.XType interface
setValueFn func(v *string) error
validFn func(v string) error
getDefaultFn func() (string, error)
redactFn func(string) string
}
func (f paramSetField) redactedValue(v *string) func() string {
return func() string {
if f.secret {
return redactedPlaceholder
}
if v == nil {
return "<missing>"
}
return f.redactFn(*v)
}
}
func (f paramSetField) redactedDefaultValue() string {
if f.secret {
return redactedPlaceholder
}
ret, err := f.getDefaultFn()
if err != nil {
return "<" + err.Error() + ">"
}
return f.redactFn(ret)
}