Parses Unix (-pewpew, --pew-pew=value, --pewpew value) and Dos style (/x, /x value) argv strings
Input
"node server.js -h 0.0.0.0 -p 80 -s -a --vvvv --r-x /v 123 /x --debug-enabled=yes"Output
{
"h": "0.0.0.0",
"p": "80",
"s": true,
"a": true,
"vvvv": true,
"r-x": true,
"v": 123,
"x": true,
"debug-enabled": "yes"
}Demo: http://jsfiddle.net/p3mc9/3/
Thx @maettig for help
This parser can have a strange behavior if you pass full path names e.g. -location /home/user/path/to/file.txt it thinks that /home is dos-style argument name... Fix it if your file accepts paths - \B[\/-] -> \B-
I saw you changed
\wto[\w-]. Yes, that's better. If you want, you can also change the last\s*to[\s=]*. This will allow Unix style like--long-name=value(becomes"long-name":"value"). Oh, and of course changing-+to[\/-]+will allow both Unix and DOS style.