In the following code I'm defining a command, where two options are possible: 1. myapp info --flag1 text 2. myapp info --flag2 if none of the two options are specified, I want to show the 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
}
},
}
In the cobra README the helpCommand is explained for usage like
myapp help info
or myapp info --help
or myapp info --nonexistentoption
but nothing regarding how to actually call the method voluntarily. Any pointers?