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