Repository: carbon-language/carbon-lang
File: toolchain/autoupdate_testdata.py (Python)

Code before:
        [
            bazel,
            "info",
            "workspace",
            "--ui_event_filters=stdout",
        ],
        encoding="utf-8",
    ).strip()
    bazel_bin_path = Path(workspace).joinpath("bazel-bin")
    if bazel_bin_path.exists():
        link = str(bazel_bin_path.readlink())
        m = re.search(r"-(\w+)/bin$", link)
        if m:
            build_mode = m[1]
        else:
            exit(f"Build mode not found in `bazel-bin` symlink: {link}")

    # TODO: Add proper argument parsing.
    if "--allow-check-fail" in args:
        if build_mode == "opt":
            exit(
                "`--allow-check-fail` is incompatible with inferred "
                "`-c opt` build mode"
            )
        configs.append("--config=non-fatal-checks")
        args = [arg for arg in args if arg != "--allow-check-fail"]

    argv = [
        bazel,
        "run",
        "-c",
        build_mode,
        *configs,
        "--experimental_convenience_symlinks=ignore",
        "--ui_event_filters=-info,-stdout,-stderr,-finish",
        "//toolchain/testing:file_test",
        "--",
        "--autoupdate",
    ]
    # Support specifying tests to update, such as:
    # ./autoupdate_testdata.py lex/**/*
    if len(args) > 1:
        repo_root = Path(__file__).parents[1]
        file_tests = []
        # Filter down to just test files.
        for f in args[1:]:
            if f.endswith(".carbon"):
                path = str(Path(f).resolve().relative_to(repo_root))
                if path.count("/testdata/"):
                    file_tests.append(path)
        if not file_tests:

Review comment (bug):
If you want to address this here, I think it's something like:

```suggestion
    # Parse arguments.
    parser = argparse.ArgumentParser(__doc__)
    parser.add_argument("--allow-check-fail", action="store_true")
    parser.add_argument("files", nargs="+")
    args = parser.parse_args()
  
    if args.allow_check_fail:
        if build_mode == "opt":
            exit(
                "`--allow-check-fail` is incompatible with inferred "
                "`-c opt` build mode"
            )
        configs.append("--config=non-fatal-checks")
```

And below, `sys.argv` becomes `args.files`... note this drops the need to pass `args` into `main`, adds `import argparse`

Code after:
    workspace = subprocess.check_output(
        [
            bazel,
            "info",
            "workspace",
            "--ui_event_filters=stdout",
        ],
        encoding="utf-8",
    ).strip()
    bazel_bin_path = Path(workspace).joinpath("bazel-bin")
    if bazel_bin_path.exists():
        link = str(bazel_bin_path.readlink())
        m = re.search(r"-(\w+)/bin$", link)
        if m:
            build_mode = m[1]
        else:
            exit(f"Build mode not found in `bazel-bin` symlink: {link}")

    # Parse arguments.
    parser = argparse.ArgumentParser(__doc__)
    parser.add_argument("--non-fatal-checks", action="store_true")
    parser.add_argument("files", nargs="*")
    args = parser.parse_args()

    if args.allow_check_fail:
        if build_mode == "opt":
            exit(
                "`--non-fatal-checks` is incompatible with inferred "
                "`-c opt` build mode"
            )
        configs.append("--config=non-fatal-checks")

    argv = [
        bazel,
        "run",
        "-c",
        build_mode,
        *configs,
        "--experimental_convenience_symlinks=ignore",
        "--ui_event_filters=-info,-stdout,-stderr,-finish",
        "//toolchain/testing:file_test",
        "--",
        "--autoupdate",
    ]
    # Support specifying tests to update, such as:
    # ./autoupdate_testdata.py lex/**/*
    if args.files:
        repo_root = Path(__file__).parents[1]
        file_tests = []
        # Filter down to just test files.
        for f in args.files: