From a5898a9559f8bdc223333e50a69c951e92b40e84 Mon Sep 17 00:00:00 2001 From: Filipe Brandenburger Date: Thu, 22 Jan 2015 16:32:12 -0800 Subject: [PATCH] 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. --- pkg/util/pflag_import.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/util/pflag_import.go b/pkg/util/pflag_import.go index 19bfa283cf2..e45d88ef23c 100644 --- a/pkg/util/pflag_import.go +++ b/pkg/util/pflag_import.go @@ -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) {