Consolidate mutually exclusive flag validation with helper#96
Merged
Conversation
…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
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 inaai_cli/errors.py. The function accepts flag name/value pairs, raisesUsageErrorwhen more than one flag is set (truthy), and automatically formats the error message with proper grammar (including Oxford comma for 3+ flags).Key Changes
mutually_exclusive()function inaai_cli/errors.py: Detects which flags are set (truthy values) and raisesUsageErrorwith a formatted message listing conflicting flags. Supports optional suggestion text.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()"--flag1 and --flag2 can't be combined.")mutually_exclusive()covering: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