0.0.1 • Published 7 years ago
@ztmd/argv v0.0.1
argv
Opinionated argument parser for node.js CLI.
Install
npm install @ztmd/argvyarn add @ztmd/argvUsage
const argv = require('@ztmd/argv');
argv(args, options);Return
An object to representation the result.
result._is specified as the first argument(s).result.$is specified as extra arguments seperated by--exactly.
If you need to parse arguments which the key is
_or$, setoptions._to a truthy value, and notice other values will be moved toresult.argv.
Options
first
- type:
boolean - default: true
true to accept multi values for first arguments.
multi
- type:
boolean/array
Use multi values for the specify key.
While multi is an array, check key is in it or not.
_
- type:
boolean
Support using underline _ as the key.
Example
Scripts
argv(['--foo', 'bar']);
// > { _: [], foo: 'bar' }
argv(['example', '--list', 'a', '--list', 'b'], { multi: true });
// > { _: [ 'example' ], list: [ 'a', 'b' ] }CLI
// demo.js
const argv = require('@ztmd/argv');
console.log(argv(process.argv.slice(2), { multi: ['test'] }));$ node demo.js hello --test world> { _: [ 'hello' ], test: [ 'world' ] }License
MIT.
0.0.1
7 years ago