Get one value from environment variable(s).

    :raise KeyError: If option not in environment variables.

    :param str key: Option long name (e.g. --config).
    :param str env_prefix: Variable name prefix from docoptcfg().
    :param bool boolean: Is this a boolean/flag option?
    :param bool repeatable: Is this option repeatable?

    :return: Value to set in the defaults dict. May be int, iter, string, or bool.

def get_env(key, env_prefix, boolean, repeatable):
    """Get one value from environment variable(s).

    :raise KeyError: If option not in environment variables.

    :param str key: Option long name (e.g. --config).
    :param str env_prefix: Variable name prefix from docoptcfg().
    :param bool boolean: Is this a boolean/flag option?
    :param bool repeatable: Is this option repeatable?

    :return: Value to set in the defaults dict. May be int, iter, string, or bool.
    """
    env_name = '{0}{1}'.format(env_prefix, key[2:].replace('-', '_').upper())

    # Handle repeatable non-boolean options (e.g. --file=file1.txt --file=file2.txt).
    if repeatable and not boolean:
        values = list()
        if env_name in os.environ:  # Optional variable not ending with integer.
            values.append(os.environ[env_name])
        for i in range(99):
            env_name_i = '{0}{1}'.format(env_name, i)  # Loop until variable with integer not found.
            if env_name_i not in os.environ:
                break
            values.append(os.environ[env_name_i])
        if not values:
            raise KeyError(env_name)  # Nothing found.
        return values

    if env_name not in os.environ:
        raise KeyError(env_name)

    # Handle repeatable booleans.
    if repeatable and boolean:
        try:
            return int(os.environ[env_name])
        except (TypeError, ValueError):
            return 0

    # Handle the rest.
    if boolean:
        return os.environ[env_name].strip().lower() in ('true', 'yes', 'on', '1')
    return os.environ[env_name]