Skip to content

Commit

Permalink
Use pflag functions instead of ours.
Browse files Browse the repository at this point in the history
  • Loading branch information
eparis committed Aug 20, 2015
1 parent 681ee12 commit bcf9126
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 126 deletions.
6 changes: 3 additions & 3 deletions cmd/hyperkube/hyperkube.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func (hk *HyperKube) Flags() *pflag.FlagSet {

// These will add all of the "global" flags (defined with both the
// flag and pflag packages) to the new flag set we have.
util.AddFlagSetToPFlagSet(flag.CommandLine, hk.baseFlags)
util.AddPFlagSetToPFlagSet(pflag.CommandLine, hk.baseFlags)
hk.baseFlags.AddGoFlagSet(flag.CommandLine)
hk.baseFlags.AddFlagSet(pflag.CommandLine)

}
return hk.baseFlags
Expand Down Expand Up @@ -154,7 +154,7 @@ func (hk *HyperKube) Run(args []string) error {
return err
}

util.AddPFlagSetToPFlagSet(hk.Flags(), s.Flags())
s.Flags().AddFlagSet(hk.Flags())
err = s.Flags().Parse(args)
if err != nil || hk.helpFlagVal {
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/hyperkube/hyperkube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ func TestServerHelp(t *testing.T) {
x := runFull(t, "hyperkube test1 --help")
assert.NoError(t, x.err)
assert.Contains(t, x.output, "A simple server named test1")
assert.Contains(t, x.output, "--help=false: help for hyperkube")
assert.Contains(t, x.output, "--help[=false]: help for hyperkube")
assert.NotContains(t, x.output, "test1 Run")
}

func TestServerFlagsBad(t *testing.T) {
x := runFull(t, "hyperkube test1 --bad-flag")
assert.EqualError(t, x.err, "unknown flag: --bad-flag")
assert.Contains(t, x.output, "A simple server named test1")
assert.Contains(t, x.output, "--help=false: help for hyperkube")
assert.Contains(t, x.output, "--help[=false]: help for hyperkube")
assert.NotContains(t, x.output, "test1 Run")
}

Expand Down
6 changes: 3 additions & 3 deletions contrib/mesos/cmd/km/hyperkube.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func (hk *HyperKube) Flags() *pflag.FlagSet {

// These will add all of the "global" flags (defined with both the
// flag and pflag packages) to the new flag set we have.
util.AddFlagSetToPFlagSet(flag.CommandLine, hk.baseFlags)
util.AddPFlagSetToPFlagSet(pflag.CommandLine, hk.baseFlags)
hk.baseFlags.AddGoFlagSet(flag.CommandLine)
hk.baseFlags.AddFlagSet(pflag.CommandLine)

}
return hk.baseFlags
Expand Down Expand Up @@ -152,7 +152,7 @@ func (hk *HyperKube) Run(args []string) error {
return err
}

util.AddPFlagSetToPFlagSet(hk.Flags(), s.Flags())
s.Flags().AddFlagSet(hk.Flags())
err = s.Flags().Parse(args)
if err != nil || hk.helpFlagVal {
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions contrib/mesos/cmd/km/hyperkube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ func TestServerHelp(t *testing.T) {
x := runFull(t, "hyperkube test1 --help")
assert.NoError(t, x.err)
assert.Contains(t, x.output, "A simple server named test1")
assert.Contains(t, x.output, "--help=false: help for hyperkube")
assert.Contains(t, x.output, "--help[=false]: help for hyperkube")
assert.NotContains(t, x.output, "test1 Run")
}

func TestServerFlagsBad(t *testing.T) {
x := runFull(t, "hyperkube test1 --bad-flag")
assert.EqualError(t, x.err, "unknown flag: --bad-flag")
assert.Contains(t, x.output, "A simple server named test1")
assert.Contains(t, x.output, "--help=false: help for hyperkube")
assert.Contains(t, x.output, "--help[=false]: help for hyperkube")
assert.NotContains(t, x.output, "test1 Run")
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/kubectl/cmd/util/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,11 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
// 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)
flags.AddGoFlagSet(flag.CommandLine)

// 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)
flags.AddFlagSet(pflag.CommandLine)

// Hack for global access to validation flag.
// TODO: Refactor out after configuration flag overhaul.
Expand All @@ -284,7 +284,7 @@ func (f *Factory) BindFlags(flags *pflag.FlagSet) {
}

// Merge factory's flags
util.AddPFlagSetToPFlagSet(f.flags, flags)
flags.AddFlagSet(f.flags)

// Globally persistent flags across all subcommands.
// TODO Change flag names to consts to allow safer lookup from subcommands.
Expand Down
11 changes: 7 additions & 4 deletions pkg/util/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ limitations under the License.

package util

import "strings"
import (
goflag "flag"
"strings"

import "github.com/spf13/pflag"
import "github.com/golang/glog"
"github.com/golang/glog"
"github.com/spf13/pflag"
)

// WordSepNormalizeFunc changes all flags that contain "_" separators
func WordSepNormalizeFunc(f *pflag.FlagSet, name string) pflag.NormalizedName {
Expand All @@ -43,6 +46,6 @@ func WarnWordSepNormalizeFunc(f *pflag.FlagSet, name string) pflag.NormalizedNam
// InitFlags normalizes and parses the command line flags
func InitFlags() {
pflag.CommandLine.SetNormalizeFunc(WordSepNormalizeFunc)
AddAllFlagsToPFlags()
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)
pflag.Parse()
}
109 changes: 0 additions & 109 deletions pkg/util/pflag_import.go

This file was deleted.

0 comments on commit bcf9126

Please sign in to comment.