diff --git a/command.go b/command.go index 73d009f7..61f2104a 100644 --- a/command.go +++ b/command.go @@ -239,11 +239,19 @@ func (c *Command) Find(arrs []string) (*Command, []string, error) { innerfind = func(c *Command, args []string) (*Command, []string) { if len(args) > 0 && c.HasSubCommands() { + matches := make([]*Command, 0) for _, cmd := range c.commands { - if cmd.Name() == args[0] { + if cmd.Name() == args[0] { // exact name match return innerfind(cmd, args[1:]) + } else if strings.HasPrefix(cmd.Name(), args[0]) { // prefix match + matches = append(matches, cmd) } } + + // only accept a single prefix match - multiple matches would be ambiguous + if len(matches) == 1 { + return innerfind(matches[0], args[1:]) + } } return c, args