Use new Tag type for slice separator.

This commit is contained in:
Alec Thomas
2018-05-23 12:20:47 -04:00
parent 886edb6f5a
commit 5df3b26bab
4 changed files with 6 additions and 4 deletions
+1
View File
@@ -118,6 +118,7 @@ func buildNode(v reflect.Value, seenFlags map[string]bool, cmd bool) *Node {
Help: tag.Help,
Default: tag.Default,
Decoder: decoder,
Tag: tag,
Value: fv,
// Flags are optional by default, and args are required by default.
+1 -1
View File
@@ -222,7 +222,7 @@ func floatDecoder(bits int) DecoderFunc {
func sliceDecoder(ctx *DecoderContext, scan *Scanner, target reflect.Value) error {
el := target.Type().Elem()
sep, ok := ctx.Value.Tag.Lookup("sep")
sep, ok := ctx.Value.Tag.Get("sep")
if !ok {
sep = ","
}
+1 -1
View File
@@ -30,7 +30,7 @@ type Value struct {
Help string
Default string
Decoder Decoder
Tag reflect.StructTag
Tag *Tag
Value reflect.Value
Required bool
Set bool // Used with Required to test if a value has been given.
+3 -2
View File
@@ -123,8 +123,9 @@ func (t *Tag) Has(k string) bool {
return ok
}
func (t *Tag) Get(k string) (string, error) {
return t.items[k], nil
func (t *Tag) Get(k string) (string, bool) {
s, ok := t.items[k]
return s, ok
}
func (t *Tag) GetBool(k string) (bool, error) {