-
Notifications
You must be signed in to change notification settings - Fork 0
/
string.go
45 lines (37 loc) · 1.12 KB
/
string.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
package checksetter
import (
"github.com/nickwells/check.mod/check"
"github.com/nickwells/param.mod/v2/param"
"github.com/nickwells/param.mod/v2/param/psetter"
)
// String can be used to set a list of checkers for a string.
type String struct {
param.ValueReqMandatory
Value *[]check.String
}
// SetWithVal (called when a value follows the parameter) splits the value
// into a slice of check.String's and sets the Value accordingly.
func (s String) SetWithVal(_ string, paramVal string) error {
v, err := stringCFParse(paramVal)
if err != nil {
return err
}
*s.Value = v
return nil
}
// AllowedValues returns a description of the allowed values. It includes the
// separator to be used
func (s String) AllowedValues() string {
return allowedValues(strCFName)
}
// CurrentValue returns the current setting of the parameter value
func (s String) CurrentValue() string {
return currentValue(len(*s.Value))
}
// CheckSetter panics if the setter has not been properly created - if the
// Value is nil.
func (s String) CheckSetter(name string) {
if s.Value == nil {
panic(psetter.NilValueMessage(name, "checksetter.String"))
}
}