sort flags with the same name in a consistent order

Docker-DCO-1.1-Signed-off-by: Jonathan Boulle <jonathanboulle@gmail.com> (github: jonboulle)
This commit is contained in:
Jonathan Boulle 2014-05-16 16:40:27 -07:00 committed by Victor Vieux
parent 0959287cb7
commit 1d8231b230

View file

@ -305,12 +305,10 @@ type flagSlice []string
func (p flagSlice) Len() int { return len(p) } func (p flagSlice) Len() int { return len(p) }
func (p flagSlice) Less(i, j int) bool { func (p flagSlice) Less(i, j int) bool {
pi, pj := strings.ToLower(p[i]), strings.ToLower(p[j]) pi, pj := strings.TrimPrefix(p[i], "-"), strings.TrimPrefix(p[j], "-")
if pi[0] == '-' { lpi, lpj := strings.ToLower(pi), strings.ToLower(pj)
pi = pi[1:] if lpi != lpj {
} return lpi < lpj
if pj[0] == '-' {
pj = pj[1:]
} }
return pi < pj return pi < pj
} }
@ -443,8 +441,6 @@ func (f *FlagSet) PrintDefaults() {
} }
fmt.Fprintln(writer, "\t", line) fmt.Fprintln(writer, "\t", line)
} }
// start := fmt.Sprintf(format, strings.Join(names, ", -"), flag.DefValue)
// fmt.Fprintln(f.out(), start, strings.Replace(flag.Usage, "\n", "\n"+strings.Repeat(" ", len(start)+1), -1))
} }
}) })
writer.Flush() writer.Flush()
@ -833,14 +829,12 @@ func (f *FlagSet) parseOne() (bool, string, error) {
f.args = f.args[1:] f.args = f.args[1:]
has_value := false has_value := false
value := "" value := ""
for i := 1; i < len(name); i++ { // equals cannot be first if i := strings.Index(name, "="); i != -1 {
if name[i] == '=' { value = trimQuotes(name[i+1:])
value = trimQuotes(name[i+1:]) has_value = true
has_value = true name = name[:i]
name = name[0:i]
break
}
} }
m := f.formal m := f.formal
flag, alreadythere := m[name] // BUG flag, alreadythere := m[name] // BUG
if !alreadythere { if !alreadythere {