minimisty
Minimistish argument parsing.
I have used minimist as my argument-parsing library, but two minor things always bothered me:
-
Checking for flags is not that good.
-a
becomes{ a: true }
. The correct way to check if thea
flag was provided isif (args.a === true)
. If you simply doif (args.a)
you could be mistakingly interpreting-a some-other-thing
. -
process.argv.slice(2) isn't really classy. There is a reason for that, but I use it only with node so I don't care.
Usage
// example.jsconst argv = consoledirargv
$ node examplejs -a beep -b boop _: _flags: {} a: 'beep' b: 'boop'
$ node examplejs -x 3 -y 4 -n5 -abc --beep=boop foo bar baz _: 'foo' 'bar' 'baz' _flags: '5': true n: true a: true b: true c: true x: '3' y: '4' beep: 'boop'