vercel / arg

Simple argument parsing
https://npmjs.com/arg
MIT License
1.23k stars 54 forks source link

FIX: Parse long args with '=' in value (#47) #48

Closed flexdinesh closed 5 years ago

flexdinesh commented 5 years ago

Fixes #47

Qix- commented 5 years ago

Oh wow, my understanding of .split(x, n) has been completely off. I suppose I assumed it worked like Java's, where it would stop splitting after n splits and put the rest in the last element. As it stands, the second parameter seems a bit useless IMO.

Thanks for this, it's a great catch.

flexdinesh commented 5 years ago

As it stands, the second parameter seems a bit useless IMO.

Second param is definitely useless as far as I observed as well. When I remove it, all tests pass. Do you want me to remove the second param as well as part of this PR?

Qix- commented 5 years ago

No because it's actually necessary to get it to work as expected.

> (x => x.split(/=(.*)/, 2))('--foo=qux=qox')
[ '--foo', 'qux=qox' ]
> (x => x.split(/=(.*)/))('--foo=qux=qox')
[ '--foo', 'qux=qox', '' ]

We have to have exactly 2 elements for the destructure to work.

Nevermind, TIL that you can have a disproportionate amount of array elements for destructuring. I'm learning so much. I think I'm too used to Python throwing errors when you have wonky things going on.

Still, keep it. I imagine there's some performance benefit, however miniscule.

What a weird API. Javascript is weird.

Qix- commented 5 years ago

Great, thank you so much!

Qix- commented 5 years ago

Published as 4.1.1.