low hanging fruit for using cobra commands

This commit is contained in:
David Eads
2018-01-17 13:41:01 -05:00
parent 8a6bb3e120
commit d7ddcca231
20 changed files with 111 additions and 101 deletions

View File

@@ -19,7 +19,12 @@ go_library(
srcs = ["kubectl.go"],
importpath = "k8s.io/kubernetes/cmd/kubectl",
visibility = ["//visibility:private"],
deps = ["//cmd/kubectl/app:go_default_library"],
deps = [
"//pkg/kubectl/cmd:go_default_library",
"//vendor/github.com/spf13/pflag:go_default_library",
"//vendor/k8s.io/apiserver/pkg/util/flag:go_default_library",
"//vendor/k8s.io/apiserver/pkg/util/logs:go_default_library",
],
)
filegroup(

View File

@@ -17,16 +17,33 @@ limitations under the License.
package main
import (
"fmt"
goflag "flag"
"math/rand"
"os"
"time"
"k8s.io/kubernetes/cmd/kubectl/app"
"github.com/spf13/pflag"
utilflag "k8s.io/apiserver/pkg/util/flag"
"k8s.io/apiserver/pkg/util/logs"
"k8s.io/kubernetes/pkg/kubectl/cmd"
)
func main() {
if err := app.Run(); err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
rand.Seed(time.Now().UTC().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 {
os.Exit(1)
}
os.Exit(0)
}