clia
Command line arguments parser and t3st example project.
usage
Example command line input:
node your-node-app hello -a -ab -d world
In your-node-app:
const clia = require('clia')
const conf = clia(process.argv.slice(2))
conf === {
plain: [ 'hello' ],
opt: { a: true, b: true, d: true },
args: { d: [ 'world' ] },
arg: { d: 'world' },
}
parsing
If --
is encountered, it is ignored. All subsequent inputs are treated as arguments.
An error is thrown when:
- any argument containts
__proto__
to prevent prototype pollution - key-value pair with missing key or value, eg:
--store=
or --=pet
alias
clia('run -o yaml --d=/usr/bin --fruit=mango'.split(' ')
, ['output', 'directory', 'fruit'])
yields
{
arg: {
o: 'yaml', output: 'yaml',
d: '/usr/bin', directory: '/usr/bin',
fruit: 'mango'
},
args: {
o: ['yaml'], output: ['yaml'],
d: ['/usr/bin'], directory: ['/usr/bin'],
fruit: ['mango']
},
opt: { o: true, output: true },
plain: ['run']
}
Docs
All examples here
Dev/specs

