Now can add descriptions for tools.
This commit is contained in:
parent
bb1d6be89a
commit
b7dbc364ea
2 changed files with 21 additions and 10 deletions
|
@ -8,13 +8,19 @@ import(
|
|||
|
||||
var(
|
||||
tools = multitool.Tools{
|
||||
"echo" : func(args []string) {
|
||||
fmt.Println(args)
|
||||
"echo" : multitool.Tool{
|
||||
func(args []string) {
|
||||
fmt.Println(args)
|
||||
},
|
||||
"print string to standard output string",
|
||||
},
|
||||
"sum" : func(args []string) {
|
||||
one, _ := strconv.Atoi(args[1])
|
||||
two, _ := strconv.Atoi(args[2])
|
||||
fmt.Println(one + two)
|
||||
"sum" : multitool.Tool{
|
||||
func(args []string) {
|
||||
one, _ := strconv.Atoi(args[1])
|
||||
two, _ := strconv.Atoi(args[2])
|
||||
fmt.Println(one + two)
|
||||
},
|
||||
"add one value to another",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
|
|
@ -6,8 +6,13 @@ import(
|
|||
"path"
|
||||
)
|
||||
|
||||
type Tool struct {
|
||||
Handler func(args []string)
|
||||
Desc string
|
||||
}
|
||||
|
||||
type Tools map[string] func(args []string)
|
||||
|
||||
type Tools map[string] Tool
|
||||
|
||||
func Main(name string, m Tools) {
|
||||
var(
|
||||
|
@ -20,8 +25,8 @@ func Main(name string, m Tools) {
|
|||
args = os.Args[:]
|
||||
} else {
|
||||
if len(os.Args)<2 {
|
||||
for k, _ := range m {
|
||||
fmt.Printf("%s\n", k)
|
||||
for k, v := range m {
|
||||
fmt.Printf("%s:\t%s\n", k, v.Desc)
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
|
@ -34,6 +39,6 @@ func Main(name string, m Tools) {
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
m[utilName](args)
|
||||
m[utilName].Handler(args)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue