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

commands: Formatted code

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