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

liujun 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 5d62542  only print usage string when occurring flag error (#32)
     new bcd31ac  Merge pull request #38 from dawnzzz/master
5d62542 is described below

commit 5d62542f1d5a8b3324b65fe3e8b72fe24e34fa2e
Author: dawnzzz <[email protected]>
AuthorDate: Sun Sep 17 11:26:58 2023 +0800

    only print usage string when occurring flag error (#32)
---
 app/dubboctl/cmd/root.go | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/app/dubboctl/cmd/root.go b/app/dubboctl/cmd/root.go
index 23fcce6..8744d5f 100644
--- a/app/dubboctl/cmd/root.go
+++ b/app/dubboctl/cmd/root.go
@@ -34,15 +34,25 @@ type RootCommandConfig struct {
 // 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:  ``,
+               Use:           "dubboctl",
+               Short:         "dubbo control interface",
+               Long:          ``,
+               SilenceErrors: true,
+               SilenceUsage:  true,
        }
 
        cfg := RootCommandConfig{

Reply via email to