From a7d3cdbabf86ed890ff16473f4397c0cc7575da8 Mon Sep 17 00:00:00 2001 From: Siyu Wang Date: Wed, 10 Nov 2021 19:18:20 +0800 Subject: [PATCH] Remove useless sub commands (#29) Signed-off-by: Siyu Wang --- Makefile | 2 +- pkg/cmd/cmd.go | 56 +++++++--------------------------------- pkg/cmd/expose/expose.go | 2 +- 3 files changed, 11 insertions(+), 49 deletions(-) diff --git a/Makefile b/Makefile index 191a3b8..26292ba 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ default: build build: kubectl-kruise kubectl-kruise: - GO111MODULE=on CGO_ENABLED=0 GOOS=${GOOS} go build -ldflags "$(LDFLAGS)" -o bin/kubectl-kruise cmd/plugin/main.go + GO111MODULE=on CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o bin/kubectl-kruise cmd/plugin/main.go test: find . -iname '*.go' -type f | grep -v /vendor/ | xargs gofmt -l diff --git a/pkg/cmd/cmd.go b/pkg/cmd/cmd.go index bc69ad6..a24b143 100644 --- a/pkg/cmd/cmd.go +++ b/pkg/cmd/cmd.go @@ -32,26 +32,14 @@ import ( cliflag "k8s.io/component-base/cli/flag" "k8s.io/kubectl/pkg/cmd/apiresources" "k8s.io/kubectl/pkg/cmd/apply" - "k8s.io/kubectl/pkg/cmd/attach" - "k8s.io/kubectl/pkg/cmd/autoscale" - "k8s.io/kubectl/pkg/cmd/certificates" - "k8s.io/kubectl/pkg/cmd/clusterinfo" cmdconfig "k8s.io/kubectl/pkg/cmd/config" - "k8s.io/kubectl/pkg/cmd/describe" "k8s.io/kubectl/pkg/cmd/diff" - "k8s.io/kubectl/pkg/cmd/drain" - cmdexec "k8s.io/kubectl/pkg/cmd/exec" "k8s.io/kubectl/pkg/cmd/kustomize" - "k8s.io/kubectl/pkg/cmd/logs" "k8s.io/kubectl/pkg/cmd/options" "k8s.io/kubectl/pkg/cmd/patch" "k8s.io/kubectl/pkg/cmd/plugin" - "k8s.io/kubectl/pkg/cmd/portforward" "k8s.io/kubectl/pkg/cmd/replace" - "k8s.io/kubectl/pkg/cmd/run" "k8s.io/kubectl/pkg/cmd/scale" - "k8s.io/kubectl/pkg/cmd/taint" - "k8s.io/kubectl/pkg/cmd/top" cmdutil "k8s.io/kubectl/pkg/cmd/util" "k8s.io/kubectl/pkg/cmd/version" "k8s.io/kubectl/pkg/cmd/wait" @@ -319,9 +307,8 @@ func NewKubectlCommand(in io.Reader, out, err io.Writer) *cobra.Command { warningsAsErrors := false // Parent command to which all subcommands are added. cmds := &cobra.Command{ - Use: "kubectl-kruise", - Short: i18n.T("kubectl-kruise controls the OpenKruise manager"), - Aliases: []string{"kk"}, + Use: "kubectl-kruise", + Short: i18n.T("kubectl-kruise controls the OpenKruise CRs"), Long: templates.LongDesc(` kubectl-kruise controls the OpenKruise manager. @@ -377,10 +364,10 @@ func NewKubectlCommand(in io.Reader, out, err io.Writer) *cobra.Command { groups := templates.CommandGroups{ { - Message: "Basic Commands (Beginner):", + Message: "Basic Commands:", Commands: []*cobra.Command{ expose.NewCmdExposeService(f, ioStreams), - run.NewCmdRun(f, ioStreams), + cmdWithShortOverwrite(scale.NewCmdScale(f, ioStreams), "Set a new size for a Deployment, ReplicaSet, CloneSet, or Advanced StatefulSet"), }, }, @@ -405,36 +392,6 @@ func NewKubectlCommand(in io.Reader, out, err io.Writer) *cobra.Command { scaledown.NewCmdScaleDown(f, ioStreams), }, }, - - { - Message: "Basic Commands:", - Commands: []*cobra.Command{ - scale.NewCmdScale(f, ioStreams), - autoscale.NewCmdAutoscale(f, ioStreams), - }, - }, - { - Message: "Cluster Management Commands:", - Commands: []*cobra.Command{ - certificates.NewCmdCertificate(f, ioStreams), - clusterinfo.NewCmdClusterInfo(f, ioStreams), - top.NewCmdTop(f, ioStreams), - drain.NewCmdCordon(f, ioStreams), - drain.NewCmdUncordon(f, ioStreams), - drain.NewCmdDrain(f, ioStreams), - taint.NewCmdTaint(f, ioStreams), - }, - }, - { - Message: "Troubleshooting and Debugging Commands:", - Commands: []*cobra.Command{ - describe.NewCmdDescribe("kubectl-kruise", f, ioStreams), - logs.NewCmdLogs(f, ioStreams), - attach.NewCmdAttach(f, ioStreams), - cmdexec.NewCmdExec(f, ioStreams), - portforward.NewCmdPortForward(f, ioStreams), - }, - }, { Message: "Advanced Commands:", Commands: []*cobra.Command{ @@ -497,3 +454,8 @@ func NewDefaultKubectlCommandWithArgs(args []string, in io.Reader, out, errout i return cmd } + +func cmdWithShortOverwrite(cmd *cobra.Command, short string) *cobra.Command { + cmd.Short = i18n.T(short) + return cmd +} diff --git a/pkg/cmd/expose/expose.go b/pkg/cmd/expose/expose.go index ed1477d..b359edd 100644 --- a/pkg/cmd/expose/expose.go +++ b/pkg/cmd/expose/expose.go @@ -135,7 +135,7 @@ func NewCmdExposeService(f cmdutil.Factory, streams genericclioptions.IOStreams) cmd := &cobra.Command{ Use: "expose (-f FILENAME | TYPE NAME) [--port=port] [--protocol=TCP|UDP|SCTP] [--target-port=number-or-name] [--name=name] [--external-ip=external-ip-of-service] [--type=type]", DisableFlagsInUseLine: true, - Short: i18n.T("Take a replication controller, service, deployment or pod and expose it as a new Kubernetes Service"), + Short: i18n.T("Take a workload(e.g. deployment, cloneset), service or pod and expose it as a new Kubernetes Service"), Long: exposeLong, Example: exposeExample, Run: func(cmd *cobra.Command, args []string) {