Turning cli into a package
This commit is contained in:
parent
e830a4195e
commit
372b86498f
36
cli.go
36
cli.go
@ -1,38 +1,4 @@
|
|||||||
package main
|
package cli
|
||||||
|
|
||||||
import "os"
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
App{
|
|
||||||
Name: "math",
|
|
||||||
Description: "a simple command line math utility",
|
|
||||||
Commands: []Command{{
|
|
||||||
Name: "add",
|
|
||||||
Description: "Add 2 and 2",
|
|
||||||
Action: func(name string) {
|
|
||||||
println("2+2=", 2+2)
|
|
||||||
},
|
|
||||||
}, {
|
|
||||||
Name: "subtract",
|
|
||||||
Description: "Subtract 2 and 2",
|
|
||||||
Action: func(name string) {
|
|
||||||
println("2-2=", 2-2)
|
|
||||||
},
|
|
||||||
}, {
|
|
||||||
Name: "multiply",
|
|
||||||
Description: "Multiply 2 and 2",
|
|
||||||
Action: func(name string) {
|
|
||||||
println("2*2=", 2*2)
|
|
||||||
},
|
|
||||||
}, {
|
|
||||||
Name: "divide",
|
|
||||||
Description: "Divide 2 and 2",
|
|
||||||
Action: func(name string) {
|
|
||||||
println("2/2=", 2/2)
|
|
||||||
},
|
|
||||||
}},
|
|
||||||
}.Run(os.Args[1])
|
|
||||||
}
|
|
||||||
|
|
||||||
type App struct {
|
type App struct {
|
||||||
Name string
|
Name string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user