github.com/lyft/flytestdlib@v0.3.12-0.20210213045714-8cdd111ecda1/logger/config_flags.go (about) 1 // Code generated by go generate; DO NOT EDIT. 2 // This file was generated by robots. 3 4 package logger 5 6 import ( 7 "encoding/json" 8 "reflect" 9 10 "fmt" 11 12 "github.com/spf13/pflag" 13 ) 14 15 // If v is a pointer, it will get its element value or the zero value of the element type. 16 // If v is not a pointer, it will return it as is. 17 func (Config) elemValueOrNil(v interface{}) interface{} { 18 if t := reflect.TypeOf(v); t.Kind() == reflect.Ptr { 19 if reflect.ValueOf(v).IsNil() { 20 return reflect.Zero(t.Elem()).Interface() 21 } else { 22 return reflect.ValueOf(v).Interface() 23 } 24 } else if v == nil { 25 return reflect.Zero(t).Interface() 26 } 27 28 return v 29 } 30 31 func (Config) mustMarshalJSON(v json.Marshaler) string { 32 raw, err := v.MarshalJSON() 33 if err != nil { 34 panic(err) 35 } 36 37 return string(raw) 38 } 39 40 // GetPFlagSet will return strongly types pflags for all fields in Config and its nested types. The format of the 41 // flags is json-name.json-sub-name... etc. 42 func (cfg Config) GetPFlagSet(prefix string) *pflag.FlagSet { 43 cmdFlags := pflag.NewFlagSet("Config", pflag.ExitOnError) 44 cmdFlags.Bool(fmt.Sprintf("%v%v", prefix, "show-source"), defaultConfig.IncludeSourceCode, "Includes source code location in logs.") 45 cmdFlags.Bool(fmt.Sprintf("%v%v", prefix, "mute"), defaultConfig.Mute, "Mutes all logs regardless of severity. Intended for benchmarks/tests only.") 46 cmdFlags.Int(fmt.Sprintf("%v%v", prefix, "level"), defaultConfig.Level, "Sets the minimum logging level.") 47 cmdFlags.String(fmt.Sprintf("%v%v", prefix, "formatter.type"), defaultConfig.Formatter.Type, "Sets logging format type.") 48 return cmdFlags 49 }