Skip to content
Myr

Finding command based on args cleaned up

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by spf13 · committed by spf13 · parent 74ce44d · Browse files · 1 file+22 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+22 added−10 removed

  • other:+22 added−10 removed

1 file+22 added−10 removed

modified:command.go+22 added-10 removed
75 unmodified lines
76}7778// find the target command given the args and command tree79// Meant to be run on the highest node. Only searches down.80func (c *Command) Find(args []string) (cmd *Command, a []string, err error) {80func (c *Command) Find(arrs []string) (*Command, []string, error) {81 if c == nil {82 return nil, nil, fmt.Errorf("Called find() on a nil Command")83 }8485 validSubCommand := false86 if len(args) > 0 && c.HasSubCommands() {87 for _, cmd := range c.commands {88 if cmd.Name() == args[0] {89 validSubCommand = true90 return cmd.Find(args[1:])85 if len(arrs) == 0 {86 return c.Commander().cmd, arrs, nil87 }8889 var innerfind func(*Command, []string) (*Command, []string)9091 innerfind = func(c *Command, args []string) (*Command, []string) {92 if len(args) > 0 && c.HasSubCommands() {93 for _, cmd := range c.commands {94 if cmd.Name() == args[0] {95 return innerfind(cmd, args[1:])96 }97 }98 }99100 return c, args101 }94 if !validSubCommand && c.Runnable() {95 return c, args, nil102103 commandFound, a := innerfind(c, arrs)104105 // if commander returned and not appropriately matched return nil & error106 if commandFound.Name() == c.Name() && commandFound.Name() != arrs[0] {107 return nil, a, fmt.Errorf("Command not found")108 }10998 return nil, nil, nil110 return commandFound, a, nil111}112113func (c *Command) Root() *Command {114 var findRoot func(*Command) *Command
307 unmodified lines