Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/bezoerb/group-args

CLI helper to group commandline arguments
https://github.com/bezoerb/group-args

Last synced: 14 days ago
JSON representation

CLI helper to group commandline arguments

Awesome Lists containing this project

README

        

# group-args [![Build Status](https://travis-ci.org/bezoerb/group-args.svg?branch=master)](https://travis-ci.org/bezoerb/group-args) [![Coverage Status](https://coveralls.io/repos/github/bezoerb/group-args/badge.svg?branch=master)](https://coveralls.io/github/bezoerb/group-args?branch=master)

> CLI helper to group commandline arguments

## Install

```
$ npm install --save group-args
```

## Usage

```bash
node ./cli.js --foo --bar something --group-a 1 --group-b 2
```
```js
const groupArgs = require('group-args');

// process.argv: [
groupArgs('group');
//=> {foo: true, bar: 'something', group: { a: 1, b: 2 }}
```

## API

### groupArgs(key, [options], [minimistOptions])

#### key

Type: `string|array|object`

Group arguments by key. When passing an object it is
Could be `'key'`, `['key1','key2']`, `{alias1: 'key1', alias2: 'key2'}`

#### options

##### argv

Type: `array|object`

Default: `process.argv.slice(2)`

Arguments array or already parsed arguments.

##### delimiter

Type: `string`

Default: `-`

Delimiter between group identifier & key.

##### strict

Type: `bool`

Default: `true`

Disable to allow camelCased arguments provided by e.g. [`meow`](https://github.com/sindresorhus/meow)

##### alias

Type: `string`

Default: `undefined`

Alias for identifier (short opt)

##### camelCase

Type: `bool`

Default: `true`

camelCase grouped arguments

#### minimistOptions

See [`minimist`](https://github.com/substack/minimist#var-argv--parseargsargs-opts)

## License

MIT © [Ben Zörb](http://sommerlaune.com)