-
Notifications
You must be signed in to change notification settings - Fork 54
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
Issues parsing negative numbers when passed without =
#52
Comments
`{"features":24,"specified":7,"verified":17,"checks":36}` - some additions in arg/dump.js as suggested in #6 Filed vercel/arg#52
You have to pass arguments individually. arg({"--int": parseInt}, {argv: ["--int", "-100"]}); The only exception is Since it looks like you're creating a repository showing off many different argument parsing libraries, it's probably worth mentioning this is how all argument parsing is done unless the library accepts a full, single-string command line (which I would caution against anyone using, personally). This is because processes on most (all?) modern platforms accept command line arguments as individual strings fashioned into an array. $ my_program foo bar "qux qix" #include <stdio.h>
int main(int argc, char *argv[]) {
for (int i = 0; i < argc; i++) {
printf("%s\n", argv[i]);
}
return 0;
}
In Node, It's up to the shell (cmd.exe, bash, fish, zsh, powershell, etc.) to split a single command line on the spaces and, depending on the shell's syntax, parse and then throw away any quotes. For example, it's the shell (e.g. bash) keeping the That is also why double quotes never show up in your program's This is why you have to pass |
Thx for the elaboration, it's true that I didn't (yet) check how other parsers behave on that aspect. And it's true that I learn a lot during that research. 👍 |
While working on documenting dashdash features I discovered that it is able to parse negative values just fine. This is also true for command-line-args. The assumption that this would not be possible in general originated from the referenced issue. And I remember I checked at least one other lib after that reply. I will now add those cases to all compared libs. vercel/arg#52
Added "custom option handling" for integer and number. vercel/arg#52
Just added the case from the ticket, so it's more obvious. vercel/arg#52
FYI: I finally verified this behavior for (And of course they don't expect you to pass in all options as a single string.) |
PS: I updated the initial description of the issue, since this is less about passing all args as a single string, it is about passing option arguments starting with |
Hi. I'm not sure what issue you're referring to. Very clearly in your original post, you had a single argument passed in expecting it to be parsed as two arguments. That's not what
I don't really know what to tell you here. There's no bug, |
My intention was not to confuse you, but it seems to have happened anyways. Sorry for that. I was trying to understand if there is a way to achieve the following: Best regards, |
However, the confusion comes from your usage. In the OP, you CANNOT pass a single string ( I'll push a patch shortly. Thank you for bringing it up. |
Got distracted yesterday, apologies. Released as |
FYI: It currently only works when using type |
Need to think of a good way to approach this problem, then. |
If you want we can do it together. My thoughts would be: If an option requires an argument the next thing in the list should be treated as such, independent of the first character. Since I'm not familiar with your code base, feel free to explain how you do the parsing in general/differently (and why) if you want to exchange thoughts/arguments. |
That's why this is non-trivial; we check to see if the next argument starts with a |
Maybe the proper way to handle it then is to document as loudly as possible something like "If an option argument could start with If you could use a different criteria for the decision if something is an argument or an option (like a blacklist of types, instead of a white-list, or the Not trying to make the problem more complex, just thinking out loud while trying to grasp the scope of it... (If you would prefer a different channel for this communication, just let me know.) |
in node shell:
I also tried to wrap the numbers with different kinds of quotes, but it didn't have any effect.
I don't know if this is a "feature" or a "bug".
Update: The example above is bad in the sense that
argv
is different from what it would look like when using from the shell, which influences the error messages. A better example is:Since the repo doesn't seem to be maintained(sorry for that, it's not true, must have switched the name with one of the other repos), just filing this to make people aware since I discovered it while comparing features of different argument parsers (WIP)The text was updated successfully, but these errors were encountered: