import re


def wslpath(winpath):
    """
    Convert Windows path (or a command line argument containing a Windows path)
    to the equivalent WSL path (e.g. ``c:\\Users`` -> ``/mnt/c/Users``). Also supports
    paths in the form ``\\wsl$\\(distro)\\users\\...``

    :param winpath: Command line argument which may (or may not) contain a Windows path. It is assumed to be
                    either of the form <windows path> or --<arg>=<windows path>. Note that we don't need to
                    handle --arg <windows path> or -a <windows path> since in these cases the argument
                    and the path will be parsed as separate entities.
    :return: If ``winpath`` matches a Windows path, the converted argument (including the --<arg>= portion).
                Otherwise returns ``winpath`` unchanged.
    """
    match = re.match(r"^(--[\w-]+=)?\\\\wsl\$[\\\/][^\\^\/]+(.*)$", winpath)
    if match:
        arg, path = match.group(1, 2)
        if arg is None:
            arg = ""
        return arg + path.replace("\\", "/")

    match = re.match(r"^(--[\w-]+=)?([a-zA-z]):(.+)$", winpath)
    if match:
        arg, drive, path = match.group(1, 2, 3)
        if arg is None:
            arg = ""
        return arg + "/mnt/" + drive.lower() + path.replace("\\", "/")

    return winpath