print commands in order of appearance

This commit is contained in:
gutmet 2018-12-09 18:14:38 +01:00
parent 72de932c7e
commit 4012f24235

View File

@ -174,7 +174,7 @@ func NewCommand(cmd string, f CommandFunc, desc string) Command {
type commandCollection map[string]Command type commandCollection map[string]Command
func UsageAndExit(cmds commandCollection) { func usageAndExit(cmds []Command) {
fmt.Println(os.Args[0]) fmt.Println(os.Args[0])
fmt.Println() fmt.Println()
fmt.Println("Possible commands:") fmt.Println("Possible commands:")
@ -194,16 +194,16 @@ func Execute(possibleCommands []Command) error {
} }
arglen := len(os.Args) arglen := len(os.Args)
if arglen <= 1 { if arglen <= 1 {
UsageAndExit(commands) usageAndExit(possibleCommands)
} }
cmdStr := os.Args[1] cmdStr := os.Args[1]
if cmdStr == "help" { if cmdStr == "help" {
if arglen == 2 { if arglen == 2 {
UsageAndExit(commands) usageAndExit(possibleCommands)
} else { } else {
cmd, ok := commands[os.Args[2]] cmd, ok := commands[os.Args[2]]
if !ok { if !ok {
UsageAndExit(commands) usageAndExit(possibleCommands)
} else { } else {
fmt.Println("Description of " + cmd.cmd + ":") fmt.Println("Description of " + cmd.cmd + ":")
fmt.Println(" " + cmd.desc) fmt.Println(" " + cmd.desc)
@ -219,7 +219,7 @@ func Execute(possibleCommands []Command) error {
} }
cmd, ok := commands[cmdStr] cmd, ok := commands[cmdStr]
if !ok { if !ok {
UsageAndExit(commands) usageAndExit(possibleCommands)
} }
if cmd.flags != nil { if cmd.flags != nil {
cmd.flags.Parse(os.Args[2:]) cmd.flags.Parse(os.Args[2:])