You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by zh...@apache.org on 2024/12/05 04:04:00 UTC

(dubbo-kubernetes) branch master updated: [operator] Command table combing logic

This is an automated email from the ASF dual-hosted git repository.

zhongxjian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-kubernetes.git


The following commit(s) were added to refs/heads/master by this push:
     new 2c105da3 [operator] Command table combing logic
2c105da3 is described below

commit 2c105da3436168a7e2f6aa1be0f344a2c86d80b1
Author: mfordjody <11...@qq.com>
AuthorDate: Thu Dec 5 12:03:50 2024 +0800

    [operator] Command table combing logic
---
 dubboctl/cmd/root.go        |  6 +++++-
 dubboctl/pkg/cli/context.go | 20 +++++++++++++++++++-
 dubboctl/pkg/cli/options.go |  8 ++++----
 3 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/dubboctl/cmd/root.go b/dubboctl/cmd/root.go
index a5b93ed7..973de7d3 100644
--- a/dubboctl/cmd/root.go
+++ b/dubboctl/cmd/root.go
@@ -34,8 +34,12 @@ func GetRootCmd(args []string) *cobra.Command {
 		Long:  `Dubbo configuration command line utility for debug and use dubbo applications.`,
 	}
 	rootCmd.SetArgs(args)
+	flags := rootCmd.PersistentFlags()
 
-	installCmd := cluster.InstallCmd(nil)
+	rootOptions := cli.AddRootFlags(flags)
+	ctx := cli.NewCLIContext(rootOptions)
+
+	installCmd := cluster.InstallCmd(ctx)
 	rootCmd.AddCommand(installCmd)
 	AddFlags(installCmd)
 	hideFlags(installCmd, cli.NamespaceFlag, cli.DubboNamespaceFlag, cli.ChartFlag)
diff --git a/dubboctl/pkg/cli/context.go b/dubboctl/pkg/cli/context.go
index b4fbaf3b..82107a0b 100644
--- a/dubboctl/pkg/cli/context.go
+++ b/dubboctl/pkg/cli/context.go
@@ -1,15 +1,33 @@
 package cli
 
-import "github.com/apache/dubbo-kubernetes/pkg/kube"
+import (
+	"github.com/apache/dubbo-kubernetes/pkg/kube"
+	"github.com/apache/dubbo-kubernetes/pkg/pointer"
+)
 
 type instance struct {
 	client map[string]kube.CLIClient
+	RootFlags
 }
 
 type Context interface {
 	CLIClient() (kube.CLIClient, error)
 }
 
+func NewCLIContext(rootFlags *RootFlags) Context {
+	if rootFlags == nil {
+		rootFlags = &RootFlags{
+			kubeconfig:     pointer.Of[string](""),
+			Context:        pointer.Of[string](""),
+			namespace:      pointer.Of[string](""),
+			dubboNamespace: pointer.Of[string](""),
+		}
+	}
+	return &instance{
+		RootFlags: *rootFlags,
+	}
+}
+
 func (i *instance) CLIClient() (kube.CLIClient, error) {
 	return nil, nil
 }
diff --git a/dubboctl/pkg/cli/options.go b/dubboctl/pkg/cli/options.go
index 85096f67..6b4ce431 100644
--- a/dubboctl/pkg/cli/options.go
+++ b/dubboctl/pkg/cli/options.go
@@ -11,13 +11,13 @@ const (
 	KubeConfigFlag     = "kubeconfig"
 	ContextFlag        = "context"
 	NamespaceFlag      = "namespace"
-	DubboNamespaceFlag = "dubboNamespace"
+	DubboNamespaceFlag = "dubbo-namespace"
 	ChartFlag          = "charts"
 )
 
 type RootFlags struct {
 	kubeconfig     *string
-	cfgContext     *string
+	Context        *string
 	namespace      *string
 	dubboNamespace *string
 }
@@ -25,12 +25,12 @@ type RootFlags struct {
 func AddRootFlags(flags *pflag.FlagSet) *RootFlags {
 	rootFlags := &RootFlags{
 		kubeconfig:     pointer.Of[string](""),
-		cfgContext:     pointer.Of[string](""),
+		Context:        pointer.Of[string](""),
 		namespace:      pointer.Of[string](""),
 		dubboNamespace: pointer.Of[string](""),
 	}
 	flags.StringVarP(rootFlags.kubeconfig, KubeConfigFlag, "c", "", "Kubernetes configuration file")
-	flags.StringVar(rootFlags.cfgContext, ContextFlag, "", "Kubernetes configuration context")
+	flags.StringVar(rootFlags.Context, ContextFlag, "", "Kubernetes configuration context")
 	flags.StringVarP(rootFlags.namespace, NamespaceFlag, "n", v1.NamespaceAll, "Kubernetes namespace")
 	flags.StringVarP(rootFlags.dubboNamespace, DubboNamespaceFlag, "i", viper.GetString(DubboNamespaceFlag), "Dubbo system namespace")
 	return rootFlags