Getting help in there

This commit is contained in:
Jeremy Saenz 2013-07-14 08:15:40 -07:00
parent 04c645f6c6
commit ef5944640e

32
cli.go
View File

@ -1,12 +1,33 @@
package cli
type App struct {
type Application struct {
Name string
Usage string
Action Action
Commands []Command
}
func (a *Application) Run(args []string) {
help := Command{
Name: "help",
Usage: "View help topics",
Action: func(name string) {
println("usage: " + a.Name + " [global-options] COMMAND [command-options]")
},
}
command := args[1]
for _, c := range a.Commands {
if c.Name == command {
c.Action(command)
return
}
}
// Run default action
help.Action("foo")
}
type Command struct {
Name string
ShortName string
@ -16,12 +37,3 @@ type Command struct {
}
type Action func(name string)
func (a App) Run(args []string) {
command := args[1]
for _, c := range a.Commands {
if c.Name == command {
c.Action(command)
}
}
}