https://github.com/snvfk1n/argv-options
opinionated argv options parser
https://github.com/snvfk1n/argv-options
args cli nodejs
Last synced: about 1 month ago
JSON representation
opinionated argv options parser
- Host: GitHub
- URL: https://github.com/snvfk1n/argv-options
- Owner: snvfk1n
- License: mit
- Created: 2017-01-21T14:41:24.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-23T13:05:59.000Z (over 9 years ago)
- Last Synced: 2025-07-08T09:15:50.756Z (12 months ago)
- Topics: args, cli, nodejs
- Language: JavaScript
- Homepage:
- Size: 20.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# argv-options
[](https://www.npmjs.com/package/argv-options)
[]()
`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.