question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot specify negative number as command option value

See original GitHub issue

As 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:closed
  • Created 2 years ago
  • Comments:13 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
jouniheikniemicommented, Jan 23, 2022

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.

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.

1reaction
nils-acommented, Jan 22, 2022

@jouniheikniemi I’ll try to answer all your questions.

[…] Spectre.Cli used to say it is “extremely opinionated”, so what’s its opinion here?

That would be @patriksvensson opinion of things. I think there’s no fully written down version of it 😄

Do you have a master plan here?

Again, nothing that’s written down or anything.

Currently, options follow the following guidelines:

  • option names can only be letters or digits (char.IsLetterOrDigit)
  • no option can start with a digit
  • each option can have one short name (starting with -, followed by exactly one character) or one long name (starting with --) or both.
  • if options have a value, that value needs to be passed after the option, separated by either a space ( ) or equal (=) sign. (I think passing a colon (:) is also possible)

(I hope this is all of them, and I did not forget anything.)

I personally prefer POSIX/GNU parsing in everything I do

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found