minimist: update layout

This commit is contained in:
Rico Sta. Cruz 2017-10-15 14:47:53 +08:00
parent b640bba1d6
commit 546b575d7c
No known key found for this signature in database
GPG Key ID: CAAD38AE2962619A
1 changed files with 43 additions and 9 deletions

View File

@ -1,34 +1,67 @@
--- ---
title: minimist title: minimist
category: JavaScript libraries category: JavaScript libraries
layout: 2017/sheet
--- ---
### Usage
```js ```js
var minimist = require('minimist') var minimist = require('minimist')
```
{: .-setup}
```js
var args = minimist(process.argv.slice(2), { var args = minimist(process.argv.slice(2), {
string: 'lang', string: 'lang', // --lang xml
boolean: 'pager', boolean: ['version'], // --version
alias: { v: 'version' }
})
```
```js
console.log(args)
```
All options are optional, but it's recommended you set `string` and `boolean` at least.
### All options
```js
var args = minimist(process.argv.slice(2), {
string: [ 'lang' ],
boolean: [ 'pager' ],
alias: { h: 'help', v: 'version' }, alias: { h: 'help', v: 'version' },
default: { lang: 'en' }, default: { lang: 'en' },
'--': true, '--': true,
stopEarly: true, /* populate _ with first non-option */ stopEarly: true, /* populate _ with first non-option */
unknown: function () { ... } /* invoked on unknown param */ unknown: function () { ... } /* invoked on unknown param */
}); })
```
// --lang xml --no-pager -h index.js package.json All options are optional.
### Result
With `--lang xml --no-pager -h index.js package.json`, you get:
{: .-setup}
```
args == { args == {
lang: 'xml', lang: 'xml',
pager: false, version: false,
h: true, h: true,
help: true, help: true,
_: [ 'index.js', 'package.json' ] _: [ 'index.js', 'package.json' ]
} }
``` ```
## Meow
### Help and version ### Help and version
Use [meow](https://www.npmjs.com/package/meow). Use [meow](https://www.npmjs.com/package/meow) to automatically add support for `--help`, `--version` and more.
{: .-setup}
```js ```js
meow(` meow(`
@ -39,11 +72,12 @@ meow(`
-h, --help print usage information -h, --help print usage information
-v, --version show version info and exit -v, --version show version info and exit
`, { `, {
/* options */ alias: { h: 'help', v: 'version' }
/* minimist options */
}) })
``` ```
### Reference ### Reference
* https://www.npmjs.org/package/minimist * <https://www.npmjs.org/package/minimist>
* https://github.com/substack/minimist * <https://github.com/substack/minimist>