Tidy up the flag name visitor func in Context

This commit is contained in:
Dan Buch 2016-05-17 03:46:16 -04:00
parent 7828300b97
commit 7318e27528
No known key found for this signature in database
GPG Key ID: FAEF12936DD3E3EC

View File

@ -137,11 +137,9 @@ func (c *Context) LocalFlagNames() []string {
// its parent contexts.
func (c *Context) FlagNames() []string {
names := []string{}
for _, ctx := range c.Lineage() {
ctx.flagSet.Visit(makeFlagNameVisitor(&names))
}
return names
}
@ -362,8 +360,17 @@ func normalizeFlags(flags []Flag, set *flag.FlagSet) error {
func makeFlagNameVisitor(names *[]string) func(*flag.Flag) {
return func(f *flag.Flag) {
name := strings.Split(f.Name, ",")[0]
if name != "help" && name != "version" {
nameParts := strings.Split(f.Name, ",")
name := strings.TrimSpace(nameParts[0])
for _, part := range nameParts {
part = strings.TrimSpace(part)
if len(part) > len(name) {
name = part
}
}
if name != "" {
(*names) = append(*names, name)
}
}