code: func sortFlags(flags map[string]*Flag) []*Flag {
  	var list flagSlice
  
  	// The sorted list is based on the first name, when flag map might use the other names.
  	nameMap := make(map[string]string)
  
  	for n, f := range flags {
  		fName := strings.TrimPrefix(f.Names[0], "#")
  		nameMap[fName] = n
  		if len(f.Names) == 1 {
  			list = append(list, fName)
  			continue
  		}
  
  		found := false
  		for _, name := range list {
  			if name == fName {
  				found = true
  				break
  			}
  		}
  		if !found {
  			list = append(list, fName)
  		}
  	}
  	sort.Sort(list)
  	result := make([]*Flag, len(list))
  	for i, name := range list {
  		result[i] = flags[nameMap[name]]
  	}
  	return result
  }
docs: // sortFlags returns the flags as a slice in lexicographical sorted order.