Fix up logging flags for kubectl.

This commit is contained in:
Joe Beda 2015-01-14 14:54:39 -08:00
parent 7ee327146a
commit 1d0b6ee5f5
3 changed files with 16 additions and 2 deletions

View File

@ -143,6 +143,10 @@ func (f *Factory) BindFlags(flags *pflag.FlagSet) {
// any flags defined by external projects (not part of pflags)
util.AddAllFlagsToPFlagSet(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)
if f.flags != nil {
f.flags.VisitAll(func(flag *pflag.Flag) {
flags.AddFlag(flag)

View File

@ -17,14 +17,15 @@ limitations under the License.
package util
import (
"flag"
"log"
"time"
"github.com/golang/glog"
flag "github.com/spf13/pflag"
"github.com/spf13/pflag"
)
var logFlushFreq = flag.Duration("log_flush_frequency", 5*time.Second, "Maximum number of seconds between log flushes")
var logFlushFreq = pflag.Duration("log_flush_frequency", 5*time.Second, "Maximum number of seconds between log flushes")
// TODO(thockin): This is temporary until we agree on log dirs and put those into each cmd.
func init() {

View File

@ -87,3 +87,12 @@ func AddAllFlagsToPFlagSet(fs *pflag.FlagSet) {
func AddAllFlagsToPFlags() {
AddFlagSetToPFlagSet(flag.CommandLine, pflag.CommandLine)
}
// Merge all of the flags from fsFrom into fsTo.
func AddPFlagSetToPFlagSet(fsFrom *pflag.FlagSet, fsTo *pflag.FlagSet) {
fsFrom.VisitAll(func(f *pflag.Flag) {
if fsTo.Lookup(f.Name) == nil {
fsTo.AddFlag(f)
}
})
}