from typing import Any
import shlex


def reverse_docopt(program_name: str, args_map: dict[str, Any]) -> str:
    """
    Turns a docopt-style dict of arguments and flags into a string
    you would type into your shell (WIP)

    >>> reverse_docopt('prog', { '--ab': 4, '--bb': 'yes', '--cb': True, '--db': False, '--eb': ['5', 'fefez$$/./!**fe'], 'thingie': True, 'nothingie': False, 'SHOUT': ':thinking:' })
    "prog --ab --ab --ab --ab --bb=yes --cb --eb=5 --eb='fefez$$/./!**fe' thingie :thinking:"
    """
    line = [program_name]

    for key, value in args_map.items():
        # Arguments
        if not key.startswith("--"):
            # Strings in the command that are either present or not
            if type(value) is bool and value:
                line += [key]
            # Positional arguments
            elif type(value) is str:
                line += [value]
            continue
        # Flag with a value, but is not specified
        if value is None:
            continue
        # Flags with a value
        elif type(value) is str:
            line += [f"{key}={shlex.quote(value)}"]
        # Count (repeated value-less flag)
        elif type(value) is int:
            line += [key] * value
        # list (repeated flag with value)
        elif type(value) is list:
            line += [f"{key}={shlex.quote(str(v))}" for v in value]
        # Boolean (value-less flag, ony present if `True`)
        elif type(value) is bool and value:
            line += [key]

    return " ".join(line)