minimist: mention meow

This commit is contained in:
Rico Sta. Cruz 2015-11-15 11:05:57 +11:00
parent 856f1e3ca1
commit fe4a49f389
1 changed files with 25 additions and 28 deletions

View File

@ -4,46 +4,43 @@ layout: default
--- ---
```js ```js
var args = require('minimist')(process.argv.slice(2), { var minimist = require('minimist')
var args = minimist(process.argv.slice(2), {
string: 'lang', string: 'lang',
boolean: 'pager', boolean: 'pager',
alias: { h: 'help', v: 'version' } alias: { h: 'help', v: 'version' },
default: { lang: 'en' },
'--': true,
stopEarly: true, /* populate _ with first non-option */
unknown: function () { ... } /* invoked on unknown param */
}); });
// --lang xml --no-pager -h index.js package.json // --lang xml --no-pager -h index.js package.json
args == { args == {
lang: 'xml', pager: false, lang: 'xml',
h: true, help: true, pager: false,
h: true,
help: true,
_: [ 'index.js', 'package.json' ] _: [ 'index.js', 'package.json' ]
} }
``` ```
### Help and version
Use [meow](https://www.npmjs.com/package/meow).
```js ```js
if (args.help || args._.length === 0) { meow(`
var cmd = require('path').basename(process.argv[1]); Usage:
console.log( $0 FILES [options]
require('fs')
.readFileSync(__dirname+'/../help.txt','utf-8')
.replace(/\$0/g, cmd)
.trim());
process.exit();
}
if (args.version) { Options:
console.log(require('../package.json').version); -h, --help print usage information
process.exit(); -v, --version show version info and exit
} `, {
``` /* options */
})
### Help.txt
```
Usage:
$0 FILES [options]
Options:
-h, --help print usage information
-v, --version show version info and exit
``` ```
### Reference ### Reference