mirror of
https://github.com/spf13/viper
synced 2025-05-06 20:27:17 +00:00
Merge 94e8f72a4c
into 5d46e70da8
This commit is contained in:
commit
b11cd5a631
1 changed files with 17 additions and 2 deletions
19
viper.go
19
viper.go
|
@ -21,6 +21,7 @@ package viper
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/csv"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
|
@ -893,8 +894,13 @@ func (v *Viper) find(lcaseKey string) interface{} {
|
|||
case "bool":
|
||||
return cast.ToBool(flag.ValueString())
|
||||
case "stringSlice":
|
||||
s := strings.TrimPrefix(flag.ValueString(), "[")
|
||||
return strings.TrimSuffix(s, "]")
|
||||
s := flag.ValueString()
|
||||
s = s[1 : len(s)-1] // trim []
|
||||
if len(s) == 0 {
|
||||
return []string{}
|
||||
}
|
||||
res, _ := readAsCSV(s)
|
||||
return res
|
||||
default:
|
||||
return flag.ValueString()
|
||||
}
|
||||
|
@ -1544,6 +1550,15 @@ func (v *Viper) findConfigFile() (string, error) {
|
|||
return "", ConfigFileNotFoundError{v.configName, fmt.Sprintf("%s", v.configPaths)}
|
||||
}
|
||||
|
||||
func readAsCSV(val string) ([]string, error) {
|
||||
if val == "" {
|
||||
return []string{}, nil
|
||||
}
|
||||
stringReader := strings.NewReader(val)
|
||||
csvReader := csv.NewReader(stringReader)
|
||||
return csvReader.Read()
|
||||
}
|
||||
|
||||
// Debug prints all configuration registries for debugging
|
||||
// purposes.
|
||||
func Debug() { v.Debug() }
|
||||
|
|
Loading…
Add table
Reference in a new issue