EnumList maps a configuration directive to a []string variable. Directive must be in form 'name string1 string2' where each string should be from *allowed* slice. At least one argument should be present. See Map.Custom for description of inheritGlobal and required.
(name string, inheritGlobal, required bool, allowed, defaultVal []string, store *[]string)
| 82 | // |
| 83 | // See Map.Custom for description of inheritGlobal and required. |
| 84 | func (m *Map) EnumList(name string, inheritGlobal, required bool, allowed, defaultVal []string, store *[]string) { |
| 85 | m.Custom(name, inheritGlobal, required, func() (interface{}, error) { |
| 86 | return defaultVal, nil |
| 87 | }, func(_ *Map, node Node) (interface{}, error) { |
| 88 | if len(node.Children) != 0 { |
| 89 | return nil, NodeErr(node, "can't declare a block here") |
| 90 | } |
| 91 | if len(node.Args) == 0 { |
| 92 | return nil, NodeErr(node, "expected at least one argument") |
| 93 | } |
| 94 | |
| 95 | for _, arg := range node.Args { |
| 96 | isAllowed := false |
| 97 | for _, str := range allowed { |
| 98 | if str == arg { |
| 99 | isAllowed = true |
| 100 | } |
| 101 | } |
| 102 | if !isAllowed { |
| 103 | return nil, NodeErr(node, "invalid argument, valid values are: %v", allowed) |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | return node.Args, nil |
| 108 | }, store) |
| 109 | } |
| 110 | |
| 111 | // Enum maps a configuration directive to a string variable. |
| 112 | // |