argvee
argv parsing (that is actually useful)
Installation
argvee
is available on npm.
npm install argvee
Usage
Theargvee
argument parser takes the node.js standard
process.argv
array and constructs an object with helpers
that can easily be queried.
```js
import { parse } from 'argvee';
const argv = parse(process.argv);
```
When constructed, the argv collection recognizes three
types command line arguments: commands, modes, and parameters.
Commands
Commands are the simplest of arguments. They are any arguments that are listed to that do not start with the-
or --
prefix.
Essentially, they are a list of keys.
```js
// $ node cli.js hello universe
argv.commands === 'hello', 'universe';
```
Modes
Modes are also a non-value list of keys, but they can be expressed differently by using the-
or --
prefix. When using modes, if
it begins with a single -
, each letter will be parsed as its own mode.
```js
// $ node cli.js --universe -abc
argv.modes === 'universe', 'a', 'b', 'c';
```
Parameters
Parameters are key:value pairs that are declared in a similiar manner as modes. They can be declared in any of the following ways. ```js // $ node cli.js --noun universe --noun=world -v say --topic=hello -w=now argv.params === {noun: ['universe', 'world'],
v: ['say'],
topic: ['hello'],
w: ['now'],
};
```
You can also specify parameters with multiple words by surrounding the
phrase with double-quotes.
```js
// $ node cli.js --say "hello universe" --say "hello world"
argv.params ===
{
say: ['hello universe', 'hello world'],
};
```