Skip to content

fix: match short flags when ShortPrefix and LongPrefix are identical (#26) - #197

Open
terrabeckhub wants to merge 2 commits into
Taywee:masterfrom
terrabeckhub:fix/windows-slash-prefix-26
Open

fix: match short flags when ShortPrefix and LongPrefix are identical (#26)#197
terrabeckhub wants to merge 2 commits into
Taywee:masterfrom
terrabeckhub:fix/windows-slash-prefix-26

Conversation

@terrabeckhub

Copy link
Copy Markdown

Summary

Fixes Windows-style identical / short and long prefixes so /h matches short flags (#26).

When ShortPrefix("/") and LongPrefix("/") are the same, every flag looked both short and long. The previous rule preferred the long form, so /h was parsed as a long flag named h and failed even though a short h existed.

Change

If the prefixes are identical, prefer ShortFlag when the next character is a registered short flag (covers /h and joined values like /ifile.txt); otherwise keep LongFlag for names like /help.

Test

Adds test/windows_slash_prefix.cxx.

Closes #26

…aywee#26)

Signed-off-by: terrabeckhub <terrabeckhub@users.noreply.github.com>
…aywee#26)

Signed-off-by: terrabeckhub <terrabeckhub@users.noreply.github.com>
@Taywee

Taywee commented Aug 14, 2026

Copy link
Copy Markdown
Owner

I'm still not sure if I like this pattern. You should be able to specify "h", "help" to make both /h and /help long flags. This approach won't work, because if you have 'h', "help" as your flags, /help will see /h as a short flag, and then look for e as a short flag (as the failing tests show).

This kind of argument matching is pretty ugly and ambiguous. I don't like having the short flag the same as the long flag; it becomes inconsistent and difficult to reason about from a user perspective. I'd prefer making / just the long prefix with multiple forms for the arguments you want, and if anything, adding an option to forbid long or short arguments (so the parser becomes long-only or short-only).

@Taywee Taywee left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fails tests.

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.

Using Windows like "/" short prefixes don't work

2 participants