code: func FindCommand(cmdline string) (*Command, *[]Command, []*Command, []string) {
  	var chain []*Command
  	var matches []Command
  	var next *Command
  	cmds := &commands
  
  	// Tokenise string.
  	cmdstr := strings.Fields(cmdline)
  	if len(cmdstr) == 0 {
  		return nil, cmds, chain, nil
  	}
  
  	for idx, subcmd := range cmdstr {
  		matches = make([]Command, 0)
  		next = nil
  		for i := range *cmds {
  			cmd := (*cmds)[i]
  			if strings.HasPrefix(cmd.Command, subcmd) {
  				matches = append(matches, cmd)
  				next = &cmd
  			}
  		}
  		if len(matches) == 0 {
  			// Sub command not found.
  			return nil, nil, chain, cmdstr[idx:]
  		} else if len(matches) > 1 {
  			// Ambiguious command.
  			return nil, &matches, chain, cmdstr[idx:]
  		}
  		chain = append(chain, next)
  		if next.function != nil {
  			// We've reached a function.
  			return next, nil, chain, cmdstr[idx+1:]
  		} else {
  			cmds = next.Subcommands
  		}
  	}
  	if next != nil {
  		return nil, next.Subcommands, chain, nil
  	}
  
  	return nil, nil, chain, nil
  }
docs: // FindCommand tokenises a command line and attempts to locate the
  // corresponding Command. If a matching command is found it is returned,
  // along with the remaining arguments. If the command has sub-commands then
  // the list of sub-commands is returned instead. A chain of matched commands
  // is also returned, along with the slice of remaining arguments.