From 089bf5e11e4284a6ed07dc165098bb269dfddf46 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 5 Mar 2014 19:27:39 +0000 Subject: [PATCH 1/2] fix usage for completly deprecated flag Docker-DCO-1.1-Signed-off-by: Victor Vieux (github: vieux) --- pkg/mflag/example/example.go | 1 + pkg/mflag/flag.go | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/mflag/example/example.go b/pkg/mflag/example/example.go index b0d25fbfc6..352f652ebe 100644 --- a/pkg/mflag/example/example.go +++ b/pkg/mflag/example/example.go @@ -12,6 +12,7 @@ var ( ) func init() { + flag.Bool([]string{"#hp", "#-halp"}, false, "display the halp") flag.BoolVar(&b, []string{"b"}, false, "a simple bool") flag.BoolVar(&b2, []string{"-bool"}, false, "a simple bool") flag.IntVar(&i, []string{"#integer", "-integer"}, -1, "a simple integer") diff --git a/pkg/mflag/flag.go b/pkg/mflag/flag.go index 6fe3e41b23..ff0de23f78 100644 --- a/pkg/mflag/flag.go +++ b/pkg/mflag/flag.go @@ -404,7 +404,9 @@ func (f *FlagSet) PrintDefaults() { names = append(names, name) } } - fmt.Fprintf(f.out(), format, strings.Join(names, ", -"), flag.DefValue, flag.Usage) + if len(names) > 0 { + fmt.Fprintf(f.out(), format, strings.Join(names, ", -"), flag.DefValue, flag.Usage) + } }) } From 069dc7f8c7bc3eaf61ddd926636aacce5f1ed1ee Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 5 Mar 2014 19:45:57 +0000 Subject: [PATCH 2/2] fix panic with only long flags or only one deprecatd Docker-DCO-1.1-Signed-off-by: Victor Vieux (github: vieux) --- pkg/mflag/example/example.go | 4 ++-- pkg/mflag/flag.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/mflag/example/example.go b/pkg/mflag/example/example.go index 352f652ebe..ed940e8d70 100644 --- a/pkg/mflag/example/example.go +++ b/pkg/mflag/example/example.go @@ -14,8 +14,8 @@ var ( func init() { flag.Bool([]string{"#hp", "#-halp"}, false, "display the halp") flag.BoolVar(&b, []string{"b"}, false, "a simple bool") - flag.BoolVar(&b2, []string{"-bool"}, false, "a simple bool") - flag.IntVar(&i, []string{"#integer", "-integer"}, -1, "a simple integer") + flag.BoolVar(&b2, []string{"#-bool"}, false, "a simple bool") + flag.IntVar(&i, []string{"-integer", "-number"}, -1, "a simple integer") flag.StringVar(&str, []string{"s", "#hidden", "-string"}, "", "a simple string") //-s -hidden and --string will work, but -hidden won't be in the usage flag.BoolVar(&h, []string{"h", "#help", "-help"}, false, "display the help") flag.Parse() diff --git a/pkg/mflag/flag.go b/pkg/mflag/flag.go index ff0de23f78..7125c030ed 100644 --- a/pkg/mflag/flag.go +++ b/pkg/mflag/flag.go @@ -290,13 +290,13 @@ type Flag struct { func sortFlags(flags map[string]*Flag) []*Flag { var list sort.StringSlice for _, f := range flags { + fName := strings.TrimPrefix(f.Names[0], "#") if len(f.Names) == 1 { - list = append(list, f.Names[0]) + list = append(list, fName) continue } found := false - fName := strings.TrimPrefix(strings.TrimPrefix(f.Names[0], "#"), "-") for _, name := range list { if name == fName { found = true