Getting help in there
This commit is contained in:
parent
04c645f6c6
commit
ef5944640e
32
cli.go
32
cli.go
@ -1,12 +1,33 @@
|
|||||||
package cli
|
package cli
|
||||||
|
|
||||||
type App struct {
|
type Application struct {
|
||||||
Name string
|
Name string
|
||||||
Usage string
|
Usage string
|
||||||
Action Action
|
Action Action
|
||||||
Commands []Command
|
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 {
|
type Command struct {
|
||||||
Name string
|
Name string
|
||||||
ShortName string
|
ShortName string
|
||||||
@ -16,12 +37,3 @@ type Command struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Action func(name string)
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user