print commands in order of appearance
This commit is contained in:
parent
72de932c7e
commit
4012f24235
10
goutil.go
10
goutil.go
|
@ -174,7 +174,7 @@ func NewCommand(cmd string, f CommandFunc, desc string) Command {
|
|||
|
||||
type commandCollection map[string]Command
|
||||
|
||||
func UsageAndExit(cmds commandCollection) {
|
||||
func usageAndExit(cmds []Command) {
|
||||
fmt.Println(os.Args[0])
|
||||
fmt.Println()
|
||||
fmt.Println("Possible commands:")
|
||||
|
@ -194,16 +194,16 @@ func Execute(possibleCommands []Command) error {
|
|||
}
|
||||
arglen := len(os.Args)
|
||||
if arglen <= 1 {
|
||||
UsageAndExit(commands)
|
||||
usageAndExit(possibleCommands)
|
||||
}
|
||||
cmdStr := os.Args[1]
|
||||
if cmdStr == "help" {
|
||||
if arglen == 2 {
|
||||
UsageAndExit(commands)
|
||||
usageAndExit(possibleCommands)
|
||||
} else {
|
||||
cmd, ok := commands[os.Args[2]]
|
||||
if !ok {
|
||||
UsageAndExit(commands)
|
||||
usageAndExit(possibleCommands)
|
||||
} else {
|
||||
fmt.Println("Description of " + cmd.cmd + ":")
|
||||
fmt.Println(" " + cmd.desc)
|
||||
|
@ -219,7 +219,7 @@ func Execute(possibleCommands []Command) error {
|
|||
}
|
||||
cmd, ok := commands[cmdStr]
|
||||
if !ok {
|
||||
UsageAndExit(commands)
|
||||
usageAndExit(possibleCommands)
|
||||
}
|
||||
if cmd.flags != nil {
|
||||
cmd.flags.Parse(os.Args[2:])
|
||||
|
|
Loading…
Reference in New Issue
Block a user