提交 4f06c6fd 作者: Matt Bell 提交者: Juan Batiz-Benet

commands: Formatted code

上级 d2176c05
package commands
import (
"errors"
"fmt"
"strings"
"errors"
)
type Command struct {
......@@ -49,7 +49,7 @@ func (c *Command) Call(req *Request) *Response {
}
cmd := cmds[len(cmds)-1]
if(cmd.f == nil) {
if cmd.f == nil {
res.SetError(NotCallableError, Client)
return res
}
......@@ -73,7 +73,7 @@ func (c *Command) Call(req *Request) *Response {
// Resolve gets the subcommands at the given path
func (c *Command) Resolve(path []string) ([]*Command, error) {
cmds := make([]*Command, len(path) + 1)
cmds := make([]*Command, len(path)+1)
cmds[0] = c
cmd := c
......@@ -96,7 +96,7 @@ func (c *Command) Get(path []string) (*Command, error) {
if err != nil {
return nil, err
}
return cmds[len(cmds) - 1], nil
return cmds[len(cmds)-1], nil
}
// GetOptions gets the options in the given path of commands
......
......@@ -149,7 +149,7 @@ func TestResolving(t *testing.T) {
cmdA.Register("b", cmdB)
cmdB.Register("c", cmdC)
cmds, err := cmd.Resolve([]string{"a","b","c"})
cmds, err := cmd.Resolve([]string{"a", "b", "c"})
if err != nil {
t.Error(err)
}
......
......@@ -33,21 +33,22 @@ func (r *Request) Arguments() []string {
return r.arguments
}
type converter func(string)(interface{}, error)
type converter func(string) (interface{}, error)
var converters map[reflect.Kind]converter = map[reflect.Kind]converter{
Bool: func(v string)(interface{}, error) {
Bool: func(v string) (interface{}, error) {
if v == "" {
return true, nil
}
return strconv.ParseBool(v)
},
Int: func(v string)(interface{}, error) {
Int: func(v string) (interface{}, error) {
return strconv.ParseInt(v, 0, 32)
},
Uint: func(v string)(interface{}, error) {
Uint: func(v string) (interface{}, error) {
return strconv.ParseInt(v, 0, 32)
},
Float: func(v string)(interface{}, error) {
Float: func(v string) (interface{}, error) {
return strconv.ParseFloat(v, 64)
},
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论