optymista
v1.0.0
Published
Argv parser. Like `optimist` but using node's `util.parseArgs`.
Downloads
21
Maintainers
Readme
optymista
Argv parser. Like optimist
but using node's util.parseArgs
.
Install
$ npm install --save optymista
Usage
const { argv } = require('optymista')
.usage('noble-gas [options]')
.boolean('verbose').describe('says everything')
.describe('name', 'name of the gas').short('N').default('argon');
if (argv.verbose) {
console.log('starting');
}
console.log('name:', argv.name);
API
Fluid API corresponding to util.parseArgs
options:
boolean()
,string()
- set option type toboolean
orstring
-boolean
is the defaultdefault()
- sets option default valuemultiple()
- option can be provided multiple times and all values will be collected in an arrayshort()
- provides a one letter alternative to longer POSIX style optionoption()
- can be used to directly provide one or more option propertiesversion()
- implements--version,-V
support - if no version is passedoptymista
will try to read one from thepackage.json
file
Help is automatically generated based on the information provided through usage
and descibe
usage()
- one or more strings that will form help text headerdescribe()
- option descriptionshowHelp()
- display the help text on standard output
-h|--help
is automatically added to the list of options and treated as a request to show help text.
In case of any parsing errors help and the message associated with thrown exception is displayed.
Methods can be chained with option name used only in the first method:
string('width').short('w').string('height').short('h')
License
MIT © Damian Krzeminski