You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
672 B

package cli
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
Usage string
Description string
Action Action
}
type Action func(name string)