mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-20 19:19:06 +08:00
commands: s/j/valueIndex/
This commit is contained in:

committed by
Juan Batiz-Benet

parent
eedc2e9cc7
commit
50751617b6
@ -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 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
|
Reference in New Issue
Block a user