Argv parser. Like optimist
but using node's util.parseArgs
.
$ npm install --save optymista
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);
Fluid API corresponding to util.parseArgs
options:
-
boolean()
,string()
- set option type toboolean
orstring
-boolean
is the default -
default()
- sets option default value -
multiple()
- option can be provided multiple times and all values will be collected in an array -
short()
- provides a one letter alternative to longer POSIX style option -
option()
- can be used to directly provide one or more option properties -
version()
- 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 header -
describe()
- option description -
showHelp()
- 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')
MIT © Damian Krzeminski