def migrate_impl_args(argv, migrate_args):
    """
    Given a list of arguments of the form:

        --foo --bar=baz -- --flim=flam

    And a list of arguments to migrate, return a list in which the arguments
    to migrate come before the '--' separator. For example, were we to migrate
    '--flim', we would return:

        --foo --bar=baz --flim=flam --

    Note that we do not attempt to remove the '--' separator if it is no longer
    necessary, nor do we replace '--flim' if it already appears before the
    separator. In these cases, argparse "does the right thing": it can handle
    a trailing separator, and when options that are specified twice argparse
    uses the second value.
    """
    try:
        split_index = argv.index('--')
    except ValueError:
        # If there is no separator, then we have nothing to migrate.
        return argv

    args = argv[:split_index]
    impl_args = argv[split_index:]
    impl_args_to_remove = []
    for impl_arg in impl_args:
        if impl_arg.split('=')[0] in migrate_args:
            args.append(impl_arg)
            impl_args_to_remove.append(impl_arg)

    for impl_arg_to_remove in impl_args_to_remove:
        impl_args.remove(impl_arg_to_remove)

    return args + impl_args