-
Notifications
You must be signed in to change notification settings - Fork 610
Support option name aliases / multiple long options #240
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
Comments
I'd like to work on this. If there's anything I should keep in mind, please do let me know. Otherwise, I'll share a first draft as soon as I have one and we can take it from there. |
I can't think of anything, a short and a long name are basically already an alias for each other, so I think the syntax just needs to be extended. Go for it. |
Sorry for the slow reply -- live happened. I've taken a closer look at the code now and thought about how to implement it. AFAIK, there are a few viable options, ranked in increasing order of intrusiveness:
Since I don't know this package and its users well enough to make this call, I require your expertise to make this decision. Once we've narrowed it down, I'll create an initial implementation that we can discuss in detail. |
I think that the minimal change in terms of user-facing functions is simply being willing to parse "x,foo,bar" and not just "x,foo":
That's your second option IIUC. But it doesn't have to be just one way of specifying multiple aliases. And I like the first option as well, i.e. I'd also like it if I could write:
and for that to work. |
Yeah, that's the
to define aliases. My question is about the backend -- i.e. about how |
Change the backend, of course. (Goes without saying IMHO). |
You should extend the interface without breaking existing behaviour if possible, and change the backend to support it. I think this is easily done in this case. |
@KappaDistributive : Did you get around to working on this? |
No. I was planning to work on this as my vacation project but then decided to go with another project instead. Sorry for not letting you know sooner. |
@eyalroz I'm just interested why would you need extra aliases for the single option? |
* We now use a vector of long option names instead of a single name * When specifying an option, you can provide multiple names separated by commas, at most one of which may have a length of 1 (not necessarily the first specified name). The length-1 name is the single-hyphen switch (the "short name"). * Hashing uses the first long name * Option help currently only uses the first long name. Not sure if that should change. * No tests for this functionality yet * Not sure whether option lookup works already with names other than the first...
@artpaul : Basically for the same reason you want both a short name and a long name: Convenience for the user. This way they don't have to remember whether to type, for example It also makes it easier to change option names without breaking existing scripts. |
* We now use a vector of long option names instead of a single name * When specifying an option, you can provide multiple names separated by commas, at most one of which may have a length of 1 (not necessarily the first specified name). The length-1 name is the single-hyphen switch (the "short name"). * Hashing uses the first long name * Option help currently only uses the first long name. Not sure if that should change. * No tests for this functionality yet * Not sure whether option lookup works already with names other than the first...
* We now use a vector of long option names instead of a single name * When specifying an option, you can provide multiple names separated by commas, at most one of which may have a length of 1 (not necessarily the first specified name). The length-1 name is the single-hyphen switch (the "short name"). * Hashing uses the first long name * Option help currently only uses the first long name. Not sure if that should change. * No tests for this functionality yet * Not sure whether option lookup works already with names other than the first...
* We now use a vector of long option names instead of a single name * When specifying an option, you can provide multiple names separated by commas, at most one of which may have a length of 1 (not necessarily the first specified name). The length-1 name is the single-hyphen switch (the "short name"). * Hashing uses the first long name * Option help currently only uses the first long name. Not sure if that should change. * No tests for this functionality yet * Not sure whether option lookup works already with names other than the first...
@KappaDistributive : Your input on my WIP would be appreciated. |
* Now also covering the no-regex case * Using `std::token_regex_iterator` to tokenize for option-splitting instead of doing it "ourselves" * Still almost no tests for this functionality
* We now use a vector of long option names instead of a single name * When specifying an option, you can provide multiple names separated by commas, at most one of which may have a length of 1 (not necessarily the first specified name). The length-1 name is the single-hyphen switch (the "short name"). * Hashing uses the first long name * Option help currently only uses the first long name. Not sure if that should change. * Almost no tests for this functionality yet * Using `std::token_regex_iterator` to tokenize for option-splitting
* We now use a vector of long option names instead of a single name * When specifying an option, you can provide multiple names separated by commas, at most one of which may have a length of 1 (not necessarily the first specified name). The length-1 name is the single-hyphen switch (the "short name"). * Hashing uses the first long name * Option help currently only uses the first long name. Not sure if that should change. * Almost no tests for this functionality yet * Using `std::token_regex_iterator` to tokenize for option-splitting
* We now use a vector of long option names instead of a single name * When specifying an option, you can provide multiple names separated by commas, at most one of which may have a length of 1 (not necessarily the first specified name). The length-1 name is the single-hyphen switch (the "short name"). * Hashing uses the first long name * Option help currently only uses the first long name. Not sure if that should change. * Almost no tests for this functionality yet * Using `std::token_regex_iterator` to tokenize for option-splitting
Related to jarro2783#240, jarro2783#363, and jarro2783#349
(This is a feature I added to boost::program_options a couple of years back.)
Right now, if you name an option
"x,long-name-of-x,another-long-name-of-x"
- you get an error:instead, cxxopts should support having multiple aliases for the (first and primary) name of the option - all of which would be accepted on the command-line just as though the primary name were used.
The text was updated successfully, but these errors were encountered: