Always match commands before arguments.
This commit is contained in:
+6
-5
@@ -264,11 +264,9 @@ func (c *Context) trace(node *Node) (err error) { // nolint: gocyclo
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// After positional arguments have been consumed, handle commands and branching arguments.
|
// After positional arguments have been consumed, check commands next...
|
||||||
for _, branch := range node.Children {
|
for _, branch := range node.Children {
|
||||||
switch branch.Type {
|
if branch.Type == CommandNode && branch.Name == token.Value {
|
||||||
case CommandNode:
|
|
||||||
if branch.Name == token.Value {
|
|
||||||
c.scan.Pop()
|
c.scan.Pop()
|
||||||
c.Path = append(c.Path, &Path{
|
c.Path = append(c.Path, &Path{
|
||||||
Parent: node,
|
Parent: node,
|
||||||
@@ -278,8 +276,11 @@ func (c *Context) trace(node *Node) (err error) { // nolint: gocyclo
|
|||||||
})
|
})
|
||||||
return c.trace(branch)
|
return c.trace(branch)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
case ArgumentNode:
|
// Finally, check arguments.
|
||||||
|
for _, branch := range node.Children {
|
||||||
|
if branch.Type == ArgumentNode {
|
||||||
arg := branch.Argument
|
arg := branch.Argument
|
||||||
if value, err := arg.Parse(c.scan); err == nil {
|
if value, err := arg.Parse(c.scan); err == nil {
|
||||||
c.Path = append(c.Path, &Path{
|
c.Path = append(c.Path, &Path{
|
||||||
|
|||||||
Reference in New Issue
Block a user