From 29b75b0bb1c255139c00ff31165abac63b119c5a Mon Sep 17 00:00:00 2001 From: gutmet Date: Fri, 29 May 2020 10:10:30 +0200 Subject: [PATCH] export command fields --- goutil.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/goutil.go b/goutil.go index afdab06..6ab770a 100644 --- a/goutil.go +++ b/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:]) } }