urfave-cli/cli.go

44 lines
742 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(arguments []string) {
2013-07-17 02:59:04 +00:00
2013-07-19 00:39:42 +00:00
set := flagSet(Flags)
set.Parse(arguments[1:])
2013-07-17 02:59:04 +00:00
context := NewContext(set, set)
args := context.Args()
if len(args) > 0 {
name := args[0]
2013-07-15 00:53:59 +00:00
for _, c := range append(Commands, HelpCommand) {
2013-07-19 02:30:18 +00:00
if c.HasName(name) {
2013-07-19 02:23:00 +00:00
c.Run(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 Handler func(context *Context)