func (l *Loader) putFlagIntoValues(v *config.Values, f *flaglib.Flag) { //all flaglib.Values are supposed to implement flaglib.Getters getter, ok := f.Value.(flaglib.Getter) if !ok { return } name := f.Name if alias, ok := l.Aliases[f.Name]; ok { name = alias } key := l.KeyParser.Parse(name) v.Put(key, getter.Get()) }
func (l *Loader) loadSingleIntoValues(key config.Key, values *config.Values, value interface{}) { if !key.StartsWith(l.KeyPrefix) || !key.EndsWith(l.KeySuffix) { return } if value == nil { if l.DiscardNull { return } values.Put(key, nil) } switch v := value.(type) { case jsonlib.Number: l.loadNumberIntoValues(key, values, v) default: values.Put(key, v) } }
func (l *Loader) loadNumberIntoValues(key config.Key, values *config.Values, num jsonlib.Number) { if l.NumberAsString { values.Put(key, num.String()) return } i64, err := num.Int64() if err != nil { f64, _ := num.Float64() values.Put(key, f64) } else { values.Put(key, i64) } }