export command fields
This commit is contained in:
parent
1a369915ff
commit
29b75b0bb1
30
goutil.go
30
goutil.go
|
@ -217,10 +217,10 @@ type CommandFlagsInit func(s *flag.FlagSet)
|
|||
type CommandInitExecFunc func() (CommandFlagsInit, CommandFunc)
|
||||
|
||||
type Command struct {
|
||||
cmd string
|
||||
exec CommandFunc
|
||||
desc string
|
||||
flags *flag.FlagSet
|
||||
Cmd string
|
||||
Exec CommandFunc
|
||||
Desc string
|
||||
Flags *flag.FlagSet
|
||||
}
|
||||
|
||||
func NewCommandWithFlags(cmd string, f CommandInitExecFunc, desc string) Command {
|
||||
|
@ -246,8 +246,8 @@ func usageAndExit(cmds []Command) {
|
|||
fmt.Println()
|
||||
fmt.Println("Possible commands:")
|
||||
for _, cmd := range cmds {
|
||||
fmt.Println(" " + cmd.cmd)
|
||||
fmt.Println(" \t" + cmd.desc)
|
||||
fmt.Println(" " + cmd.Cmd)
|
||||
fmt.Println(" \t" + cmd.Desc)
|
||||
}
|
||||
fmt.Println()
|
||||
fmt.Println("for detailed information type '" + app + " help COMMAND'")
|
||||
|
@ -257,7 +257,7 @@ func usageAndExit(cmds []Command) {
|
|||
func Execute(possibleCommands []Command) error {
|
||||
commands := commandCollection{}
|
||||
for _, c := range possibleCommands {
|
||||
commands[c.cmd] = c
|
||||
commands[c.Cmd] = c
|
||||
}
|
||||
arglen := len(os.Args)
|
||||
if arglen <= 1 {
|
||||
|
@ -272,11 +272,11 @@ func Execute(possibleCommands []Command) error {
|
|||
if !ok {
|
||||
usageAndExit(possibleCommands)
|
||||
} else {
|
||||
fmt.Println("Description of " + cmd.cmd + ":")
|
||||
fmt.Println(" " + cmd.desc)
|
||||
if cmd.flags != nil {
|
||||
fmt.Println("Description of " + cmd.Cmd + ":")
|
||||
fmt.Println(" " + cmd.Desc)
|
||||
if cmd.Flags != nil {
|
||||
fmt.Println("Possible flags:")
|
||||
cmd.flags.PrintDefaults()
|
||||
cmd.Flags.PrintDefaults()
|
||||
} else {
|
||||
fmt.Println("No flags")
|
||||
}
|
||||
|
@ -288,11 +288,11 @@ func Execute(possibleCommands []Command) error {
|
|||
if !ok {
|
||||
usageAndExit(possibleCommands)
|
||||
}
|
||||
if cmd.flags != nil {
|
||||
cmd.flags.Parse(os.Args[2:])
|
||||
return cmd.exec(cmd.flags.Args())
|
||||
if cmd.Flags != nil {
|
||||
cmd.Flags.Parse(os.Args[2:])
|
||||
return cmd.Exec(cmd.Flags.Args())
|
||||
} else {
|
||||
return cmd.exec(os.Args[2:])
|
||||
return cmd.Exec(os.Args[2:])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user