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 010c905f [dubboctl] fix errors imports v2
010c905f is described below

commit 010c905f2051cb279d69d070d5402556bf710924
Author: mfordjody <[email protected]>
AuthorDate: Wed Oct 30 07:54:52 2024 +0800

    [dubboctl] fix errors imports v2
---
 dubboctl/cmd/manifest_test.go                  |  23 ++---
 dubboctl/cmd/root.go                           | 121 ------------------------
 dubboctl/{cmd/root.go => pkg/common/common.go} | 124 ++++---------------------
 dubboctl/pkg/deploy/build.go                   |  22 ++---
 dubboctl/pkg/deploy/common.go                  |  26 ------
 dubboctl/pkg/deploy/create.go                  |  38 ++++----
 dubboctl/pkg/deploy/deploy.go                  |  46 ++++-----
 dubboctl/pkg/deploy/repository.go              |  34 +++----
 8 files changed, 98 insertions(+), 336 deletions(-)

diff --git a/dubboctl/cmd/manifest_test.go b/dubboctl/cmd/manifest_test.go
index 5eb66deb..4361abbd 100644
--- a/dubboctl/cmd/manifest_test.go
+++ b/dubboctl/cmd/manifest_test.go
@@ -18,20 +18,15 @@ package cmd
 import (
        "bytes"
        "os"
-       "sigs.k8s.io/controller-runtime/pkg/client"
        "strings"
        "testing"
 )
 
-import (
-       "sigs.k8s.io/controller-runtime/pkg/client/fake"
-)
-
-var (
-       // TestInstallFlag and TestCli are uses for black box testing
-       TestInstallFlag bool
-       TestCli         client.Client
-)
+//var (
+//     // TestInstallFlag and TestCli are uses for black box testing
+//     TestInstallFlag bool
+//     TestCli         client.Client
+//)
 
 func TestManifestGenerate(t *testing.T) {
        tests := []struct {
@@ -102,8 +97,8 @@ func TestManifestInstall(t *testing.T) {
                },
        }
        // For now, we do not use envTest to do black box testing
-       TestInstallFlag = true
-       TestCli = fake.NewClientBuilder().Build()
+       //TestInstallFlag = true
+       //TestCli = fake.NewClientBuilder().Build()
 
        for _, test := range tests {
                t.Run(test.desc, func(t *testing.T) {
@@ -127,8 +122,8 @@ func TestManifestUninstall(t *testing.T) {
                },
        }
        // For now, we do not use envTest to do black box testing
-       TestInstallFlag = true
-       TestCli = fake.NewClientBuilder().Build()
+       //TestInstallFlag = true
+       //TestCli = fake.NewClientBuilder().Build()
 
        for _, test := range tests {
                t.Run(test.desc, func(t *testing.T) {
diff --git a/dubboctl/cmd/root.go b/dubboctl/cmd/root.go
index 0fa886d8..82bf9a5e 100644
--- a/dubboctl/cmd/root.go
+++ b/dubboctl/cmd/root.go
@@ -16,15 +16,11 @@
 package cmd
 
 import (
-       "fmt"
        "github.com/apache/dubbo-kubernetes/dubboctl/pkg/dashboard"
        "github.com/apache/dubbo-kubernetes/dubboctl/pkg/deploy"
        "github.com/apache/dubbo-kubernetes/dubboctl/pkg/generate"
        "github.com/apache/dubbo-kubernetes/dubboctl/pkg/manifest"
        "github.com/apache/dubbo-kubernetes/dubboctl/pkg/profile"
-       "os"
-       "path/filepath"
-       "strings"
 )
 
 import (
@@ -101,120 +97,3 @@ func addSubCommands(rootCmd *cobra.Command, newClient 
deploy.ClientFactory) {
        addRegistryCmd(rootCmd)
        addProxy(cmd2.DefaultRunCmdOpts, rootCmd)
 }
-
-// bindFunc which conforms to the cobra PreRunE method signature
-type bindFunc func(*cobra.Command, []string) error
-
-// BindEnv returns a bindFunc that binds env vars to the named flags.
-func BindEnv(flags ...string) bindFunc {
-       return func(cmd *cobra.Command, args []string) (err error) {
-               for _, flag := range flags {
-                       if err = viper.BindPFlag(flag, 
cmd.Flags().Lookup(flag)); err != nil {
-                               return
-                       }
-               }
-               viper.AutomaticEnv()        // read in environment variables 
for DUBBO_<flag>
-               viper.SetEnvPrefix("dubbo") // ensure that all have the prefix
-               return
-       }
-}
-
-// AddConfirmFlag ensures common text/wording when the --path flag is used
-func AddConfirmFlag(cmd *cobra.Command, dflt bool) {
-       cmd.Flags().BoolP("confirm", "c", dflt, "Prompt to confirm options 
interactively ($DUBBO_CONFIRM)")
-}
-
-// AddPathFlag ensures common text/wording when the --path flag is used
-func AddPathFlag(cmd *cobra.Command) {
-       cmd.Flags().StringP("path", "p", "", "Path to the application.  Default 
is current directory ($DUBBO_PATH)")
-}
-
-// SurveySelectDefault returns 'value' if defined and exists in 'options'.
-// Otherwise, options[0] is returned if it exists.  Empty string otherwise.
-//
-// Usage Example:
-//
-//     languages := []string{ "go", "node", "rust" },
-//     survey.Select{
-//       Options: options,
-//       Default: surveySelectDefaut(cfg.Language, languages),
-//     }
-//
-// Summary:
-//
-// This protects against an incorrectly initialized survey.Select when the user
-// has provided a nonexistant option (validation is handled elsewhere) or
-// when a value is required but there exists no defaults (no default value on
-// the associated flag).
-//
-// Explanation:
-//
-// The above example chooses the default for the Survey (--confirm) question
-// in a way that works with user-provided flag and environment variable values.
-//
-//     `cfg.Language` is the current value set in the config struct, which is
-//        populated from (in ascending order of precedence):
-//        static flag default, associated environment variable, or command 
flag.
-//     `languages` are the options which are being used by the survey select.
-//
-// This cascade allows for the Survey questions to be properly pre-initialzed
-// with their associated environment variables or flags.  For example,
-// A user whose default language is set to 'node' using the global environment
-// variable FUNC_LANGUAGE will have that option pre-selected when running
-// `dubbo create -c`.
-//
-// The 'survey' package expects the value of the Default member to exist
-// in the 'Options' member.  This is not possible when user-provided data is
-// allowed for the default, hence this logic is necessary.
-//
-// For example, when the user is using prompts (--confirm) to select from a set
-// of options, but the associated flag either has an unrecognized value, or no
-// value at all, without this logic the resulting select prompt would be
-// initialized with this as the default value, and the act of what appears to
-// be choose the first option displayed does not overwrite the invalid default.
-// It could perhaps be argued this is a shortcoming in the survey package, but
-// it is also clearly an error to provide invalid data for a default.
-func SurveySelectDefault(value string, options []string) string {
-       for _, v := range options {
-               if value == v {
-                       return v // The provided value is acceptable
-               }
-       }
-       if len(options) > 0 {
-               return options[0] // Sync with the option which will be shown 
by the UX
-       }
-       // Either the value is not an option or there are no options.  Either of
-       // which should fail proper validation
-       return ""
-}
-
-// cwd returns the current working directory or exits 1 printing the error.
-func cwd() (cwd string) {
-       cwd, err := os.Getwd()
-       if err != nil {
-               panic(fmt.Sprintf("Unable to determine current working 
directory: %v", err))
-       }
-       return cwd
-}
-
-// DeriveNameAndAbsolutePathFromPath returns application name and absolute path
-// to the application project root. The input parameter path could be one of:
-// 'relative/path/to/foo', '/absolute/path/to/foo', 'foo' or ”.
-func DeriveNameAndAbsolutePathFromPath(path string) (string, string) {
-       var absPath string
-
-       // If path is not specified, we would like to use current working dir
-       if path == "" {
-               path = cwd()
-       }
-
-       // Expand the passed function name to its absolute path
-       absPath, err := filepath.Abs(path)
-       if err != nil {
-               return "", ""
-       }
-
-       // Get the name of the function, which equals to name of the current 
directory
-       pathParts := strings.Split(strings.TrimRight(path, 
string(os.PathSeparator)), string(os.PathSeparator))
-       return pathParts[len(pathParts)-1], absPath
-}
diff --git a/dubboctl/cmd/root.go b/dubboctl/pkg/common/common.go
similarity index 60%
copy from dubboctl/cmd/root.go
copy to dubboctl/pkg/common/common.go
index 0fa886d8..44ca9eaa 100644
--- a/dubboctl/cmd/root.go
+++ b/dubboctl/pkg/common/common.go
@@ -1,107 +1,14 @@
-// Licensed to the Apache Software Foundation (ASF) under one or more
-// contributor license agreements.  See the NOTICE file distributed with
-// this work for additional information regarding copyright ownership.
-// The ASF licenses this file to You under the Apache License, Version 2.0
-// (the "License"); you may not use this file except in compliance with
-// the License.  You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package cmd
+package common
 
 import (
        "fmt"
-       "github.com/apache/dubbo-kubernetes/dubboctl/pkg/dashboard"
-       "github.com/apache/dubbo-kubernetes/dubboctl/pkg/deploy"
-       "github.com/apache/dubbo-kubernetes/dubboctl/pkg/generate"
-       "github.com/apache/dubbo-kubernetes/dubboctl/pkg/manifest"
-       "github.com/apache/dubbo-kubernetes/dubboctl/pkg/profile"
+       "github.com/ory/viper"
+       "github.com/spf13/cobra"
        "os"
        "path/filepath"
        "strings"
 )
 
-import (
-       "github.com/ory/viper"
-
-       "github.com/spf13/cobra"
-)
-
-import (
-       "github.com/apache/dubbo-kubernetes/pkg/core"
-       cmd2 "github.com/apache/dubbo-kubernetes/pkg/core/cmd"
-)
-
-type RootCommandConfig struct {
-       Name      string
-       NewClient deploy.ClientFactory
-}
-
-var controlPlaneLog = core.Log.WithName("dubboctl")
-
-// Execute adds all child commands to the root command and sets flags 
appropriately.
-// This is called by main.main(). It only needs to happen once to the rootCmd.
-func Execute(args []string) {
-       rootCmd := GetRootCmd(args)
-       // when flag error occurs, print usage string.
-       // but if an error occurs when executing command, usage string will not 
be printed.
-       rootCmd.SetFlagErrorFunc(func(command *cobra.Command, err error) error {
-               command.Println(command.UsageString())
-
-               return err
-       })
-
-       cobra.CheckErr(rootCmd.Execute())
-}
-
-func GetRootCmd(args []string) *cobra.Command {
-       // rootCmd represents the base command when called without any 
subcommands
-       rootCmd := &cobra.Command{
-               Use:           "dubboctl",
-               Short:         "dubbo control interface",
-               Long:          ``,
-               SilenceErrors: true,
-               SilenceUsage:  true,
-       }
-
-       cfg := RootCommandConfig{
-               Name: "dubboctl",
-       }
-
-       // DeployMode Variables
-       // Evaluated first after static defaults, set all flags to be 
associated with
-       // a version prefixed by "DUBBO_"
-       viper.AutomaticEnv()        // read in environment variables for 
DUBBO_<flag>
-       viper.SetEnvPrefix("dubbo") // ensure that all have the prefix
-       newClient := cfg.NewClient
-       if newClient == nil {
-               newClient = deploy.NewClient
-       }
-
-       addSubCommands(rootCmd, newClient)
-       rootCmd.SetArgs(args)
-       return rootCmd
-}
-
-func addSubCommands(rootCmd *cobra.Command, newClient deploy.ClientFactory) {
-       deploy.AddBuild(rootCmd, newClient)
-       deploy.AddCreate(rootCmd, newClient)
-       deploy.AddRepository(rootCmd, newClient)
-       deploy.AddDeploy(rootCmd, newClient)
-       manifest.AddManifest(rootCmd)
-       generate.AddGenerate(rootCmd)
-       profile.AddProfile(rootCmd)
-       dashboard.AddDashboard(rootCmd)
-       addRegistryCmd(rootCmd)
-       addProxy(cmd2.DefaultRunCmdOpts, rootCmd)
-}
-
 // bindFunc which conforms to the cobra PreRunE method signature
 type bindFunc func(*cobra.Command, []string) error
 
@@ -119,6 +26,13 @@ func BindEnv(flags ...string) bindFunc {
        }
 }
 
+func WriteFile(filename string, data []byte, perm os.FileMode) error {
+       if err := os.MkdirAll(filepath.Dir(filename), perm); err != nil {
+               return err
+       }
+       return os.WriteFile(filename, data, perm)
+}
+
 // AddConfirmFlag ensures common text/wording when the --path flag is used
 func AddConfirmFlag(cmd *cobra.Command, dflt bool) {
        cmd.Flags().BoolP("confirm", "c", dflt, "Prompt to confirm options 
interactively ($DUBBO_CONFIRM)")
@@ -188,15 +102,6 @@ func SurveySelectDefault(value string, options []string) 
string {
        return ""
 }
 
-// cwd returns the current working directory or exits 1 printing the error.
-func cwd() (cwd string) {
-       cwd, err := os.Getwd()
-       if err != nil {
-               panic(fmt.Sprintf("Unable to determine current working 
directory: %v", err))
-       }
-       return cwd
-}
-
 // DeriveNameAndAbsolutePathFromPath returns application name and absolute path
 // to the application project root. The input parameter path could be one of:
 // 'relative/path/to/foo', '/absolute/path/to/foo', 'foo' or ”.
@@ -218,3 +123,12 @@ func DeriveNameAndAbsolutePathFromPath(path string) 
(string, string) {
        pathParts := strings.Split(strings.TrimRight(path, 
string(os.PathSeparator)), string(os.PathSeparator))
        return pathParts[len(pathParts)-1], absPath
 }
+
+// cwd returns the current working directory or exits 1 printing the error.
+func cwd() (cwd string) {
+       cwd, err := os.Getwd()
+       if err != nil {
+               panic(fmt.Sprintf("Unable to determine current working 
directory: %v", err))
+       }
+       return cwd
+}
diff --git a/dubboctl/pkg/deploy/build.go b/dubboctl/pkg/deploy/build.go
index e70f150b..9228dd82 100644
--- a/dubboctl/pkg/deploy/build.go
+++ b/dubboctl/pkg/deploy/build.go
@@ -17,7 +17,7 @@ package deploy
 
 import (
        "fmt"
-       "github.com/apache/dubbo-kubernetes/dubboctl/cmd"
+       "github.com/apache/dubbo-kubernetes/dubboctl/pkg/common"
        "os"
        "strings"
 )
@@ -38,32 +38,32 @@ import (
 )
 
 func AddBuild(baseCmd *cobra.Command, newClient ClientFactory) {
-       cmds := &cobra.Command{
+       cmd := &cobra.Command{
                Use:        "build",
                Short:      "Build the image for the application",
                Long:       ``,
                SuggestFor: []string{"biuld", "buidl", "built"},
-               PreRunE: cmd.BindEnv("useDockerfile", "image", "path", "push", 
"force", "envs",
+               PreRunE: common.BindEnv("useDockerfile", "image", "path", 
"push", "force", "envs",
                        "builder-image"),
                RunE: func(cmd *cobra.Command, args []string) error {
                        return runBuildCmd(cmd, newClient)
                },
        }
 
-       cmds.Flags().StringP("builder-image", "b", "",
+       cmd.Flags().StringP("builder-image", "b", "",
                "Specify a custom builder image for use by the builder other 
than its default.")
-       cmds.Flags().BoolP("useDockerfile", "d", false,
+       cmd.Flags().BoolP("useDockerfile", "d", false,
                "Use the dockerfile with the specified path to build")
-       cmds.Flags().StringP("image", "i", "",
+       cmd.Flags().StringP("image", "i", "",
                "Container image( [registry]/[namespace]/[name]:[tag] )")
-       cmds.Flags().BoolP("push", "", true,
+       cmd.Flags().BoolP("push", "", true,
                "Whether to push the image to the registry center by the way")
-       cmds.Flags().BoolP("force", "f", false,
+       cmd.Flags().BoolP("force", "f", false,
                "Whether to force build")
-       cmds.Flags().StringArrayP("envs", "e", []string{},
+       cmd.Flags().StringArrayP("envs", "e", []string{},
                "environment variable for an application, KEY=VALUE format")
-       cmd.AddPathFlag(cmds)
-       baseCmd.AddCommand(cmds)
+       common.AddPathFlag(cmd)
+       baseCmd.AddCommand(cmd)
 }
 
 func runBuildCmd(cmd *cobra.Command, newClient ClientFactory) error {
diff --git a/dubboctl/pkg/deploy/common.go b/dubboctl/pkg/deploy/common.go
deleted file mode 100644
index 1e89b3d9..00000000
--- a/dubboctl/pkg/deploy/common.go
+++ /dev/null
@@ -1,26 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one or more
-// contributor license agreements.  See the NOTICE file distributed with
-// this work for additional information regarding copyright ownership.
-// The ASF licenses this file to You under the Apache License, Version 2.0
-// (the "License"); you may not use this file except in compliance with
-// the License.  You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package deploy
-
-import (
-       "sigs.k8s.io/controller-runtime/pkg/client"
-)
-
-var (
-       // TestInstallFlag and TestCli are uses for black box testing
-       TestInstallFlag bool
-       TestCli         client.Client
-)
diff --git a/dubboctl/pkg/deploy/create.go b/dubboctl/pkg/deploy/create.go
index caaeaee7..0087b94f 100644
--- a/dubboctl/pkg/deploy/create.go
+++ b/dubboctl/pkg/deploy/create.go
@@ -18,7 +18,7 @@ package deploy
 import (
        "errors"
        "fmt"
-       "github.com/apache/dubbo-kubernetes/dubboctl/cmd"
+       "github.com/apache/dubbo-kubernetes/dubboctl/pkg/common"
        "os"
        "strings"
        "text/tabwriter"
@@ -49,7 +49,7 @@ type ErrInvalidTemplate error
 
 // NewCreateCmd creates a create command using the given client creator.
 func AddCreate(baseCmd *cobra.Command, newClient ClientFactory) {
-       cmds := &cobra.Command{
+       cmd := &cobra.Command{
                Use:   "create",
                Short: "Create an application",
                Long: `
@@ -95,7 +95,7 @@ EXAMPLES
          $ {{.Name}} create -l go -t common mydubbo
                `,
                SuggestFor: []string{"vreate", "creaet", "craete", "new"},
-               PreRunE:    cmd.BindEnv("language", "template", "repository", 
"confirm", "init"),
+               PreRunE:    common.BindEnv("language", "template", 
"repository", "confirm", "init"),
                Aliases:    []string{"init"},
                RunE: func(cmd *cobra.Command, args []string) error {
                        return runCreate(cmd, args, newClient)
@@ -103,26 +103,26 @@ EXAMPLES
        }
 
        // Flags
-       cmds.Flags().StringP("language", "l", "", "Language Runtime (see help 
text for list) ($DUBBO_LANGUAGE)")
-       cmds.Flags().StringP("template", "t", "", "Application template. (see 
help text for list) ($DUBBO_TEMPLATE)")
-       cmds.Flags().StringP("repository", "r", "", "URI to a Git repository 
containing the specified template ($DUBBO_REPOSITORY)")
-       cmds.Flags().BoolP("init", "i", false,
+       cmd.Flags().StringP("language", "l", "", "Language Runtime (see help 
text for list) ($DUBBO_LANGUAGE)")
+       cmd.Flags().StringP("template", "t", "", "Application template. (see 
help text for list) ($DUBBO_TEMPLATE)")
+       cmd.Flags().StringP("repository", "r", "", "URI to a Git repository 
containing the specified template ($DUBBO_REPOSITORY)")
+       cmd.Flags().BoolP("init", "i", false,
                "Initialize the current project directly into a dubbo project 
without using a template")
 
-       cmd.AddConfirmFlag(cmds, false)
+       common.AddConfirmFlag(cmd, false)
 
        // Help Action
-       cmds.SetHelpFunc(func(cmd *cobra.Command, args []string) { 
runCreateHelp(cmd, args, newClient) })
+       cmd.SetHelpFunc(func(cmd *cobra.Command, args []string) { 
runCreateHelp(cmd, args, newClient) })
 
        // Tab completion
-       if err := cmds.RegisterFlagCompletionFunc("language", 
newRuntimeCompletionFunc(newClient)); err != nil {
+       if err := cmd.RegisterFlagCompletionFunc("language", 
newRuntimeCompletionFunc(newClient)); err != nil {
                fmt.Fprintf(os.Stderr, "unable to provide language runtime 
suggestions: %v\n", err)
        }
-       if err := cmds.RegisterFlagCompletionFunc("template", 
newTemplateCompletionFunc(newClient)); err != nil {
+       if err := cmd.RegisterFlagCompletionFunc("template", 
newTemplateCompletionFunc(newClient)); err != nil {
                fmt.Fprintf(os.Stderr, "unable to provide template suggestions: 
%v\n", err)
        }
 
-       baseCmd.AddCommand(cmds)
+       baseCmd.AddCommand(cmd)
 }
 
 // Run Create
@@ -189,7 +189,7 @@ type createConfig struct {
 // The client constructor function is used to create a transient client for
 // accessing things like the current valid templates list, and uses the
 // current value of the config at time of prompting.
-func newCreateConfig(cmds *cobra.Command, args []string, newClient 
ClientFactory) (cfg createConfig, err error) {
+func newCreateConfig(cmd *cobra.Command, args []string, newClient 
ClientFactory) (cfg createConfig, err error) {
        var (
                path         string
                dirName      string
@@ -200,7 +200,7 @@ func newCreateConfig(cmds *cobra.Command, args []string, 
newClient ClientFactory
                path = args[0]
        }
 
-       dirName, absolutePath = cmd.DeriveNameAndAbsolutePathFromPath(path)
+       dirName, absolutePath = common.DeriveNameAndAbsolutePathFromPath(path)
 
        // Config is the final default values based off the execution context.
        // When prompting, these become the defaults presented.
@@ -230,7 +230,7 @@ func newCreateConfig(cmds *cobra.Command, args []string, 
newClient ClientFactory
                        return createdCfg, err
                }
                fmt.Println("Command:")
-               fmt.Println(singleCommand(cmds, args, createdCfg))
+               fmt.Println(singleCommand(cmd, args, createdCfg))
                return createdCfg, nil
        }
 
@@ -272,7 +272,7 @@ func singleCommand(cmd *cobra.Command, args []string, cfg 
createConfig) string {
 // pre-client validation should not be required, as the Client does its own
 // validation.
 func (c createConfig) Validate(client *dubbo.Client) (err error) {
-       dirName, _ := cmd.DeriveNameAndAbsolutePathFromPath(c.Path)
+       dirName, _ := common.DeriveNameAndAbsolutePathFromPath(c.Path)
        if err = util.ValidateApplicationName(dirName); err != nil {
                return
        }
@@ -404,11 +404,11 @@ func (c createConfig) prompt(client *dubbo.Client) 
(createConfig, error) {
                                Default: c.Path,
                        },
                        Validate: func(val interface{}) error {
-                               derivedName, _ := 
cmd.DeriveNameAndAbsolutePathFromPath(val.(string))
+                               derivedName, _ := 
common.DeriveNameAndAbsolutePathFromPath(val.(string))
                                return util.ValidateApplicationName(derivedName)
                        },
                        Transform: func(ans interface{}) interface{} {
-                               _, absolutePath := 
cmd.DeriveNameAndAbsolutePathFromPath(ans.(string))
+                               _, absolutePath := 
common.DeriveNameAndAbsolutePathFromPath(ans.(string))
                                return absolutePath
                        },
                }, {
@@ -416,7 +416,7 @@ func (c createConfig) prompt(client *dubbo.Client) 
(createConfig, error) {
                        Prompt: &survey.Select{
                                Message: "Language Runtime:",
                                Options: runtimes,
-                               Default: cmd.SurveySelectDefault(c.Runtime, 
runtimes),
+                               Default: common.SurveySelectDefault(c.Runtime, 
runtimes),
                        },
                },
        }
diff --git a/dubboctl/pkg/deploy/deploy.go b/dubboctl/pkg/deploy/deploy.go
index 0f6dfc4f..18066bd8 100644
--- a/dubboctl/pkg/deploy/deploy.go
+++ b/dubboctl/pkg/deploy/deploy.go
@@ -18,7 +18,7 @@ package deploy
 import (
        "errors"
        "fmt"
-       "github.com/apache/dubbo-kubernetes/dubboctl/cmd"
+       "github.com/apache/dubbo-kubernetes/dubboctl/pkg/common"
        "os"
        "os/exec"
        "path/filepath"
@@ -50,7 +50,7 @@ const (
 )
 
 func AddDeploy(baseCmd *cobra.Command, newClient ClientFactory) {
-       cmds := &cobra.Command{
+       cmd := &cobra.Command{
                Use:   "deploy",
                Short: "Generate the k8s yaml of the application. By the way, 
you can choose to build the image, push the image and apply to the k8s 
cluster.",
                Long: `
@@ -61,55 +61,55 @@ SYNOPSIS
        dubboctl deploy [flags]
 `,
                SuggestFor: []string{"delpoy", "deplyo"},
-               PreRunE: cmd.BindEnv("path", "output", "namespace", "image", 
"envs", "name", "containerPort",
+               PreRunE: common.BindEnv("path", "output", "namespace", "image", 
"envs", "name", "containerPort",
                        "targetPort", "nodePort", "apply", "useDockerfile", 
"force", "builder-image", "build", "context",
                        "kubeConfig", "push"),
                RunE: func(cmd *cobra.Command, args []string) error {
                        return runDeploy(cmd, newClient)
                },
        }
-       cmds.Flags().StringP("namespace", "n", "default",
+       cmd.Flags().StringP("namespace", "n", "default",
                "Deploy into a specific namespace")
-       cmds.Flags().StringP("output", "o", "kube.yaml",
+       cmd.Flags().StringP("output", "o", "kube.yaml",
                "output kubernetes manifest")
-       cmds.Flags().StringP("name", "", "",
+       cmd.Flags().StringP("name", "", "",
                "The name of application")
-       cmds.Flags().IntP("containerPort", "", 0,
+       cmd.Flags().IntP("containerPort", "", 0,
                "The port of the deployment to listen on pod (required)")
-       cmds.Flags().IntP("targetPort", "", 0,
+       cmd.Flags().IntP("targetPort", "", 0,
                "The targetPort of the deployment, default to port")
-       cmds.Flags().IntP("nodePort", "", 0,
+       cmd.Flags().IntP("nodePort", "", 0,
                "The nodePort of the deployment to expose")
 
-       cmds.Flags().StringP("context", "", "",
+       cmd.Flags().StringP("context", "", "",
                "Context in kubeconfig to use")
-       cmds.Flags().StringP("kubeConfig", "k", "",
+       cmd.Flags().StringP("kubeConfig", "k", "",
                "Path to kubeconfig")
 
-       cmds.Flags().StringArrayP("envs", "e", nil,
+       cmd.Flags().StringArrayP("envs", "e", nil,
                "DeployMode variable to set in the form NAME=VALUE. "+
                        "This is for the environment variables passed in by the 
builderpack build method.")
-       cmds.Flags().StringP("builder-image", "b", "",
+       cmd.Flags().StringP("builder-image", "b", "",
                "Specify a custom builder image for use by the builder other 
than its default.")
-       cmds.Flags().BoolP("useDockerfile", "d", false,
+       cmd.Flags().BoolP("useDockerfile", "d", false,
                "Use the dockerfile with the specified path to build")
-       cmds.Flags().StringP("image", "i", "",
+       cmd.Flags().StringP("image", "i", "",
                "Container image( [registry]/[namespace]/[name]:[tag] )")
-       cmds.Flags().BoolP("push", "", true,
+       cmd.Flags().BoolP("push", "", true,
                "Whether to push the image to the registry center by the way")
-       cmds.Flags().BoolP("force", "f", false,
+       cmd.Flags().BoolP("force", "f", false,
                "Whether to force build")
 
-       cmds.Flags().BoolP("build", "", true,
+       cmd.Flags().BoolP("build", "", true,
                "Whether to build the image")
-       cmds.Flags().BoolP("apply", "a", false,
+       cmd.Flags().BoolP("apply", "a", false,
                "Whether to apply the application to the k8s cluster by the 
way")
-       cmds.Flags().StringP("portName", "", "http",
+       cmd.Flags().StringP("portName", "", "http",
                "Name of the port to be exposed")
 
-       cmd.AddPathFlag(cmds)
-       cmds.Flags().SetInterspersed(false)
-       baseCmd.AddCommand(cmds)
+       common.AddPathFlag(cmd)
+       cmd.Flags().SetInterspersed(false)
+       baseCmd.AddCommand(cmd)
 }
 
 func runDeploy(cmd *cobra.Command, newClient ClientFactory) error {
diff --git a/dubboctl/pkg/deploy/repository.go 
b/dubboctl/pkg/deploy/repository.go
index 771b2191..f68fe87f 100644
--- a/dubboctl/pkg/deploy/repository.go
+++ b/dubboctl/pkg/deploy/repository.go
@@ -18,7 +18,7 @@ package deploy
 import (
        "errors"
        "fmt"
-       "github.com/apache/dubbo-kubernetes/dubboctl/cmd"
+       "github.com/apache/dubbo-kubernetes/dubboctl/pkg/common"
        "os"
 )
 
@@ -38,7 +38,7 @@ import (
 // command constructors
 // --------------------
 func AddRepository(baseCmd *cobra.Command, newClient ClientFactory) {
-       cmds := &cobra.Command{
+       cmd := &cobra.Command{
                Short:   "Manage installed template repositories",
                Use:     "repository",
                Aliases: []string{"repo", "repositories"},
@@ -166,20 +166,20 @@ EXAMPLES
          default
 `,
                SuggestFor: []string{"repositories", "repos", "template", 
"templates", "pack", "packs"},
-               PreRunE:    cmd.BindEnv("confirm"),
+               PreRunE:    common.BindEnv("confirm"),
                RunE: func(cmd *cobra.Command, args []string) error {
                        return runRepository(cmd, args, newClient)
                },
        }
 
-       cmd.AddConfirmFlag(cmds, false)
+       common.AddConfirmFlag(cmd, false)
 
-       cmds.AddCommand(NewRepositoryListCmd(newClient))
-       cmds.AddCommand(NewRepositoryAddCmd(newClient))
-       cmds.AddCommand(NewRepositoryRenameCmd(newClient))
-       cmds.AddCommand(NewRepositoryRemoveCmd(newClient))
+       cmd.AddCommand(NewRepositoryListCmd(newClient))
+       cmd.AddCommand(NewRepositoryAddCmd(newClient))
+       cmd.AddCommand(NewRepositoryRenameCmd(newClient))
+       cmd.AddCommand(NewRepositoryRemoveCmd(newClient))
 
-       baseCmd.AddCommand(cmds)
+       baseCmd.AddCommand(cmd)
 }
 
 func NewRepositoryListCmd(newClient ClientFactory) *cobra.Command {
@@ -187,13 +187,13 @@ func NewRepositoryListCmd(newClient ClientFactory) 
*cobra.Command {
                Short:   "List repositories",
                Use:     "list",
                Aliases: []string{"ls"},
-               PreRunE: cmd.BindEnv("confirm"),
+               PreRunE: common.BindEnv("confirm"),
                RunE: func(cmd *cobra.Command, args []string) error {
                        return runRepositoryList(cmd, args, newClient)
                },
        }
 
-       cmd.AddConfirmFlag(cmds, false)
+       common.AddConfirmFlag(cmds, false)
        return cmds
 }
 
@@ -202,13 +202,13 @@ func NewRepositoryAddCmd(newClient ClientFactory) 
*cobra.Command {
                Short:      "Add a repository",
                Use:        "add <name> <url>",
                SuggestFor: []string{"ad", "install"},
-               PreRunE:    cmd.BindEnv("confirm"),
+               PreRunE:    common.BindEnv("confirm"),
                RunE: func(cmd *cobra.Command, args []string) error {
                        return runRepositoryAdd(cmd, args, newClient)
                },
        }
 
-       cmd.AddConfirmFlag(cmds, false)
+       common.AddConfirmFlag(cmds, false)
        return cmds
 }
 
@@ -217,13 +217,13 @@ func NewRepositoryRenameCmd(newClient ClientFactory) 
*cobra.Command {
                Short:   "Rename a repository",
                Use:     "rename <old> <new>",
                Aliases: []string{"mv"},
-               PreRunE: cmd.BindEnv("confirm"),
+               PreRunE: common.BindEnv("confirm"),
                RunE: func(cmd *cobra.Command, args []string) error {
                        return runRepositoryRename(cmd, args, newClient)
                },
        }
 
-       cmd.AddConfirmFlag(cmds, false)
+       common.AddConfirmFlag(cmds, false)
        return cmds
 }
 
@@ -233,13 +233,13 @@ func NewRepositoryRemoveCmd(newClient ClientFactory) 
*cobra.Command {
                Use:        "remove <name>",
                Aliases:    []string{"rm"},
                SuggestFor: []string{"delete", "del"},
-               PreRunE:    cmd.BindEnv("confirm"),
+               PreRunE:    common.BindEnv("confirm"),
                RunE: func(cmd *cobra.Command, args []string) error {
                        return runRepositoryRemove(cmd, args, newClient)
                },
        }
 
-       cmd.AddConfirmFlag(cmds, false)
+       common.AddConfirmFlag(cmds, false)
        return cmds
 }
 

Reply via email to