Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jankaszel/argv-options

opinionated argv options parser
https://github.com/jankaszel/argv-options

args cli nodejs

Last synced: 17 days ago
JSON representation

opinionated argv options parser

Awesome Lists containing this project

README

        

# argv-options

[![npm](https://img.shields.io/npm/v/argv-options.svg)](https://www.npmjs.com/package/argv-options)
[![Travis](https://travis-ci.org/fallafeljan/argv-options.svg)]()

`argv-options` subjectively parses your `argv` options, i.e., it makes
assumptions about how your CLI is designed to keep the API simple. It expects your `argv` object to be supplied in the format of `-p foo --param bar`, i.e.,
simple key-value arguments that may be aliased (using `--`).

## API

`parseOptions(argv, options)`

This method will return the parsed options in a key-value based object,
including all found options and their respective aliases. The following
arugments are mandatory:

* `argv` The arguments array, as space-split array of all parameters. In your
average usage case, passing `process.argv.slice(2)` will do.
* `options` The possible options, as object:

```json
{
"p": {
"optional": false,
"alias": "param"
},

"a": {
"optional": true,
"alias": "argument"
}
}
```

Parameters are required (`optional` is false) by default. Alternatively, for
more convenient use, aliases may be specified by using the key's value:

```json
{
"p": "param"
}
```

If any non-optional parameters are missing or undocumented parameters occur,
`parseOptions` will throw an error.