Keep boolean status of imported flags

This makes glog flags such as --logtostderr and --alsologtostderr keep
working without requiring an explicit =true.

Tested by building kubelet and invoking it with --logtostderr. Also
tested a few non-boolean flags to ensure they weren't affected.
This commit is contained in:
Filipe Brandenburger 2015-01-22 16:32:12 -08:00
parent ebcc45b11c
commit a5898a9559

View File

@ -65,6 +65,18 @@ func (v *flagValueWrapper) Type() string {
return v.flagType
}
type boolFlag interface {
flag.Value
IsBoolFlag() bool
}
func (v *flagValueWrapper) IsBoolFlag() bool {
if bv, ok := v.inner.(boolFlag); ok {
return bv.IsBoolFlag()
}
return false
}
// Imports a 'flag.Flag' into a 'pflag.FlagSet'. The "short" option is unset
// and the type is inferred using reflection.
func AddFlagToPFlagSet(f *flag.Flag, fs *pflag.FlagSet) {