Skip to content

fix: use last occurrence in combined short flags - #3897

Open
cuishuang wants to merge 2 commits into
sharkdp:masterfrom
cuishuang:master
Open

fix: use last occurrence in combined short flags#3897
cuishuang wants to merge 2 commits into
sharkdp:masterfrom
cuishuang:master

Conversation

@cuishuang

Copy link
Copy Markdown

Summary

Use the last occurrence of -p, -n, and -b when determining the effective option in combined short arguments.

The raw argument scanner currently uses Iterator::position, which finds the first occurrence of each flag. This works for combinations such as -pn and -np, but produces incorrect results when a flag occurs more than once.

For example, -npn ends with -n, so numbering should be enabled. The scanner currently compares the first n with p and incorrectly allows the loop-through printer to be selected, which drops the requested line numbers.

The same issue affects -b combinations:

  • -pbp should use plain output.
  • -bpb should number non-blank lines.

-pnp already produces plain output through clap's option handling, but the raw scan still selects the wrong internal printing path.

Switch the scans to rposition() and add regression coverage for all four combinations. The existing rule that -b takes precedence over -n remains unchanged.

Tests

  • cargo test --test integration_tests
  • cargo fmt --all -- --check

Signed-off-by: cuishuang <imcusg@gmail.com>
Signed-off-by: cuishuang <imcusg@gmail.com>
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.

1 participant