import six


def get_command_line_configuration(configuration_schema, command_line_options):
    """Get configuration, based on the given arguments to the program.

    Notes:
        * The first argument is omitted, as it's the script path.
        * Both '--option=value' and '--option value' formats are supported.
        * Both '--<option>' and '-<option>' formats are supported.

    Args:
        configuration_schema (dict): a match between each target option to its
            sources.
        command_line_options (iterable): the program arguments, as given by
            `sys.argv`.

    Returns:
        dict: a match between each target option to the given value.
    """
    # Omitting the first argument, which is the script path
    command_line_options = command_line_options[1:]

    # Replacing every form of '--option=value' to '--option value'
    command_line_options = " ".join(command_line_options)
    command_line_options = command_line_options.replace("=", " ")
    command_line_options = command_line_options.split(" ")

    configuration = {}
    for command_line_option, value in zip(command_line_options[::2],
                                          command_line_options[1::2]):
        if (not command_line_option.startswith("--") and
                not command_line_option.startswith("-")):
            pass

        for target, option in six.iteritems(configuration_schema):
            if command_line_option in option.command_line_options:
                configuration[target] = value

    return configuration