-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringvalue.go
More file actions
35 lines (30 loc) · 802 Bytes
/
stringvalue.go
File metadata and controls
35 lines (30 loc) · 802 Bytes
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
package opts
// String defines a string option with the specified name and default value.
// The argument s points to a string variable that will store the value of the
// option. String will panic if name is not valid or repeats an existing
// option.
func (g *Group) String(s *string, name, defValue string) {
if err := validateName("String", name); err != nil {
panic(err)
}
*s = defValue
opt := &opt{
value: &value[string]{
ptr: s,
convert: toString,
},
name: name,
isBool: false,
}
if err := g.optAlreadySet(name); err != nil {
panic(err)
}
g.opts[name] = opt
}
// StringZero is like String but with a default value of "".
func (g *Group) StringZero(s *string, name string) {
g.String(s, name, "")
}
func toString(s string) (string, error) {
return s, nil
}