fix: make -h/--human-readable actually apply - #1233
Open
VXNCXNX wants to merge 1 commit into
Open
Conversation
the flag was parsed and then referenced nowhere, so lsd -l --size bytes -h still printed raw bytes. Make -h and --size override each other so the later flag wins, which is what the rest of the CLI does. Closes lsd-rs#880.
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.
Closes #880.
The problem
-h/--human-readableis parsed and then never used:One hit, the declaration. Nothing reads it. So the flag has no effect at all:
The fix
Make
-hand--sizeoverride each other, so the later flag wins:This uses clap's
overrides_with, which the repo already relies on forall/almost_allin the same file, andargs_override_self = trueis already set on the struct, so it's the existing idiom rather than manual index comparison.--classicstill takes precedence over both, unchanged. Config-filesize:still works and the CLI still beats it:One change that needs a sentence
human_readablehad to becomepubsoflags/size.rscan read it, which lefthelp: ()as the struct's only private field, and that newly trips clippy'smanual_non_exhaustive. I madehelppubtoo, matching every other field.I checked whether this is a public API concern: it isn't. lsd has no lib target (only
[[bin]]in Cargo.toml) andmod app;is private inmain.rs, soCliis unreachable from outside the crate. The alternative clippy suggests,#[non_exhaustive], would be wrong here since clap needs the field.Tests
Four tests added to
flags/size.rs's existing test module, covering both orderings,--classicprecedence, and the config interaction.One integration test,
test_date_custom_format_supports_nanos_with_length, fails in my environment on a locale decimal separator. It fails identically on a clean checkout, so it's unrelated to this change.TODO
cargo fmt(cargo fmt --checkclean)flags/size.rs)-h/--human-readable; this makes the documented behaviour true rather than changing it)doc/samples(if applicable) (not applicable: no config key is added or changed, thesize:key is unchanged)doc/samples(if applicable) (not applicable: no icon change)doc/samples(if applicable) (not applicable: no color change)-h/--human-readable)Disclosure: written with AI assistance (Claude Code). I reproduced the issue, ran the change and the verification myself.