diff --git a/mflag/example/example.go b/mflag/example/example.go index 352f652..ed940e8 100644 --- a/mflag/example/example.go +++ b/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/mflag/flag.go b/mflag/flag.go index ff0de23..7125c03 100644 --- a/mflag/flag.go +++ b/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