Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tandrewnichols/opted
Stringify an object to command line options
https://github.com/tandrewnichols/opted
Last synced: 4 months ago
JSON representation
Stringify an object to command line options
- Host: GitHub
- URL: https://github.com/tandrewnichols/opted
- Owner: tandrewnichols
- Created: 2015-07-20T16:55:22.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-08-31T04:17:31.000Z (over 7 years ago)
- Last Synced: 2024-10-20T19:23:08.775Z (4 months ago)
- Language: JavaScript
- Size: 14.6 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
Awesome Lists containing this project
README
[](https://travis-ci.org/tandrewnichols/opted) [](https://npmjs.org/package/opted) [](https://npmjs.org/package/opted) [](https://codeclimate.com/github/tandrewnichols/opted) [](https://codeclimate.com/github/tandrewnichols/opted) [](https://david-dm.org/tandrewnichols/opted)
# opted
Stringify an object to command line options
## Installation
`npm install --save opted`
## Usage
Opted is _not_ a command line option parser. Rather, it is a library for stringifying an object into a list of command line arguments. E.g.
```js
var opted = require('opted');
var args = opted({ foo: 'bar' });
console.log(args); // ['--foo', 'bar']
```## Types of flags
### Long
Options are [kebab-cased](https://lodash.com/docs#kebabCase) and prefixed with '--'.
```js
console.log( opted({ foo: 'bar' }) ); // ['--foo', 'bar']
console.log( opted({ fooBar: 'baz' }) ); // ['--foo-bar', 'baz']
```### Short
Options that have single letter abbreviations can also be used.
```js
console.log( opted({ f: 'bar' }) ); // ['-f', 'bar']
```### Boolean
Options that are simple "on", but have no value, can be set to `true`. Setting a flag to false, will add 'no' to the beginning.
```js
console.log( opted({ bananas: true }) ); // ['--bananas']
console.log( opted({ bananas: false }) ); // ['--no-bananas']
```### Equal style
Options that include an equal sign will keep the equal sign.
```js
console.log( opted({ 'name=', 'Andrew' }) ); // ['--name=Andrew']
```### List
Multiple options for a single flag can be passed in an array.
```js
console.log( opted({ member: ['Bob', 'Larry'] }) ); // ['--member', 'Bob', '--member', 'Larry']
```## But wait, the tool I need to pass args to is some bizarre abomination like "find" that uses single dashes...
No problem. Just enable crazy-arg mode by passing true as the second parameter.
```js
console.log( opted({ hello: 'world' }, true) ); // ['-hello', 'world']
```## Contributing
Please see [the contribution guidelines](CONTRIBUTING.md).