argscan
This is a very simple CLI argument parser optimized for Daplie style.
The main export is a scan function that expects a process.argv
style array and
returns you processed information such as the command, flags, and positional
args.
Install
$ npm install --save argscan
Usage
var { command, flags, args } = require('argscan')(process.argv)
switch (command) {
case 'greet':
if (flags.loudly) { console.log('HELLO ') }
else { console.log ('hi') }
break
...
}
Style
Daplie style arg parsing means a few assumptions.
Command
First you're expected to have several commands with optional :
namespacing.
For example yourprogram action:subaction
where action:subaction
is the
command.
Also both long and short flags are supported. Long flags are expected to always
look like --someFlag
or --key=value
. Short flags are single-character
flags. You can have as many as you want on a single position. For example
-tim
is the same as -t -i -m
. Both will generate a flags map of
{ t: true, i: true, m: true }
.