dedupe: replace 5 duplicated flag-check functions with unified registry#819
Merged
Conversation
Extract a single declarative FlagDef registry (src/flag_registry.rs) that serves all flag-inspection, --from-curl, and websocket conflict validators. Each flag is defined once with its name, category, predicate, and per-context boolean inclusion tags. - Removes ~250 lines of duplicated flag-checking code from app.rs, inspection.rs, and dns/inspect.rs. - inspection.rs: 117 → 28 lines (-76%). - app.rs: ConflictRule enum + both validation functions 210 → 42 lines (-80%). - dns/inspect.rs: manual TLS/http-version checks replaced with registry categories. - Preserves WebSocket-specific --retry 0 behavior via optional is_ws_conflict predicate. - Excludes --dns-server from DNS inspection ignored flags (it selects the resolver). - Updates tests for separate --data/--json/--xml and --compress/--no-encode naming.
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.
Summary
Replace ~250 lines of duplicated flag-checking code spread across 5 functions with a single declarative flag registry.
Before
Three nearly-identical "iterate over Cli fields and check if set" patterns existed:
append_shared_ignored_request_flagsappend_shared_ignored_auth_flagsappend_shared_ignored_response_flagsvalidate_from_curl_exclusivesvalidate_websocket_exclusivesEach structurally identical — check
cli.field.is_some(), push a string.After
A single
src/flag_registry.rsdefines every flag once with name, category, predicate, and per-context boolean inclusion tags. Each use case filters the same registry.Details
--retry 0behavior via optionalis_ws_conflictpredicate--dns-serverfrom DNS inspection ignored flags (it selects the resolver)--inspect-dns --dns-servernot being reported as ignored--data) instead of combined groups (--data/--json/--xml)Validation
cargo fmt --check— cleancargo clippy --locked --all-targets --all-features -- -D warnings— clean