def METHOD_NAME(parser, args, config=None):
    if config is None:
        config = conf.config
    to_restore = []
    try:
        for path, cfg, cmdline in _iter_cmdline_config(config):
            old_value = cfg.get_value()
            new_value = cmdline.update_value(old_value, args)
            if new_value != old_value:
                to_restore.append((path, cfg.get_value()))
                try:
                    config.assign_path(path, new_value, deduce_type=True, default_type=str)
                except ValueError:
                    parser.error('Invalid value for {}: {!r}'.format(cmdline, new_value))
        for override in args.config_overrides:
            if "=" not in override:
                parser.error("Invalid config override: {}".format(override))
            path, _ = override.split("=", 1)
            to_restore.append((path, config.get_path(path)))
            try:
                config.assign_path_expression(override, deduce_type=True, default_type=str)
            except ValueError:
                parser.error("Invalid value for config override: {}".format(override))
        yield
    finally:
        for path, prev_value in reversed(to_restore):
            config.assign_path(path, prev_value)