From 7318e27528b3be6a024e85c16d1776342ac40d70 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Tue, 17 May 2016 03:46:16 -0400 Subject: [PATCH] Tidy up the flag name visitor func in Context --- context.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/context.go b/context.go index 002fe6e..03c61b2 100644 --- a/context.go +++ b/context.go @@ -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) } }