OSDN Git Service

Regular updates
[twpd/master.git] / meow.md
1 ---
2 title: Meow
3 category: JavaScript libraries
4 layout: 2017/sheet
5 updated: 2017-10-30
6 weight: -1
7 intro: |
8   [meow](https://npmjs.com/package/meow) is the easiest way to write command line apps for Node.js.
9 ---
10
11 ### Typical settings
12
13 ```js
14 const cli = require('meow')(`
15   Usage: appname [options]
16
17   Options:
18         --lang LANG    set the language
19
20   Other options:
21     -h, --help         show usage information
22     -v, --version      print version info and exit
23 `, {
24   string: ['lang'],
25   boolean: ['help', 'version'],
26   alias: { h: 'help', v: 'version' }
27 })
28 ```
29
30 `string` and `boolean` lets meow/minimist know which flags expect arguments (`string`) and which don't (`boolean`).
31
32 ### Using the result
33
34 ```js
35 cli.flags   // { lang: 'en' }
36 cli.input   // []
37 ```
38
39 Yes, flags are automatically camelCased!
40
41 ### Lesser-used settings
42
43 ```js
44 meow(`...`, {
45   // Default values if flags are not specified
46   default: { lang: 'en' },
47
48   // allow using -- to stop processing flags
49   '--': true,
50
51   // Populate `_` with first non-option
52   stopEarly: true,
53
54   // Invoked on unknown param
55   unknown: function () { ... }
56 })
57 ```
58
59 Also see [minimist](minimist.html).