Using anon functions and calling run altogether
This commit is contained in:
parent
6efb9862ea
commit
994660f605
38
cli.go
38
cli.go
@ -3,45 +3,35 @@ package main
|
|||||||
import "os"
|
import "os"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := App{
|
App{
|
||||||
Name: "math",
|
Name: "math",
|
||||||
Description: "a simple command line math utility",
|
Description: "a simple command line math utility",
|
||||||
Commands: []Command{{
|
Commands: []Command{{
|
||||||
Name: "add",
|
Name: "add",
|
||||||
Description: "Add 2 and 2",
|
Description: "Add 2 and 2",
|
||||||
Action: DoAdd,
|
Action: func(name string) {
|
||||||
|
println("2+2=", 2+2)
|
||||||
|
},
|
||||||
}, {
|
}, {
|
||||||
Name: "subtract",
|
Name: "subtract",
|
||||||
Description: "Subtract 2 and 2",
|
Description: "Subtract 2 and 2",
|
||||||
Action: DoSubtract,
|
Action: func(name string) {
|
||||||
|
println("2-2=", 2-2)
|
||||||
|
},
|
||||||
}, {
|
}, {
|
||||||
Name: "multiply",
|
Name: "multiply",
|
||||||
Description: "Multiply 2 and 2",
|
Description: "Multiply 2 and 2",
|
||||||
Action: DoMultiply,
|
Action: func(name string) {
|
||||||
|
println("2*2=", 2*2)
|
||||||
|
},
|
||||||
}, {
|
}, {
|
||||||
Name: "divide",
|
Name: "divide",
|
||||||
Description: "Divide 2 and 2",
|
Description: "Divide 2 and 2",
|
||||||
Action: DoDivide,
|
Action: func(name string) {
|
||||||
|
println("2/2=", 2/2)
|
||||||
|
},
|
||||||
}},
|
}},
|
||||||
}
|
}.Run(os.Args[1])
|
||||||
|
|
||||||
app.Run(os.Args[1])
|
|
||||||
}
|
|
||||||
|
|
||||||
func DoAdd(name string) {
|
|
||||||
println("2+2=", 2+2)
|
|
||||||
}
|
|
||||||
|
|
||||||
func DoSubtract(name string) {
|
|
||||||
println("2-2=", 2-2)
|
|
||||||
}
|
|
||||||
|
|
||||||
func DoMultiply(name string) {
|
|
||||||
println("2*2=", 2*2)
|
|
||||||
}
|
|
||||||
|
|
||||||
func DoDivide(name string) {
|
|
||||||
println("2/2=", 2/2)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type App struct {
|
type App struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user