Returns the quote format depending on the quote_mode.
    This determines if the key value will be quoted when written to
    the env file.

    :param value:
    :param quote_mode:
    :return: str
    :raises: KeyError if the quote_mode is unknown

def _get_format(value, quote_mode='always'):
    """
    Returns the quote format depending on the quote_mode.
    This determines if the key value will be quoted when written to
    the env file.

    :param value:
    :param quote_mode:
    :return: str
    :raises: KeyError if the quote_mode is unknown
    """

    formats = {'always': '{key}="{value}"\n', 'auto': '{key}={value}\n'}

    if quote_mode not in formats.keys():
        return KeyError(f'quote_mode {quote_mode} is invalid')

    _mode = quote_mode
    if quote_mode == 'auto' and ' ' in value:
        _mode = 'always'
    return formats.get(_mode)