Got a semi working command line setup.
This commit is contained in:
parent
460c0de4ea
commit
360e387071
10
cli.go
10
cli.go
@ -1,5 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "os"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := App{
|
app := App{
|
||||||
Name: "math",
|
Name: "math",
|
||||||
@ -22,7 +24,7 @@ func main() {
|
|||||||
Description: "Divide 2 and 2",
|
Description: "Divide 2 and 2",
|
||||||
Action: DoDivide}}}
|
Action: DoDivide}}}
|
||||||
|
|
||||||
app.Run("add")
|
app.Run(os.Args[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
func DoAdd(name string) {
|
func DoAdd(name string) {
|
||||||
@ -56,5 +58,9 @@ type Command struct {
|
|||||||
type Action func(name string)
|
type Action func(name string)
|
||||||
|
|
||||||
func (a App) Run(command string) {
|
func (a App) Run(command string) {
|
||||||
a.Commands[0].Action(a.Commands[0].Name)
|
for _, c := range a.Commands {
|
||||||
|
if(c.Name == command) {
|
||||||
|
c.Action(command)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user