Skip to content

Consolidate mutually exclusive flag validation with helper#96

Merged
alexkroman merged 3 commits into
mainfrom
claude/laughing-shannon-isb317
Jun 12, 2026
Merged

Consolidate mutually exclusive flag validation with helper#96
alexkroman merged 3 commits into
mainfrom
claude/laughing-shannon-isb317

Conversation

@alexkroman

Copy link
Copy Markdown
Collaborator

Introduce a mutually_exclusive() helper function to standardize validation of conflicting CLI flags across the codebase, replacing repetitive manual checks with a single declarative call.

Summary

This change extracts the common pattern of "these flags can't be used together" into a reusable mutually_exclusive() function in aai_cli/errors.py. The function accepts flag name/value pairs, raises UsageError when more than one flag is set (truthy), and automatically formats the error message with proper grammar (including Oxford comma for 3+ flags).

Key Changes

  • New mutually_exclusive() function in aai_cli/errors.py: Detects which flags are set (truthy values) and raises UsageError with a formatted message listing conflicting flags. Supports optional suggestion text.
  • Refactored validation functions across multiple modules to use the helper:
    • aai_cli/transcribe_exec.py: validate_language_flags(), validate_out_with_llm(), validate_json_with_output()
    • aai_cli/streaming/session.py: validate_output_flags(), validate_sources()
    • aai_cli/transcribe_batch.py: reject_single_source_flags()
  • Updated test assertions to match the new standardized error message format (e.g., "--flag1 and --flag2 can't be combined.")
  • Added comprehensive unit tests for mutually_exclusive() covering:
    • Two conflicting flags with custom suggestion
    • Three+ flags with Oxford comma formatting
    • Filtering out unset (falsy) flags from the message
    • Allowing zero or one set flag without raising

Implementation Details

The function treats a flag as "set" if its value is truthy (None, False, "", [] all mean "not passed"). This matches how CLI option values are typically passed. Error messages automatically use proper English grammar: "A and B", "A, B, and C", etc. The helper reduces code duplication and ensures consistent error messaging across all flag conflict checks.

https://claude.ai/code/session_01CvoQw4jJCXEee6x21HX8Mr

…dators

gh-style typed flag-conflict primitive: mutually_exclusive() names every
set flag in one "X and Y can't be combined." UsageError (exit 2), with the
per-site rationale carried in the suggestion. Collapses the one-off checks
in validate_language_flags, validate_out_with_llm, validate_json_with_output,
reject_single_source_flags, validate_output_flags, and validate_sources,
so the conflict-detection logic is tested (and mutation-covered) once.

https://claude.ai/code/session_01CvoQw4jJCXEee6x21HX8Mr
@alexkroman alexkroman enabled auto-merge (squash) June 12, 2026 03:37
claude and others added 2 commits June 12, 2026 03:43
Resolves the import conflict in aai_cli/streaming/session.py: main added
APIError to the errors import, this branch added mutually_exclusive; keep both.

https://claude.ai/code/session_01CvoQw4jJCXEee6x21HX8Mr
@alexkroman alexkroman merged commit c673e65 into main Jun 12, 2026
12 checks passed
@alexkroman alexkroman deleted the claude/laughing-shannon-isb317 branch June 12, 2026 03:51
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.

2 participants