Add base command option for hiding generated help for normal args

This commit is contained in:
Kyle Havlovitz 2017-09-28 18:36:07 -07:00
parent a2997e2823
commit 8b31eef467
No known key found for this signature in database
GPG Key ID: 8A5E6B173056AD6C
1 changed files with 16 additions and 12 deletions

View File

@ -33,6 +33,8 @@ type BaseCommand struct {
UI cli.Ui
Flags FlagSetFlags
HideNormalFlagsHelp bool
flagSet *flag.FlagSet
hidden *flag.FlagSet
@ -233,18 +235,20 @@ func (c *BaseCommand) helpFlagsFor(f *flag.FlagSet) string {
})
}
firstCommand := true
f.VisitAll(func(f *flag.Flag) {
// Skip HTTP flags as they will be grouped separately
if flagContains(httpFlagsClient, f) || flagContains(httpFlagsServer, f) || flagContains(c.hidden, f) {
return
}
if firstCommand {
printTitle(&out, "Command Options")
firstCommand = false
}
printFlag(&out, f)
})
if !c.HideNormalFlagsHelp {
firstCommand := true
f.VisitAll(func(f *flag.Flag) {
// Skip HTTP flags as they will be grouped separately
if flagContains(httpFlagsClient, f) || flagContains(httpFlagsServer, f) || flagContains(c.hidden, f) {
return
}
if firstCommand {
printTitle(&out, "Command Options")
firstCommand = false
}
printFlag(&out, f)
})
}
return strings.TrimRight(out.String(), "\n")
}