Skip to content

fix: share CLI flags between main parser and optimize subparser#2062

Open
mashraf-222 wants to merge 1 commit intomainfrom
fix/argparse-subparser-flag-isolation
Open

fix: share CLI flags between main parser and optimize subparser#2062
mashraf-222 wants to merge 1 commit intomainfrom
fix/argparse-subparser-flag-isolation

Conversation

@mashraf-222
Copy link
Copy Markdown
Contributor

Problem

30 CLI flags (--verbose, --no-pr, --file, --function, --all, --trace-only, etc.) were defined only on the main ArgumentParser. When using the optimize subparser path (codeflash optimize mvn test ...), these flags were silently dropped by argparse — the subparser didn't recognize them and they were treated as part of the Java command.

This broke virtually every flag for the optimize subparser path, which is the primary entry point for Java optimization.

Root Cause

_build_parser() in cli.py added all 30+ flags to the main parser only. The optimize subparser was created with subparsers.add_parser("optimize") but didn't inherit any of these flags.

Fix

Used argparse's parents=[] pattern:

  1. Created shared_flags = ArgumentParser(add_help=False) containing all shared flags
  2. Both the main parser and optimize subparser use parents=[shared_flags]
  3. Added --trace-only flag (was missing entirely)
  4. Aligned max_function_count default to 256 (was 100 on subparser vs 256 elsewhere)

Test Coverage

  • 10 new unit tests in tests/test_cli_args.py:
    • 7 tests verify flags work on the optimize subparser (--verbose, --no-pr, --file, --function, multiple flags, command isolation, max_function_count default)
    • 3 tests verify flags still work on the main parser path (no regression)

Testing

$ uv run pytest tests/test_cli_args.py -v
10 passed

30 CLI flags (--verbose, --no-pr, --file, --function, etc.) were defined
only on the main parser and silently dropped when using the `optimize`
subparser path. Uses argparse `parents=[]` pattern to share flags between
both parsers. Also adds --trace-only flag and aligns max_function_count
default to 256.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant