diff --git a/go.mod b/go.mod index 30c1f637fd..0c139be31d 100644 --- a/go.mod +++ b/go.mod @@ -102,7 +102,6 @@ require ( github.com/robfig/cron/v3 v3.0.1 github.com/rootless-containers/rootlesskit v0.14.5 github.com/sirupsen/logrus v1.8.1 - github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.7.0 github.com/tchap/go-patricia v2.3.0+incompatible // indirect github.com/urfave/cli v1.22.4 diff --git a/pkg/kubectl/main.go b/pkg/kubectl/main.go index e45809f5bf..fd32c21cd3 100644 --- a/pkg/kubectl/main.go +++ b/pkg/kubectl/main.go @@ -1,7 +1,6 @@ package kubectl import ( - goflag "flag" "fmt" "math/rand" "os" @@ -10,10 +9,9 @@ import ( "github.com/k3s-io/k3s/pkg/server" "github.com/sirupsen/logrus" - "github.com/spf13/pflag" - utilflag "k8s.io/component-base/cli/flag" - "k8s.io/component-base/logs" + "k8s.io/component-base/cli" "k8s.io/kubectl/pkg/cmd" + "k8s.io/kubectl/pkg/cmd/util" ) func Main() { @@ -42,19 +40,8 @@ func main() { rand.Seed(time.Now().UnixNano()) command := cmd.NewDefaultKubectlCommand() - - // TODO: once we switch everything over to Cobra commands, we can go back to calling - // utilflag.InitFlags() (by removing its pflag.Parse() call). For now, we have to set the - // normalize func and add the go flag set by hand. - pflag.CommandLine.SetNormalizeFunc(utilflag.WordSepNormalizeFunc) - pflag.CommandLine.AddGoFlagSet(goflag.CommandLine) - // utilflag.InitFlags() - logs.InitLogs() - defer logs.FlushLogs() - - if err := command.Execute(); err != nil { - fmt.Fprintf(os.Stderr, "%v\n", err) - os.Exit(1) + if err := cli.RunNoErrOutput(command); err != nil { + util.CheckErr(err) } }