It would be good to allow passing in negative numbers via CLI - ideally without workarounds for options, but as far as I can tell, it doesn't work at all for arguments.
Example:
import {program} from 'commander'
program.argument('<number>', 'The number to square').action(num => {
console.log(Math.pow(Number(num), 2))
})
program.parse()
You can run node square.js 2 but not node square.js -2. Since it's not an option, there's no equivalent to the --foo=-2 suggested in #61. That issue has been closed for a few years but this comment suggests it's worth opening a new one #61 (comment).
My suggested fix:
If an argv value matching ^-\d(\.\d+)?$ is encountered, and doesn't match any option, don't throw error: unknown option '-2'. Just treat it like an non-option argv. I haven't looked into the code but hopefully that could be done by a single check somewhere. If feasible, this would also probably solve for the original complaint in #61 without needing end-users to know the = workaround.
It would be good to allow passing in negative numbers via CLI - ideally without workarounds for options, but as far as I can tell, it doesn't work at all for arguments.
Example:
You can run
node square.js 2but notnode square.js -2. Since it's not an option, there's no equivalent to the--foo=-2suggested in #61. That issue has been closed for a few years but this comment suggests it's worth opening a new one #61 (comment).My suggested fix:
If an argv value matching
^-\d(\.\d+)?$is encountered, and doesn't match any option, don't throwerror: unknown option '-2'. Just treat it like an non-option argv. I haven't looked into the code but hopefully that could be done by a single check somewhere. If feasible, this would also probably solve for the original complaint in #61 without needing end-users to know the=workaround.