command: enable ordering commands by name

This commit is contained in:
Maximilian Meister
2016-12-18 17:43:48 +01:00
parent 8f6a3675e1
commit ac772237b9
2 changed files with 36 additions and 2 deletions

View File

@@ -61,6 +61,20 @@ type Command struct {
commandNamePath []string
}
type CommandsByName []Command
func (c CommandsByName) Len() int {
return len(c)
}
func (c CommandsByName) Less(i, j int) bool {
return c[i].Name < c[j].Name
}
func (c CommandsByName) Swap(i, j int) {
c[i], c[j] = c[j], c[i]
}
// FullName returns the full name of the command.
// For subcommands this ensures that parent commands are part of the command path
func (c Command) FullName() string {