Merge "cmdmain: sort Modes and Examples"

This commit is contained in:
Brad Fitzpatrick 2018-01-04 04:59:27 +00:00 committed by Gerrit Code Review
commit ed07089172
1 changed files with 17 additions and 3 deletions

View File

@ -25,6 +25,7 @@ import (
"log"
"os"
"path/filepath"
"sort"
"sync"
"perkeep.org/pkg/buildinfo"
@ -135,23 +136,36 @@ Usage: ` + cmdName + ` [globalopts] <mode> [commandopts] [commandargs]
Modes:
`)
var modes []string
for mode, cmd := range modeCommand {
if des, ok := cmd.(describer); ok {
Errorf(" %s: %s\n", mode, des.Describe())
modes = append(modes, fmt.Sprintf(" %s: %s\n", mode, des.Describe()))
}
}
sort.Strings(modes)
for i := range modes {
Errorf("%s", modes[i])
}
Errorf("\nExamples:\n")
modes = nil
for mode, cmd := range modeCommand {
if ex, ok := cmd.(exampler); ok {
line := ""
exs := ex.Examples()
if len(exs) > 0 {
Errorf("\n")
line = "\n"
}
for _, example := range exs {
Errorf(" %s %s %s\n", cmdName, mode, example)
line += fmt.Sprintf(" %s %s %s\n", cmdName, mode, example)
}
modes = append(modes, line)
}
}
sort.Strings(modes)
for i := range modes {
Errorf("%s", modes[i])
}
Errorf(`
For mode-specific help: