// BindFlags adds any flags that are common to all kubectl sub commands. func (f *Factory) BindFlags(flags *pflag.FlagSet) { // any flags defined by external projects (not part of pflags) util.AddFlagSetToPFlagSet(flag.CommandLine, flags) // This is necessary as github.com/spf13/cobra doesn't support "global" // pflags currently. See https://github.com/spf13/cobra/issues/44. util.AddPFlagSetToPFlagSet(pflag.CommandLine, flags) // Hack for global access to validation flag. // TODO: Refactor out after configuration flag overhaul. if f.flags.Lookup("validate") == nil { f.flags.Bool("validate", false, "If true, use a schema to validate the input before sending it") } // Merge factory's flags util.AddPFlagSetToPFlagSet(f.flags, flags) // Globally persistent flags across all subcommands. // TODO Change flag names to consts to allow safer lookup from subcommands. // TODO Add a verbose flag that turns on glog logging. Probably need a way // to do that automatically for every subcommand. flags.BoolVar(&f.clients.matchVersion, FlagMatchBinaryVersion, false, "Require server version to match client version") // Normalize all flags that are comming from other packages or pre-configurations // a.k.a. change all "_" to "-". e.g. glog package flags.SetNormalizeFunc(util.WordSepNormalizeFunc) }
// BindFlags adds any flags that are common to all kubectl sub commands. func (f *Factory) BindFlags(flags *pflag.FlagSet) { // Merge factory's flags flags.AddFlagSet(f.flags) // Globally persistent flags across all subcommands. // TODO Change flag names to consts to allow safer lookup from subcommands. // TODO Add a verbose flag that turns on glog logging. Probably need a way // to do that automatically for every subcommand. flags.BoolVar(&f.clients.matchVersion, FlagMatchBinaryVersion, false, "Require server version to match client version") // Normalize all flags that are coming from other packages or pre-configurations // a.k.a. change all "_" to "-". e.g. glog package flags.SetNormalizeFunc(utilflag.WordSepNormalizeFunc) }
// NewClientAccessFactoryFromDiscovery allows an external caller to substitute a different discoveryFactory // Which allows for the client cache to be built in ring0, but still rely on a custom discovery client func NewClientAccessFactoryFromDiscovery(flags *pflag.FlagSet, clientConfig clientcmd.ClientConfig, discoveryFactory DiscoveryClientFactory) ClientAccessFactory { flags.SetNormalizeFunc(utilflag.WarnWordSepNormalizeFunc) // Warn for "_" flags clientCache := NewClientCache(clientConfig, discoveryFactory) f := &ring0Factory{ flags: flags, clientConfig: clientConfig, discoveryFactory: discoveryFactory, clientCache: clientCache, } return f }