forked from AdamSLevy/flagbind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
option.go
50 lines (43 loc) · 1.06 KB
/
option.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
package flagbind
func newBind(opts ...Option) bind {
var b bind
for _, opt := range opts {
opt(&b)
}
return b
}
type bind struct {
Prefix string
NoAutoFlatten bool
NamePopulator func(fieldName string) string
}
func (b bind) Option() Option {
return func(bb *bind) {
*bb = b
}
}
// Option is an option that may be passed to Bind.
type Option func(*bind)
// Prefix all flag names with prefix, which should include any final separator
// (e.g. 'http-' or 'http.')
func Prefix(prefix string) Option {
return func(b *bind) {
b.Prefix = prefix
}
}
// By default the flags in embedded struct fields are not given a prefix unless
// they explicitly have a `flag:"name"` in their tag.
//
// This overrides this behavior so the flags in embedded struct fields are
// prefixed with their type name unless explicitly flattened with the tag
// `flag:";;;flatten"`.
func NoAutoFlatten() Option {
return func(b *bind) {
b.NoAutoFlatten = true
}
}
func NamePopulator(fn func(fieldName string) string) Option {
return func(b *bind) {
b.NamePopulator = fn
}
}