I am using https://github.com/jessevdk/go-flags and trying to group the subcommands using the top-level option "group" in the struct field. But instead of grouping the subcommands, it actually groups the options in the subcommands. Here is my code:
type Cmd1 struct {
Opt1 string `long:"opt1" description:"first opt" required:"true"`
Opt2 int `long:"opt2" description:"second opt" default:"10"`
}
type Cmd2 struct {
OptA string `long:"optA" description:"opt a" default:":8080"`
OptB string `long:"optB" description:"opt b" default:"debug"`
}
type MainCmd struct {
Cmd1 Cmd1 `group:"group1" namespace:"group1" env-namespace:"group1"`
Cmd2 Cmd2 `group:"group2" namespace:"group2" env-namespace:"group2"`
}
func main() {
var mainCmd MainCmd
parser := flags.NewParser(&mainCmd, flags.Default)
if _, err := parser.Parse(); err != nil {
if err, ok := err.(*flags.Error); ok {
if err.Type == flags.ErrHelp {
os.Exit(0)
}
parser.WriteHelp(os.Stdout)
}
os.Exit(1)
}
}
What I am looking for is when I run the main function, it will print the help message with the grouped subcommands like:
group1:
--Cmd1
group2:
--Cmd2
However it groups the subcommands' options like:
group1:
--group1.opt1=
--group1.opt2=
group2:
--group2.optA=
--group2.optB=
Any ideas or help? Thanks!