urfave-cli/cli.go

52 lines
869 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
2013-07-15 02:16:30 +00:00
var Commands []Command
2013-07-15 02:16:30 +00:00
var Flags []Flag
// The action to execute when no subcommands are specified
var Action = ShowHelp
func Run(args []string) {
2013-07-17 02:59:04 +00:00
set := flagSet(Flags)
set.Parse(args[1:])
context := Context{}
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 {
c.Action(context)
2013-07-15 00:37:43 +00:00
return
}
}
}
2013-07-14 15:15:40 +00:00
// Run default Action
Action(context)
}
2013-07-14 15:15:40 +00:00
type Command struct {
Name string
ShortName string
Usage string
Description string
Action Handler
2013-07-17 02:59:04 +00:00
Flags []Flag
}
type Handler func(context Context)