Validate string slice fields

This commit is contained in:
Kovid Goyal
2022-11-14 15:42:00 +05:30
parent 0cf8876f8a
commit 41a841c83d
2 changed files with 12 additions and 3 deletions
+2 -3
View File
@@ -6,7 +6,6 @@ import (
"fmt"
"os"
"reflect"
"regexp"
"strconv"
"strings"
@@ -425,8 +424,8 @@ func (self *Command) GetOptionValues(pointer_to_options_struct interface{}) erro
f.SetBool(v)
case StringOption:
if opt.IsList {
if f.Kind() != reflect.Slice {
return fmt.Errorf("The field: %s must be a slice", field_name)
if !is_string_slice(f) {
return fmt.Errorf("The field: %s must be a []string", field_name)
}
v := opt.parsed_value().([]string)
f.Set(reflect.ValueOf(v))