-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Options with optional option argument seem too greedy. A way to change it is needed #1899
Comments
For interest, the POSIX behaviour for an option taking an optional argument is that it never takes the following space-separated argument. The option argument can only be specified directly with the option:
Not many argument parsers support this mode, but I do like that it avoids the parsing ambiguity with optional arguments. |
It is technically possible, but...
|
Unfortunately, I could not find any. There is only this 13 year old Python issue dealing with a similar problem in the argparse module that still has not been resolved: python/cpython#53584. It is the first time I am creating a command line interface and this seemed to me like the most logical approach, so I am surprised to see there are no libraries that take it. |
For interest, I did some research when working on |
That is interesting indeed :) Well, if my suggestion does not seem feasible, maybe adding an option to make an option-argument "embedded" (and thus conforming to POSIX) should be considered. |
I have nearly written up POSIX-style a couple of times, done now: #1901 |
No further activity in a month. Closing this in favour of #1901. Feel free to open a new issue if it comes up again, with new information and renewed interest. |
I've read into the documentation explaining how to deal with parsing ambiguities and am not entirely satisfied with the suggested solutions. Below is a simple use case scenario where one required argument is expected and there is one option with an optional option argument.
I run following tests:
The expected behavior is that
file
be treated as thefilename
argument value in tests 1 and 2, but it was only treated as such in tests 5 and 6, when placed before the option.So my question is, would it be possible to add a way to make an option with optional option argument lazy, so that it would only grab the immediately following argument value if there was no other interpretation for it? (In my example, this would be the case if a second argument was provided, e.g.
node test.js -p program file
.)Maybe something like the following:
Or is there any particular reason why this would not work well?
The text was updated successfully, but these errors were encountered: