urfave-cli/cli.go

44 lines
709 B
Go
Raw Normal View History

2013-07-13 20:07:14 +00:00
package cli
import "os"
// The name of the program. Defaults to os.Args[0]
var Name = os.Args[0]
// Description of the program.
2013-07-15 00:37:43 +00:00
var Usage = "<No Description>"
// Version of the program
var Version = "0.0.0"
// List of commands to execute
var Commands []Command = nil
var DefaultAction = ShowHelp
func Run(args []string) {
2013-07-15 00:37:43 +00:00
if len(args) > 1 {
2013-07-15 00:53:59 +00:00
name := args[1]
for _, c := range append(Commands, HelpCommand) {
2013-07-15 01:00:03 +00:00
if c.Name == name || c.ShortName == name {
2013-07-15 00:53:59 +00:00
c.Action(name)
2013-07-15 00:37:43 +00:00
return
}
}
}
2013-07-14 15:15:40 +00:00
// Run default Action
2013-07-15 00:37:43 +00:00
DefaultAction("")
}
2013-07-14 15:15:40 +00:00
type Command struct {
Name string
ShortName string
Usage string
Description string
Action Action
}
type Action func(name string)