fix panic with only long flags or only one deprecatd
Docker-DCO-1.1-Signed-off-by: Victor Vieux <victor.vieux@docker.com> (github: vieux)
This commit is contained in:
parent
a5ba28e1f7
commit
7339ca8699
2 changed files with 4 additions and 4 deletions
|
@ -14,8 +14,8 @@ var (
|
||||||
func init() {
|
func init() {
|
||||||
flag.Bool([]string{"#hp", "#-halp"}, false, "display the halp")
|
flag.Bool([]string{"#hp", "#-halp"}, false, "display the halp")
|
||||||
flag.BoolVar(&b, []string{"b"}, false, "a simple bool")
|
flag.BoolVar(&b, []string{"b"}, false, "a simple bool")
|
||||||
flag.BoolVar(&b2, []string{"-bool"}, false, "a simple bool")
|
flag.BoolVar(&b2, []string{"#-bool"}, false, "a simple bool")
|
||||||
flag.IntVar(&i, []string{"#integer", "-integer"}, -1, "a simple integer")
|
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.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.BoolVar(&h, []string{"h", "#help", "-help"}, false, "display the help")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
|
@ -290,13 +290,13 @@ type Flag struct {
|
||||||
func sortFlags(flags map[string]*Flag) []*Flag {
|
func sortFlags(flags map[string]*Flag) []*Flag {
|
||||||
var list sort.StringSlice
|
var list sort.StringSlice
|
||||||
for _, f := range flags {
|
for _, f := range flags {
|
||||||
|
fName := strings.TrimPrefix(f.Names[0], "#")
|
||||||
if len(f.Names) == 1 {
|
if len(f.Names) == 1 {
|
||||||
list = append(list, f.Names[0])
|
list = append(list, fName)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
found := false
|
found := false
|
||||||
fName := strings.TrimPrefix(strings.TrimPrefix(f.Names[0], "#"), "-")
|
|
||||||
for _, name := range list {
|
for _, name := range list {
|
||||||
if name == fName {
|
if name == fName {
|
||||||
found = true
|
found = true
|
||||||
|
|
Loading…
Reference in a new issue