def find_cmd(extensions, search_term):
    candidates = []
    extensions.insert(0, 'default')
    for ext in extensions:
        cmds = HG_COMMANDS[ext]
        for name, cmd_data in cmds.items():
            if search_term in cmd_data.invocations:
                return cmd_data.invocations[search_term], cmd_data
                break
            elif search_term == name:
                return name, cmd_data
                break
            elif name.startswith(search_term):
                candidates.append((name, cmd_data))

    if len(candidates) == 1:
        return candidates[0]

    if len(candidates) > 1:
        raise AmbiguousCommandError
    else:
        raise CommandNotFoundError
dataset/ETHPy150Open guillermooo/Mercurial/shglib/commands.py/find_cmd/original