def get_matching_alias(command):
    """
    Find a matching ActionAliasDB object (if any) for the provided command.
    """
    # 1. Get aliases
    action_alias_dbs = ActionAlias.query(
        Q(formats__match_multiple=None) | Q(formats__match_multiple=False), enabled=True
    )

    # 2. Match alias(es) to command
    matches = match_command_to_alias(command=command, aliases=action_alias_dbs)

    if len(matches) > 1:
        raise ActionAliasAmbiguityException(
            "Command '%s' matched more than 1 pattern" % command,
            matches=matches,
            command=command,
        )
    elif len(matches) == 0:
        match_multiple_action_alias_dbs = ActionAlias.query(
            formats__match_multiple=True, enabled=True
        )

        matches = match_command_to_alias(
            command=command,
            aliases=match_multiple_action_alias_dbs,
            match_multiple=True,
        )

        if len(matches) > 1:
            raise ActionAliasAmbiguityException(
                "Command '%s' matched more than 1 (multi) pattern" % command,
                matches=matches,
                command=command,
            )

        if len(matches) == 0:
            raise ActionAliasAmbiguityException(
                "Command '%s' matched no patterns" % command,
                matches=[],
                command=command,
            )

    return matches[0]

    Find a matching ActionAliasDB object (if any) for the provided command.
    
st2common/st2common/util/actionalias_matching.py