Show inherited flags in help output

This commit is contained in:
Mislav Marohnić 2020-06-16 13:58:31 +02:00
parent 9c75cff94b
commit ce59deb7b3

View file

@ -95,6 +95,11 @@ func rootHelpFunc(command *cobra.Command, args []string) {
dedent := regexp.MustCompile(`(?m)^ `)
helpEntries = append(helpEntries, helpEntry{"FLAGS", dedent.ReplaceAllString(flagUsages, "")})
}
inheritedFlagUsages := command.InheritedFlags().FlagUsages()
if inheritedFlagUsages != "" {
dedent := regexp.MustCompile(`(?m)^ `)
helpEntries = append(helpEntries, helpEntry{"INHERITED FLAGS", dedent.ReplaceAllString(inheritedFlagUsages, "")})
}
if _, ok := command.Annotations["help:arguments"]; ok {
helpEntries = append(helpEntries, helpEntry{"ARGUMENTS", command.Annotations["help:arguments"]})
}