Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

short options not parsed when longprefix is empty #94

Open
culyun opened this issue Jan 7, 2021 · 2 comments
Open

short options not parsed when longprefix is empty #94

culyun opened this issue Jan 7, 2021 · 2 comments

Comments

@culyun
Copy link

culyun commented Jan 7, 2021

If I setup an ArgumentParser with both short and long options AND the long option prefix is empty (""), the short options are never parsed, eg.

args::ArgumentParser parser("This is a test program.", "This goes after the options."); parser.ShortPrefix("-"); parser.LongPrefix(""); parser.LongSeparator("="); args::ValueFlag<int> counter(parser, "integer", "The counter value", {'c', "counter"});
This works ok..

./test counter=3

But this does not..

./test -i 3

@culyun
Copy link
Author

culyun commented Jan 7, 2021

Here's a hacked together patch that can be applied to de4db87

fix_parsing_for_empty_prefixes.patch.txt

@Taywee
Copy link
Owner

Taywee commented Jan 31, 2021

That's tough. I'd prefer unambiguous parsing in most cases. An empty long prefix will always be matched, because long options take precedence over short. Options aren't required to be alphanumeric, and -v could be an actual long-option name (matching the empty-string long prefix). That said, I see why you'd want the behavior you'd expect, because usually that's the way you'd really want it to behave.

Why the restriction on long separator containing both whitespace and non-whitespace characters? I don't see a reason to prevent the long separator from being any arbitrary string, as silly as it might be. If somebody is doing something ridiculous like having their long separator : so they can specify options with 'optionname: value', that would break it.

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

No branches or pull requests

2 participants