Go 如何在cobra命令中调用默认的helpCommand?

Go 如何在cobra命令中调用默认的helpCommand?,go,go-cobra,Go,Go Cobra,在下面的代码中,我定义了一个命令,其中有两个选项: 1.myapp信息--flag1文本 2.myapp信息--flag2 如果没有指定这两个选项中的任何一个,我想显示helpCommand var infoCmd = &cobra.Command{ Use: "info", Short: "A brief description of your command", Run: func(cmd *cobra.Command, args []string) {

在下面的代码中,我定义了一个命令,其中有两个选项: 1.myapp信息--flag1文本 2.myapp信息--flag2 如果没有指定这两个选项中的任何一个,我想显示helpCommand

var infoCmd = &cobra.Command{
    Use:   "info",
    Short: "A brief description of your command",
    Run: func(cmd *cobra.Command, args []string) {
        var infoURL string
        if flag1 != "" {
            doSomething()
        } else if flag2 { //this is a boolean flag
            doSomethingElse()
        } else {
            // Show the default help here
        }
     },
 }
在cobra中,helpCommand的用法如下
myapp帮助信息
myapp信息--help
myapp信息--不存在选项
,但与如何实际调用该方法无关。有什么建议吗?

我想这只是通过lib(未测试)查看:

请看这里:

// Help puts out the help for the command.
// Used when a user calls help [command].
// Can be defined by user by overriding HelpFunc.
func (c *Command) Help() error {
    c.HelpFunc()(c, []string{})
    return nil
}
一般来说,自述仅提供一些入门和概述信息,您通常需要打开godocs(内联文档)才能正确理解软件包:

// Help puts out the help for the command.
// Used when a user calls help [command].
// Can be defined by user by overriding HelpFunc.
func (c *Command) Help() error {
    c.HelpFunc()(c, []string{})
    return nil
}