@0xengine/meow 1.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @0xengine/meow might be problematic. Click here for more details.
- package/README.md +305 -0
- package/build/dependencies.js +8030 -0
- package/build/index.d.ts +1422 -0
- package/build/index.js +95 -0
- package/build/licenses.md +1501 -0
- package/build/options.js +98 -0
- package/build/parser.js +80 -0
- package/build/utils.js +7 -0
- package/build/validate.js +132 -0
- package/package.json +103 -0
package/README.md
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
# meow
|
|
2
|
+
|
|
3
|
+
> CLI app helper
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Parses arguments
|
|
8
|
+
- Negates flags when using the `--no-` prefix
|
|
9
|
+
- Outputs version when `--version`
|
|
10
|
+
- Outputs description and supplied help text when `--help`
|
|
11
|
+
- Sets the process title to the binary name defined in package.json
|
|
12
|
+
- No dependencies!
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
npm install @xengine/meow
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
./foo-app.js unicorns --rainbow
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
#!/usr/bin/env node
|
|
28
|
+
import meow from 'meow';
|
|
29
|
+
import foo from './lib/index.js';
|
|
30
|
+
|
|
31
|
+
const cli = meow(`
|
|
32
|
+
Usage
|
|
33
|
+
$ foo <input>
|
|
34
|
+
|
|
35
|
+
Options
|
|
36
|
+
--rainbow, -r Include a rainbow
|
|
37
|
+
|
|
38
|
+
Examples
|
|
39
|
+
$ foo unicorns --rainbow
|
|
40
|
+
🌈 unicorns 🌈
|
|
41
|
+
`, {
|
|
42
|
+
importMeta: import.meta, // This is required
|
|
43
|
+
flags: {
|
|
44
|
+
rainbow: {
|
|
45
|
+
type: 'boolean',
|
|
46
|
+
shortFlag: 'r'
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
/*
|
|
51
|
+
{
|
|
52
|
+
input: ['unicorns'],
|
|
53
|
+
flags: {rainbow: true},
|
|
54
|
+
...
|
|
55
|
+
}
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
foo(cli.input.at(0), cli.flags);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## API
|
|
62
|
+
|
|
63
|
+
### meow(helpText, options)
|
|
64
|
+
### meow(options)
|
|
65
|
+
|
|
66
|
+
Returns an `object` with:
|
|
67
|
+
|
|
68
|
+
- `input` *(Array)* - Non-flag arguments
|
|
69
|
+
- `flags` *(Object)* - Flags converted to camelCase excluding aliases
|
|
70
|
+
- `unnormalizedFlags` *(Object)* - Flags converted to camelCase including aliases
|
|
71
|
+
- `pkg` *(Object)* - The `package.json` object
|
|
72
|
+
- `help` *(string)* - The help text used with `--help`
|
|
73
|
+
- `showHelp([exitCode=2])` *(Function)* - Show the help text and exit with `exitCode`
|
|
74
|
+
- `showVersion()` *(Function)* - Show the version text and exit
|
|
75
|
+
|
|
76
|
+
#### helpText
|
|
77
|
+
|
|
78
|
+
Type: `string`
|
|
79
|
+
|
|
80
|
+
Shortcut for the `help` option.
|
|
81
|
+
|
|
82
|
+
#### options
|
|
83
|
+
|
|
84
|
+
Type: `object`
|
|
85
|
+
|
|
86
|
+
##### importMeta
|
|
87
|
+
|
|
88
|
+
**Required**\
|
|
89
|
+
Type: `object`
|
|
90
|
+
|
|
91
|
+
Pass in [`import.meta`](https://nodejs.org/dist/latest/docs/api/esm.html#esm_import_meta). This is used to find the correct package.json file.
|
|
92
|
+
|
|
93
|
+
##### flags
|
|
94
|
+
|
|
95
|
+
Type: `object`
|
|
96
|
+
|
|
97
|
+
Define argument flags.
|
|
98
|
+
|
|
99
|
+
The key is the flag name in camel-case and the value is an object with any of:
|
|
100
|
+
|
|
101
|
+
- `type`: Type of value. (Possible values: `string` `boolean` `number`)
|
|
102
|
+
- `choices`: Limit valid values to a predefined set of choices.
|
|
103
|
+
- `default`: Default value when the flag is not specified.
|
|
104
|
+
- `shortFlag`: A short flag alias.
|
|
105
|
+
- `aliases`: Other names for the flag.
|
|
106
|
+
- `isRequired`: Determine if the flag is required. (Default: false)
|
|
107
|
+
- If it's only known at runtime whether the flag is required or not, you can pass a `Function` instead of a `boolean`, which based on the given flags and other non-flag arguments, should decide if the flag is required. Two arguments are passed to the function:
|
|
108
|
+
- The first argument is the **flags** object, which contains the flags converted to camel-case excluding aliases.
|
|
109
|
+
- The second argument is the **input** string array, which contains the non-flag arguments.
|
|
110
|
+
- The function should return a `boolean`, true if the flag is required, otherwise false.
|
|
111
|
+
|
|
112
|
+
Note that flags are always defined using a camel-case key (`myKey`), but will match arguments in kebab-case (`--my-key`).
|
|
113
|
+
|
|
114
|
+
Example:
|
|
115
|
+
|
|
116
|
+
```js
|
|
117
|
+
flags: {
|
|
118
|
+
unicorn: {
|
|
119
|
+
type: 'string',
|
|
120
|
+
choices: ['rainbow', 'cat', 'unicorn'],
|
|
121
|
+
default: ['rainbow', 'cat'],
|
|
122
|
+
shortFlag: 'u',
|
|
123
|
+
aliases: ['unicorns'],
|
|
124
|
+
isMultiple: true,
|
|
125
|
+
isRequired: (flags, input) => {
|
|
126
|
+
if (flags.otherFlag) {
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
##### description
|
|
137
|
+
|
|
138
|
+
Type: `string | false`\
|
|
139
|
+
Default: The package.json `"description"` property
|
|
140
|
+
|
|
141
|
+
Description to show above the help text.
|
|
142
|
+
|
|
143
|
+
Set it to `false` to disable it altogether.
|
|
144
|
+
|
|
145
|
+
##### help
|
|
146
|
+
|
|
147
|
+
Type: `string | false`
|
|
148
|
+
|
|
149
|
+
The help text you want shown.
|
|
150
|
+
|
|
151
|
+
The input is reindented and starting/ending newlines are trimmed which means you can use a [template literal](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/template_strings) without having to care about using the correct amount of indent.
|
|
152
|
+
|
|
153
|
+
The description will be shown above your help text automatically.
|
|
154
|
+
|
|
155
|
+
Set it to `false` to disable it altogether.
|
|
156
|
+
|
|
157
|
+
##### version
|
|
158
|
+
|
|
159
|
+
Type: `string`\
|
|
160
|
+
Default: The package.json `"version"` property
|
|
161
|
+
|
|
162
|
+
Set a custom version output.
|
|
163
|
+
|
|
164
|
+
##### autoHelp
|
|
165
|
+
|
|
166
|
+
Type: `boolean`\
|
|
167
|
+
Default: `true`
|
|
168
|
+
|
|
169
|
+
Automatically show the help text when the `--help` flag is present. Useful to set this value to `false` when a CLI manages child CLIs with their own help text.
|
|
170
|
+
|
|
171
|
+
This option is only considered when there is only one argument in `process.argv`.
|
|
172
|
+
|
|
173
|
+
##### autoVersion
|
|
174
|
+
|
|
175
|
+
Type: `boolean`\
|
|
176
|
+
Default: `true`
|
|
177
|
+
|
|
178
|
+
Automatically show the version text when the `--version` flag is present. Useful to set this value to `false` when a CLI manages child CLIs with their own version text.
|
|
179
|
+
|
|
180
|
+
This option is only considered when there is only one argument in `process.argv`.
|
|
181
|
+
|
|
182
|
+
##### pkg
|
|
183
|
+
|
|
184
|
+
Type: `object`\
|
|
185
|
+
Default: Closest package.json upwards
|
|
186
|
+
|
|
187
|
+
package.json as an `object`.
|
|
188
|
+
|
|
189
|
+
Note: Setting this stops `meow` from finding a package.json.
|
|
190
|
+
|
|
191
|
+
*You most likely don't need this option.*
|
|
192
|
+
|
|
193
|
+
##### argv
|
|
194
|
+
|
|
195
|
+
Type: `string[]`\
|
|
196
|
+
Default: `process.argv.slice(2)`
|
|
197
|
+
|
|
198
|
+
Custom arguments object.
|
|
199
|
+
|
|
200
|
+
##### inferType
|
|
201
|
+
|
|
202
|
+
Type: `boolean`\
|
|
203
|
+
Default: `false`
|
|
204
|
+
|
|
205
|
+
Infer the argument type.
|
|
206
|
+
|
|
207
|
+
By default, the argument `5` in `$ foo 5` becomes a string. Enabling this would infer it as a number.
|
|
208
|
+
|
|
209
|
+
##### booleanDefault
|
|
210
|
+
|
|
211
|
+
Type: `boolean | undefined`\
|
|
212
|
+
Default: `false`
|
|
213
|
+
|
|
214
|
+
Value of `boolean` flags not defined in `argv`.
|
|
215
|
+
|
|
216
|
+
If set to `undefined`, the flags not defined in `argv` will be excluded from the result.
|
|
217
|
+
The `default` value set in `boolean` flags take precedence over `booleanDefault`.
|
|
218
|
+
|
|
219
|
+
_Note: If used in conjunction with `isMultiple`, the default flag value is set to `[]`._
|
|
220
|
+
|
|
221
|
+
__Caution: Explicitly specifying `undefined` for `booleanDefault` has different meaning from omitting key itself.__
|
|
222
|
+
|
|
223
|
+
Example:
|
|
224
|
+
|
|
225
|
+
```js
|
|
226
|
+
import meow from 'meow';
|
|
227
|
+
|
|
228
|
+
const cli = meow(`
|
|
229
|
+
Usage
|
|
230
|
+
$ foo
|
|
231
|
+
|
|
232
|
+
Options
|
|
233
|
+
--rainbow, -r Include a rainbow
|
|
234
|
+
--unicorn, -u Include a unicorn
|
|
235
|
+
--no-sparkles Exclude sparkles
|
|
236
|
+
|
|
237
|
+
Examples
|
|
238
|
+
$ foo
|
|
239
|
+
🌈 unicorns✨🌈
|
|
240
|
+
`, {
|
|
241
|
+
importMeta: import.meta,
|
|
242
|
+
booleanDefault: undefined,
|
|
243
|
+
flags: {
|
|
244
|
+
rainbow: {
|
|
245
|
+
type: 'boolean',
|
|
246
|
+
default: true,
|
|
247
|
+
shortFlag: 'r'
|
|
248
|
+
},
|
|
249
|
+
unicorn: {
|
|
250
|
+
type: 'boolean',
|
|
251
|
+
default: false,
|
|
252
|
+
shortFlag: 'u'
|
|
253
|
+
},
|
|
254
|
+
cake: {
|
|
255
|
+
type: 'boolean',
|
|
256
|
+
shortFlag: 'c'
|
|
257
|
+
},
|
|
258
|
+
sparkles: {
|
|
259
|
+
type: 'boolean',
|
|
260
|
+
default: true
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
/*
|
|
265
|
+
{
|
|
266
|
+
flags: {
|
|
267
|
+
rainbow: true,
|
|
268
|
+
unicorn: false,
|
|
269
|
+
sparkles: true
|
|
270
|
+
},
|
|
271
|
+
unnormalizedFlags: {
|
|
272
|
+
rainbow: true,
|
|
273
|
+
r: true,
|
|
274
|
+
unicorn: false,
|
|
275
|
+
u: false,
|
|
276
|
+
sparkles: true
|
|
277
|
+
},
|
|
278
|
+
…
|
|
279
|
+
}
|
|
280
|
+
*/
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
##### allowUnknownFlags
|
|
284
|
+
|
|
285
|
+
Type `boolean`\
|
|
286
|
+
Default: `true`
|
|
287
|
+
|
|
288
|
+
Whether to allow unknown flags or not.
|
|
289
|
+
|
|
290
|
+
##### helpIndent
|
|
291
|
+
|
|
292
|
+
Type `number`\
|
|
293
|
+
Default: `2`
|
|
294
|
+
|
|
295
|
+
The number of spaces to use for indenting the help text.
|
|
296
|
+
|
|
297
|
+
## Tips
|
|
298
|
+
|
|
299
|
+
See [`chalk`](https://github.com/chalk/chalk) if you want to colorize the terminal output.
|
|
300
|
+
|
|
301
|
+
See [`get-stdin`](https://github.com/sindresorhus/get-stdin) if you want to accept input from stdin.
|
|
302
|
+
|
|
303
|
+
See [`conf`](https://github.com/sindresorhus/conf) if you need to persist some data.
|
|
304
|
+
|
|
305
|
+
[More useful CLI utilities…](https://github.com/sindresorhus/awesome-nodejs#command-line-utilities)
|