提交 50751617 作者: Matt Bell 提交者: Juan Batiz-Benet

commands: s/j/valueIndex/

上级 eedc2e9c
...@@ -167,18 +167,18 @@ func (c *Command) CheckArguments(req Request) error { ...@@ -167,18 +167,18 @@ func (c *Command) CheckArguments(req Request) error {
} }
// iterate over the arg definitions // iterate over the arg definitions
j := 0 valueIndex := 0 // the index of the current value (in `args`)
for _, argDef := range c.Arguments { for _, argDef := range c.Arguments {
// skip optional argument definitions if there aren't sufficient remaining values // skip optional argument definitions if there aren't sufficient remaining values
if len(args)-j <= numRequired && !argDef.Required { if len(args)-valueIndex <= numRequired && !argDef.Required {
continue continue
} }
// the value for this argument definition. can be nil if it wasn't provided by the caller // the value for this argument definition. can be nil if it wasn't provided by the caller
var v interface{} var v interface{}
if j < len(args) { if valueIndex < len(args) {
v = args[j] v = args[valueIndex]
j++ valueIndex++
} }
err := checkArgValue(v, argDef) err := checkArgValue(v, argDef)
...@@ -187,8 +187,8 @@ func (c *Command) CheckArguments(req Request) error { ...@@ -187,8 +187,8 @@ func (c *Command) CheckArguments(req Request) error {
} }
// any additional values are for the variadic arg definition // any additional values are for the variadic arg definition
if argDef.Variadic && j < len(args)-1 { if argDef.Variadic && valueIndex < len(args)-1 {
for _, val := range args[j:] { for _, val := range args[valueIndex:] {
err := checkArgValue(val, argDef) err := checkArgValue(val, argDef)
if err != nil { if err != nil {
return err return err
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论