Cannot specify negative number as command option value
See original GitHub issueAs of version 0.40.0, it doesn’t appear possible to specify a negative number as a command option.
Assuming I define a command that takes a decimal value as a command option, and that I want to pass a negative number value, neither of the following works:
mycommand -a -1.50
mycommand -a "-1.50"
Both attempts fail with this error Not a valid name for a short option
. It appears that the command option parsing logic thinks that the -1.50 is supposed to be a command option.
I would expect that the quotes at least would effectively escape the numeric value. Is this a bug, or am I missing something?
Thanks.
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (12 by maintainers)
Top Results From Across the Web
Pass negative number as command line argument
Is there a way to pass a negative number as an option or command line argument to ArgumentParser? For example, the code below...
Read more >Issue with optional arguments which are negative numbers
I'm having a small issue with argparse . I have an option xlim which is the xrange of a plot. I want to...
Read more >Cannot pass negative numbers as arguments · Issue #555
If I try to pass a negative number to click, it interprets it as an option. This happens when I define the number...
Read more >Negative Numbers for input parameters. - UNIX and Linux ...
Hello, I have a command that I need to supply a negative number as a parameter; how do I do this? I have...
Read more >Change the way negative numbers are displayed
The Command button. +1. In the Category box, click either Number or Currency. Under Negative numbers, select an option for negative numbers.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Oh I’m certainly not ready to write a full POSIX compliance PR either, now 😅
Thanks! My next week is busyish, but I’ll take a look once I have a moment.
@jouniheikniemi I’ll try to answer all your questions.
That would be @patriksvensson opinion of things. I think there’s no fully written down version of it 😄
Again, nothing that’s written down or anything.
Currently, options follow the following guidelines:
char.IsLetterOrDigit
)-
, followed by exactly one character) or one long name (starting with--
) or both.=
) sign. (I think passing a colon (:
) is also possible)(I hope this is all of them, and I did not forget anything.)
While I do feel that implementing an existing standard is always a good thing, I also feel that implementing POSIX is a bit too much, here. (And, I personally dislike
-afoo
for-a foo
and-xvjf
for-x -v -j -f
.)So, to summarize the above, currently
-1
and--11
are not valid options, and they were planned as such. At the same time, I see the inability to pass-1
as an argument to an option using e.g.--foo -1
instead of--foo=-1
as a bug.