Skip to content

fix: make Java init respect --yes flag for non-interactive mode#1952

Open
mashraf-222 wants to merge 1 commit intomainfrom
cf-1086-java-init-yes-flag
Open

fix: make Java init respect --yes flag for non-interactive mode#1952
mashraf-222 wants to merge 1 commit intomainfrom
cf-1086-java-init-yes-flag

Conversation

@mashraf-222
Copy link
Copy Markdown
Contributor

Problem

codeflash init --yes for Java projects still prompts interactively. The --yes flag is defined in the CLI argument parser (cli.py:502) but never consumed by any init function — init_java_project() always calls should_modify_java_config() and collect_java_setup_info() which use Confirm.ask() and inquirer.prompt().

Root Cause

init_java_project() has no non_interactive parameter. The --yes flag from parse_args() is never threaded through main.pyinit_codeflash()init_java_project().

Fix

  1. main.py: Pass args.yes to init_codeflash(non_interactive=...)
  2. cmd_init.py: Thread non_interactive to init_java_project()
  3. init_java.py: When non_interactive=True, skip should_modify_java_config() and collect_java_setup_info() (both interactive), use JavaSetupInfo() defaults (all auto-detected values)

Validation

  • Unit tests confirm non-interactive mode uses auto-detected defaults and skips interactive prompts
  • uv run pytest tests/test_init_java.py -v — 2 tests pass

Test Coverage

  • tests/test_init_java.py (new) — TestInitJavaNonInteractive with 2 tests:
    • test_non_interactive_skips_prompts_and_uses_auto_detected — verifies auto-detected JavaSetupInfo defaults
    • test_non_interactive_skips_should_modify_check — verifies should_modify_java_config is not called

Closes CF-1086

The --yes CLI flag was defined but never consumed by init_java_project().
Thread non_interactive through main.py → init_codeflash() → init_java_project()
so that when --yes is set, auto-detected defaults are used without prompts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@claude
Copy link
Copy Markdown
Contributor

claude bot commented Apr 1, 2026

Claude finished @mashraf-222's task in 3m 3s —— View job


PR Review Summary

  • Triage PR size — SMALL (19 lines production code, 73 lines tests)
  • Lint and typecheck
  • Resolve stale threads — none found
  • Code review
  • Duplicate detection
  • Tests verified

Prek Checks

All checks pass (ruff check, ruff format). Two pre-existing mypy errors in init_java.py (_get_theme missing return type, _prompt_directory_override returning Any) — neither introduced by this PR.

Code Review

Behavior difference worth noting: In the interactive path, configure_java_project is only called when should_modify=True (i.e., no existing config, or the user confirmed overwriting it). In the non-interactive path, configure_java_project is always called — so --yes will silently overwrite any existing Java config. This is likely intentional for a "non-interactive" flag (accept all defaults, make no confirmations), but it's a one-way door and worth documenting in a comment. Fix this →

Minor: getattr(args, "yes", False) at main.py:65args.yes will always exist since --yes is defined in the parser. args.yes is cleaner, though the defensive form is harmless.

The core fix is correct: non_interactive is properly threaded main.py → cmd_init.py → init_java.py, both interactive prompt callsites (should_modify_java_config and collect_java_setup_info) are bypassed, and JavaSetupInfo() defaults yield the right values (all None overrides → auto-detect in configure_java_project).

Duplicate Detection

No duplicates detected. The non_interactive parameter follows the same pattern already used in init_codeflash for Python/JS paths.

Test Coverage

Both new tests pass. Tests correctly verify that:

  • should_modify_java_config is not called in non-interactive mode
  • configure_java_project receives a JavaSetupInfo with all-default values

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