Fix strict-mode false positives for unset flags with default values#1882
Open
hexonal wants to merge 1 commit into
Open
Fix strict-mode false positives for unset flags with default values#1882hexonal wants to merge 1 commit into
hexonal wants to merge 1 commit into
Conversation
strict_check_long_flags used matches.contains_id(flag), which clap sets to true once a flag has been parsed and assigned *any* value - including its default - not just when the user actually passed it on the command line. This meant EZA_STRICT=true (or --strict) rejected even a bare `eza` invocation with no relevant flags at all. Switch to matches.value_source(flag) == Some(ValueSource::CommandLine), which only matches flags the user actually supplied, working uniformly for both boolean (SetTrue) and value-taking flags. Fixes eza-community#1874
hexonal
force-pushed
the
fix-strict-mode-false-positive
branch
from
July 21, 2026 03:01
694b3cc to
df2908a
Compare
Author
|
The |
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.
Fixes #1874
Problem
EZA_STRICT=true(or--strict) rejects even a bareezainvocation with no relevant flags at all —strict_check_long_flagsusesmatches.contains_id(flag)to check whether the user passed a flag that only makes sense with--long, but clap'scontains_idistrueonce a flag has been parsed and assigned any value, including its unset/default value, not just when the user actually supplied it on the command line.Fix
Switch to
matches.value_source(flag) == Some(ValueSource::CommandLine), which only matches flags the user actually supplied. This works uniformly for both boolean (SetTrue) and value-taking flags in the checked list (get_flagwould panic on the value-taking ones liketime/loc, which is whycontains_idwas presumably used originally).Testing
EZA_STRICT=true eza(bare invocation) now runs cleanly.-b/--binaryalone,--gitalone,--level 2alone (all under--strict), and that-l -btogether (long + binary, which is meaningful) still succeeds.Mode::strict_check_long_flagsdirectly: one asserting a bare invocation isOk(()), one asserting--binaryalone still errors. Confirmed the first test actually catches the regression by temporarily reverting just the source fix and re-running — it fails as expected, then passes again with the fix restored.options::test suite (124 tests) passes, no regressions.cargo fmt --checkclean on the changed file.cargo clippy --release -- -D warningsfails on an unrelated pre-existing issue inbuild.rs(auseless_borrows_in_formattinglint) — confirmed this exists identically on a clean, unmodifiedupstream/maincheckout, so it's a local clippy-version mismatch unrelated to this change, not something introduced here.