Closed dkurth closed 9 months ago
Double-dashed arguments usually should use =
, ie, --long=-118.3459323
. Does that work?
Arguments which start with a dash are assumed to be options and not used as option-values.
The work-around is to be explicit and embed the option value in the argument with an =
like:
node dump.js --lat=34.0168729 --long=-118.3459323
I tried quoting the negative value, but this did not help.
As a side-note on why this did not work, quotes around an argument are usually removed by the shell before they reach node and minimist. Quotes can help with special shell characters like $
in arguments, and with spaces within an argument, but don't help with how -
is processed.
Thank you @ljharb and @shadowspawn -- you are right, adding an "=" resolves this. I should have thought to try that!
I tried using minimist to write a command line tool that accepts a latitude and longitude, but I ran into a problem when one of the values is negative. You can see the issue by simply dumping the parsed arguments, like this:
Try running this:
node dump.js --lat 34.0168729 --long -118.3459323
Since the longitude is negative, it starts with a "-", so apparently it is being interpreted as a new argument. The output looks like this:
I expected that to be:
I tried quoting the negative value, but this did not help.