import re


def argv_to_pairs(argv):
    """Convert a argv list to key value pairs. For example,
    -x 10 -y 20 -z=100
    {x: 10, y: 20, z: 100}
    """

    arg_dict = {}

    i = 0
    while i < len(argv):
        if argv[i].startswith('-'):
            entry = re.sub('-+', '', argv[i])

            items = entry.split('=')  # handle the case '-z=100'
            if len(items) == 2:
                key = items[0]
                value = items[1]
                i += 1
            else:  # handle the case  '-x 10'
                key = entry
                value = argv[i + 1]
                i += 2

            if key in arg_dict:
                raise ValueError(
                    'You cannot specify a key multiple'
                    'times in commandline, {}'.format(key))

            arg_dict[key] = value
        else:
            raise ValueError(
                'argv in wrong format, the key must be started'
                'with - or --, but found {}'.format(argv[i]))

    return arg_dict