cheatsheets/meow.md

59 lines
1.1 KiB
Markdown
Raw Permalink Normal View History

2015-12-26 00:49:18 +00:00
---
title: Meow
category: JavaScript libraries
2017-10-29 16:25:02 +00:00
updated: 2017-10-30
weight: -1
intro: |
[meow](https://npmjs.com/package/meow) is the easiest way to write command line apps for Node.js.
2015-12-26 00:49:18 +00:00
---
2017-10-29 16:25:02 +00:00
### Typical settings
2015-12-26 00:49:18 +00:00
```js
const cli = require('meow')(`
Usage: appname [options]
Options:
2017-10-29 16:25:02 +00:00
--lang LANG set the language
Other options:
-h, --help show usage information
-v, --version print version info and exit
2015-12-26 00:49:18 +00:00
`, {
string: ['lang'],
2017-10-29 16:25:02 +00:00
boolean: ['help', 'version'],
alias: { h: 'help', v: 'version' }
2015-12-26 00:49:18 +00:00
})
2017-10-29 16:25:02 +00:00
```
2015-12-26 00:49:18 +00:00
2017-10-29 16:25:02 +00:00
`string` and `boolean` lets meow/minimist know which flags expect arguments (`string`) and which don't (`boolean`).
### Using the result
```js
cli.flags // { lang: 'en' }
2015-12-26 00:49:18 +00:00
cli.input // []
2017-10-29 16:25:02 +00:00
```
2015-12-26 00:49:18 +00:00
2017-10-29 16:25:02 +00:00
Yes, flags are automatically camelCased!
### Lesser-used settings
```js
meow(`...`, {
// Default values if flags are not specified
default: { lang: 'en' },
// allow using -- to stop processing flags
'--': true,
// Populate `_` with first non-option
stopEarly: true,
// Invoked on unknown param
unknown: function () { ... }
})
2015-12-26 00:49:18 +00:00
```
Also see [minimist](minimist.html).