@maizzle/framework 6.0.0-rc.1 → 6.0.0-rc.3
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.
- package/bin/maizzle.mjs +1 -1
- package/dist/build.mjs +2 -1
- package/dist/build.mjs.map +1 -1
- package/dist/config/index.mjs +7 -0
- package/dist/config/index.mjs.map +1 -1
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +13 -0
- package/dist/plugin.mjs.map +1 -1
- package/dist/render/createRenderer.d.mts +2 -0
- package/dist/render/createRenderer.d.mts.map +1 -1
- package/dist/render/createRenderer.mjs +11 -4
- package/dist/render/createRenderer.mjs.map +1 -1
- package/dist/render/index.mjs +2 -1
- package/dist/render/index.mjs.map +1 -1
- package/dist/serve.mjs +2 -1
- package/dist/serve.mjs.map +1 -1
- package/dist/types/config.d.mts +3 -0
- package/dist/types/config.d.mts.map +1 -1
- package/dist/utils/detect.d.mts +5 -0
- package/dist/utils/detect.d.mts.map +1 -0
- package/dist/utils/detect.mjs +11 -0
- package/dist/utils/detect.mjs.map +1 -0
- package/node_modules/@clack/core/CHANGELOG.md +87 -4
- package/node_modules/@clack/core/README.md +1 -1
- package/node_modules/@clack/core/dist/index.d.mts +186 -48
- package/node_modules/@clack/core/dist/index.mjs +10 -14
- package/node_modules/@clack/core/dist/index.mjs.map +1 -1
- package/node_modules/@clack/core/package.json +7 -9
- package/node_modules/@clack/prompts/CHANGELOG.md +171 -7
- package/node_modules/@clack/prompts/README.md +66 -3
- package/node_modules/@clack/prompts/dist/index.d.mts +302 -76
- package/node_modules/@clack/prompts/dist/index.mjs +134 -84
- package/node_modules/@clack/prompts/dist/index.mjs.map +1 -1
- package/node_modules/@clack/prompts/package.json +14 -10
- package/node_modules/citty/LICENSE +0 -15
- package/node_modules/citty/README.md +166 -69
- package/node_modules/citty/dist/index.d.mts +88 -56
- package/node_modules/citty/dist/index.mjs +399 -437
- package/node_modules/citty/package.json +28 -35
- package/node_modules/giget/README.md +59 -11
- package/node_modules/giget/dist/THIRD-PARTY-LICENSES.md +205 -0
- package/node_modules/giget/dist/_chunks/giget.mjs +508 -0
- package/node_modules/giget/dist/_chunks/libs/citty.mjs +269 -0
- package/node_modules/giget/dist/_chunks/libs/nypm.d.mts +1 -0
- package/node_modules/giget/dist/_chunks/libs/nypm.mjs +669 -0
- package/node_modules/giget/dist/_chunks/libs/tar.mjs +2931 -0
- package/node_modules/giget/dist/_chunks/rolldown-runtime.mjs +14 -0
- package/node_modules/giget/dist/cli.d.mts +1 -0
- package/node_modules/giget/dist/cli.mjs +89 -111
- package/node_modules/giget/dist/index.d.mts +46 -35
- package/node_modules/giget/dist/index.mjs +2 -22
- package/node_modules/giget/package.json +32 -45
- package/node_modules/maizzle/README.md +140 -0
- package/node_modules/maizzle/bin/maizzle.mjs +5 -0
- package/node_modules/maizzle/dist/commands/new.d.mts +7 -0
- package/node_modules/maizzle/dist/commands/new.mjs +278 -0
- package/node_modules/{@maizzle/cli → maizzle}/dist/index.d.mts +1 -1
- package/node_modules/maizzle/dist/index.mjs +44 -0
- package/node_modules/{commander → maizzle/node_modules/commander}/Readme.md +94 -67
- package/node_modules/{commander → maizzle/node_modules/commander}/lib/argument.js +5 -4
- package/node_modules/{commander → maizzle/node_modules/commander}/lib/command.js +154 -39
- package/node_modules/{commander → maizzle/node_modules/commander}/lib/help.js +77 -39
- package/node_modules/{commander → maizzle/node_modules/commander}/lib/option.js +16 -3
- package/node_modules/{commander → maizzle/node_modules/commander}/package-support.json +4 -1
- package/node_modules/{commander → maizzle/node_modules/commander}/package.json +8 -8
- package/node_modules/{commander → maizzle/node_modules/commander}/typings/index.d.ts +71 -3
- package/node_modules/{@maizzle/cli → maizzle}/package.json +13 -11
- package/node_modules/tinyexec/README.md +49 -3
- package/node_modules/tinyexec/dist/main.d.mts +25 -14
- package/node_modules/tinyexec/dist/main.mjs +148 -100
- package/node_modules/tinyexec/package.json +9 -8
- package/package.json +3 -3
- package/node_modules/@clack/core/dist/index.cjs +0 -15
- package/node_modules/@clack/core/dist/index.cjs.map +0 -1
- package/node_modules/@clack/core/dist/index.d.cts +0 -211
- package/node_modules/@clack/core/dist/index.d.ts +0 -211
- package/node_modules/@clack/prompts/dist/index.cjs +0 -87
- package/node_modules/@clack/prompts/dist/index.cjs.map +0 -1
- package/node_modules/@clack/prompts/dist/index.d.cts +0 -165
- package/node_modules/@clack/prompts/dist/index.d.ts +0 -165
- package/node_modules/@maizzle/cli/README.md +0 -58
- package/node_modules/@maizzle/cli/dist/index.mjs +0 -42
- package/node_modules/citty/dist/index.cjs +0 -475
- package/node_modules/citty/dist/index.d.cts +0 -80
- package/node_modules/citty/dist/index.d.ts +0 -80
- package/node_modules/consola/LICENSE +0 -47
- package/node_modules/consola/README.md +0 -352
- package/node_modules/consola/basic.d.ts +0 -1
- package/node_modules/consola/browser.d.ts +0 -1
- package/node_modules/consola/core.d.ts +0 -1
- package/node_modules/consola/dist/basic.cjs +0 -32
- package/node_modules/consola/dist/basic.d.cts +0 -23
- package/node_modules/consola/dist/basic.d.mts +0 -21
- package/node_modules/consola/dist/basic.d.ts +0 -23
- package/node_modules/consola/dist/basic.mjs +0 -24
- package/node_modules/consola/dist/browser.cjs +0 -84
- package/node_modules/consola/dist/browser.d.cts +0 -23
- package/node_modules/consola/dist/browser.d.mts +0 -21
- package/node_modules/consola/dist/browser.d.ts +0 -23
- package/node_modules/consola/dist/browser.mjs +0 -76
- package/node_modules/consola/dist/chunks/prompt.cjs +0 -288
- package/node_modules/consola/dist/chunks/prompt.mjs +0 -280
- package/node_modules/consola/dist/core.cjs +0 -517
- package/node_modules/consola/dist/core.d.cts +0 -459
- package/node_modules/consola/dist/core.d.mts +0 -459
- package/node_modules/consola/dist/core.d.ts +0 -459
- package/node_modules/consola/dist/core.mjs +0 -512
- package/node_modules/consola/dist/index.cjs +0 -663
- package/node_modules/consola/dist/index.d.cts +0 -24
- package/node_modules/consola/dist/index.d.mts +0 -22
- package/node_modules/consola/dist/index.d.ts +0 -24
- package/node_modules/consola/dist/index.mjs +0 -651
- package/node_modules/consola/dist/shared/consola.DCGIlDNP.cjs +0 -75
- package/node_modules/consola/dist/shared/consola.DRwqZj3T.mjs +0 -72
- package/node_modules/consola/dist/shared/consola.DXBYu-KD.mjs +0 -288
- package/node_modules/consola/dist/shared/consola.DwRq1yyg.cjs +0 -312
- package/node_modules/consola/dist/utils.cjs +0 -64
- package/node_modules/consola/dist/utils.d.cts +0 -286
- package/node_modules/consola/dist/utils.d.mts +0 -286
- package/node_modules/consola/dist/utils.d.ts +0 -286
- package/node_modules/consola/dist/utils.mjs +0 -54
- package/node_modules/consola/lib/index.cjs +0 -10
- package/node_modules/consola/package.json +0 -136
- package/node_modules/consola/utils.d.ts +0 -1
- package/node_modules/create-maizzle/README.md +0 -86
- package/node_modules/create-maizzle/bin/create-maizzle.mjs +0 -4
- package/node_modules/create-maizzle/node_modules/@clack/core/CHANGELOG.md +0 -340
- package/node_modules/create-maizzle/node_modules/@clack/core/LICENSE +0 -9
- package/node_modules/create-maizzle/node_modules/@clack/core/README.md +0 -22
- package/node_modules/create-maizzle/node_modules/@clack/core/dist/index.d.mts +0 -349
- package/node_modules/create-maizzle/node_modules/@clack/core/dist/index.mjs +0 -11
- package/node_modules/create-maizzle/node_modules/@clack/core/dist/index.mjs.map +0 -1
- package/node_modules/create-maizzle/node_modules/@clack/core/package.json +0 -60
- package/node_modules/create-maizzle/node_modules/@clack/prompts/CHANGELOG.md +0 -576
- package/node_modules/create-maizzle/node_modules/@clack/prompts/LICENSE +0 -9
- package/node_modules/create-maizzle/node_modules/@clack/prompts/README.md +0 -270
- package/node_modules/create-maizzle/node_modules/@clack/prompts/dist/index.d.mts +0 -391
- package/node_modules/create-maizzle/node_modules/@clack/prompts/dist/index.mjs +0 -137
- package/node_modules/create-maizzle/node_modules/@clack/prompts/dist/index.mjs.map +0 -1
- package/node_modules/create-maizzle/node_modules/@clack/prompts/package.json +0 -65
- package/node_modules/create-maizzle/package.json +0 -47
- package/node_modules/create-maizzle/src/index.js +0 -242
- package/node_modules/defu/LICENSE +0 -21
- package/node_modules/defu/README.md +0 -171
- package/node_modules/defu/dist/defu.cjs +0 -77
- package/node_modules/defu/dist/defu.d.cts +0 -31
- package/node_modules/defu/dist/defu.d.mts +0 -29
- package/node_modules/defu/dist/defu.d.ts +0 -31
- package/node_modules/defu/dist/defu.mjs +0 -69
- package/node_modules/defu/lib/defu.cjs +0 -10
- package/node_modules/defu/lib/defu.d.cts +0 -12
- package/node_modules/defu/package.json +0 -48
- package/node_modules/giget/dist/shared/giget.OCaTp9b-.mjs +0 -468
- package/node_modules/node-fetch-native/LICENSE +0 -114
- package/node_modules/node-fetch-native/README.md +0 -225
- package/node_modules/node-fetch-native/dist/chunks/multipart-parser.cjs +0 -2
- package/node_modules/node-fetch-native/dist/chunks/multipart-parser.mjs +0 -2
- package/node_modules/node-fetch-native/dist/index.cjs +0 -1
- package/node_modules/node-fetch-native/dist/index.mjs +0 -1
- package/node_modules/node-fetch-native/dist/native.cjs +0 -1
- package/node_modules/node-fetch-native/dist/native.mjs +0 -1
- package/node_modules/node-fetch-native/dist/node.cjs +0 -19
- package/node_modules/node-fetch-native/dist/node.mjs +0 -19
- package/node_modules/node-fetch-native/dist/polyfill.cjs +0 -1
- package/node_modules/node-fetch-native/dist/polyfill.mjs +0 -1
- package/node_modules/node-fetch-native/dist/proxy-stub.cjs +0 -1
- package/node_modules/node-fetch-native/dist/proxy-stub.mjs +0 -1
- package/node_modules/node-fetch-native/dist/proxy.cjs +0 -58
- package/node_modules/node-fetch-native/dist/shared/node-fetch-native.DfbY2q-x.mjs +0 -1
- package/node_modules/node-fetch-native/dist/shared/node-fetch-native.DhEqb06g.cjs +0 -1
- package/node_modules/node-fetch-native/index.d.ts +0 -1
- package/node_modules/node-fetch-native/lib/empty.cjs +0 -0
- package/node_modules/node-fetch-native/lib/empty.mjs +0 -0
- package/node_modules/node-fetch-native/lib/index.cjs +0 -11
- package/node_modules/node-fetch-native/lib/index.d.cts +0 -10
- package/node_modules/node-fetch-native/lib/index.d.mts +0 -10
- package/node_modules/node-fetch-native/lib/index.d.ts +0 -10
- package/node_modules/node-fetch-native/lib/native.cjs +0 -11
- package/node_modules/node-fetch-native/lib/polyfill.d.cts +0 -1
- package/node_modules/node-fetch-native/lib/polyfill.d.mts +0 -1
- package/node_modules/node-fetch-native/lib/polyfill.d.ts +0 -1
- package/node_modules/node-fetch-native/lib/proxy.d.ts +0 -32
- package/node_modules/node-fetch-native/node.d.ts +0 -1
- package/node_modules/node-fetch-native/package.json +0 -138
- package/node_modules/node-fetch-native/polyfill.d.ts +0 -1
- package/node_modules/node-fetch-native/proxy.d.ts +0 -1
- package/node_modules/nypm/node_modules/citty/LICENSE +0 -21
- package/node_modules/nypm/node_modules/citty/README.md +0 -231
- package/node_modules/nypm/node_modules/citty/dist/index.d.mts +0 -112
- package/node_modules/nypm/node_modules/citty/dist/index.mjs +0 -425
- package/node_modules/nypm/node_modules/citty/package.json +0 -42
- /package/node_modules/{nypm/node_modules/citty → citty}/dist/THIRD-PARTY-LICENSES.md +0 -0
- /package/node_modules/{nypm/node_modules/citty → citty}/dist/_chunks/libs/scule.mjs +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/LICENSE +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/component.d.mts +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/component.mjs +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/config.d.mts +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/config.mjs +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/layout.d.mts +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/layout.mjs +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/scaffold.d.mts +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/scaffold.mjs +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/stubs/component.vue +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/stubs/config.ts +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/stubs/layout.vue +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/stubs/template.vue +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/template.d.mts +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/template.mjs +0 -0
- /package/node_modules/{commander → maizzle/node_modules/commander}/LICENSE +0 -0
- /package/node_modules/{commander → maizzle/node_modules/commander}/esm.mjs +0 -0
- /package/node_modules/{commander → maizzle/node_modules/commander}/index.js +0 -0
- /package/node_modules/{commander → maizzle/node_modules/commander}/lib/error.js +0 -0
- /package/node_modules/{commander → maizzle/node_modules/commander}/lib/suggestSimilar.js +0 -0
- /package/node_modules/{commander → maizzle/node_modules/commander}/typings/esm.d.mts +0 -0
|
@@ -38,6 +38,7 @@ Read this in other languages: English | [简体中文](./Readme_zh-CN.md)
|
|
|
38
38
|
- [.description and .summary](#description-and-summary)
|
|
39
39
|
- [.helpOption(flags, description)](#helpoptionflags-description)
|
|
40
40
|
- [.helpCommand()](#helpcommand)
|
|
41
|
+
- [Help Groups](#help-groups)
|
|
41
42
|
- [More configuration](#more-configuration-2)
|
|
42
43
|
- [Custom event listeners](#custom-event-listeners)
|
|
43
44
|
- [Bits and pieces](#bits-and-pieces)
|
|
@@ -153,7 +154,7 @@ This is used in the examples in this README for brevity.
|
|
|
153
154
|
const { program } = require('commander');
|
|
154
155
|
```
|
|
155
156
|
|
|
156
|
-
For larger programs which may use commander in multiple ways, including unit testing, it is better to create a local Command object to use.
|
|
157
|
+
For larger programs which may use commander in multiple ways, including unit testing, it is better to create a local `Command` object to use.
|
|
157
158
|
|
|
158
159
|
```js
|
|
159
160
|
// CommonJS (.cjs)
|
|
@@ -175,8 +176,7 @@ const program = new Command();
|
|
|
175
176
|
|
|
176
177
|
## Options
|
|
177
178
|
|
|
178
|
-
Options are defined with the `.option()` method, also serving as documentation for the options. Each option can have a short flag (single character) and a long name, separated by a comma
|
|
179
|
-
single characters, you may also have two long options. Examples:
|
|
179
|
+
Options are defined with the `.option()` method, also serving as documentation for the options. Each option can have a short flag (single character) and a long name, separated by a comma, a space, or a vertical bar (`|`). To allow a wider range of short-ish flags than just single characters, you may also have two long options.
|
|
180
180
|
|
|
181
181
|
```js
|
|
182
182
|
program
|
|
@@ -187,9 +187,9 @@ program
|
|
|
187
187
|
|
|
188
188
|
The parsed options can be accessed by calling `.opts()` on a `Command` object, and are passed to the action handler.
|
|
189
189
|
|
|
190
|
-
Multi-word options
|
|
190
|
+
Multi-word options like `--template-engine` are normalized to camelCase option names, resulting in properties such as `program.opts().templateEngine`.
|
|
191
191
|
|
|
192
|
-
An option and its option-argument can be separated by a space, or combined into the same argument. The option-argument can follow the short option directly or follow an `=` for a long option.
|
|
192
|
+
An option and its option-argument can be separated by a space, or combined into the same argument. The option-argument can follow the short option directly, or follow an `=` for a long option.
|
|
193
193
|
|
|
194
194
|
```sh
|
|
195
195
|
serve -p 80
|
|
@@ -244,7 +244,7 @@ pizza details:
|
|
|
244
244
|
```
|
|
245
245
|
|
|
246
246
|
Multiple boolean short options may be combined following the dash, and may be followed by a single short option taking a value.
|
|
247
|
-
For example `-d -s -p cheese` may be written as `-ds -p cheese` or even `-dsp cheese`.
|
|
247
|
+
For example, `-d -s -p cheese` may be written as `-ds -p cheese` or even `-dsp cheese`.
|
|
248
248
|
|
|
249
249
|
Options with an expected option-argument are greedy and will consume the following argument whatever the value.
|
|
250
250
|
So `--id -xyz` reads `-xyz` as the option-argument.
|
|
@@ -275,8 +275,8 @@ cheese: stilton
|
|
|
275
275
|
|
|
276
276
|
### Other option types, negatable boolean and boolean|value
|
|
277
277
|
|
|
278
|
-
You can define a boolean option long name with a leading `no-` to set the option value to false when used.
|
|
279
|
-
Defined alone this also makes the option true by default.
|
|
278
|
+
You can define a boolean option long name with a leading `no-` to set the option value to `false` when used.
|
|
279
|
+
Defined alone, this also makes the option `true` by default.
|
|
280
280
|
|
|
281
281
|
If you define `--foo` first, adding `--no-foo` does not change the default value from what it would
|
|
282
282
|
otherwise be.
|
|
@@ -308,7 +308,7 @@ You ordered a pizza with no sauce and no cheese
|
|
|
308
308
|
```
|
|
309
309
|
|
|
310
310
|
You can specify an option which may be used as a boolean option but may optionally take an option-argument
|
|
311
|
-
(declared with square brackets like `--optional [value]`).
|
|
311
|
+
(declared with square brackets, like `--optional [value]`).
|
|
312
312
|
|
|
313
313
|
Example file: [options-boolean-or-value.js](./examples/options-boolean-or-value.js)
|
|
314
314
|
|
|
@@ -334,13 +334,16 @@ add cheese type mozzarella
|
|
|
334
334
|
```
|
|
335
335
|
|
|
336
336
|
Options with an optional option-argument are not greedy and will ignore arguments starting with a dash.
|
|
337
|
-
So `id` behaves as a boolean option for `--id -
|
|
337
|
+
So `id` behaves as a boolean option for `--id -ABCD`, but you can use a combined form if needed like `--id=-ABCD`.
|
|
338
|
+
Negative numbers are special and are accepted as an option-argument.
|
|
338
339
|
|
|
339
340
|
For information about possible ambiguous cases, see [options taking varying arguments](./docs/options-in-depth.md).
|
|
340
341
|
|
|
341
342
|
### Required option
|
|
342
343
|
|
|
343
|
-
You may specify a required (mandatory) option using `.requiredOption()`. The option must have a value after parsing, usually specified on the command line, or perhaps from a default value (
|
|
344
|
+
You may specify a required (mandatory) option using `.requiredOption()`. The option must have a value after parsing, usually specified on the command line, or perhaps from a default value (e.g., from environment).
|
|
345
|
+
|
|
346
|
+
The method is otherwise the same as `.option()` in format, taking flags and description, and optional default value or custom processing.
|
|
344
347
|
|
|
345
348
|
Example file: [options-required.js](./examples/options-required.js)
|
|
346
349
|
|
|
@@ -361,7 +364,7 @@ error: required option '-c, --cheese <type>' not specified
|
|
|
361
364
|
You may make an option variadic by appending `...` to the value placeholder when declaring the option. On the command line you
|
|
362
365
|
can then specify multiple option-arguments, and the parsed option value will be an array. The extra arguments
|
|
363
366
|
are read until the first argument starting with a dash. The special argument `--` stops option processing entirely. If a value
|
|
364
|
-
is specified in the same argument as the option then no further values are read.
|
|
367
|
+
is specified in the same argument as the option, then no further values are read.
|
|
365
368
|
|
|
366
369
|
Example file: [options-variadic.js](./examples/options-variadic.js)
|
|
367
370
|
|
|
@@ -392,7 +395,7 @@ For information about possible ambiguous cases, see [options taking varying argu
|
|
|
392
395
|
|
|
393
396
|
### Version option
|
|
394
397
|
|
|
395
|
-
The optional
|
|
398
|
+
The optional `.version()` method adds handling for displaying the command version. The default option flags are `-V` and `--version`. When used, the command prints the version number and exits.
|
|
396
399
|
|
|
397
400
|
```js
|
|
398
401
|
program.version('0.0.1');
|
|
@@ -403,8 +406,8 @@ $ ./examples/pizza -V
|
|
|
403
406
|
0.0.1
|
|
404
407
|
```
|
|
405
408
|
|
|
406
|
-
You may change the flags and description by passing additional parameters to the
|
|
407
|
-
the same syntax for flags as the
|
|
409
|
+
You may change the flags and description by passing additional parameters to the `.version()` method, using
|
|
410
|
+
the same syntax for flags as the `.option()` method.
|
|
408
411
|
|
|
409
412
|
```js
|
|
410
413
|
program.version('0.0.1', '-v, --vers', 'output the current version');
|
|
@@ -451,7 +454,7 @@ $ extra --disable-server --port 8000
|
|
|
451
454
|
error: option '--disable-server' cannot be used with option '-p, --port <number>'
|
|
452
455
|
```
|
|
453
456
|
|
|
454
|
-
Specify a required (mandatory) option using the `Option` method `.makeOptionMandatory()`. This matches the `Command` method [
|
|
457
|
+
Specify a required (mandatory) option using the `Option` method `.makeOptionMandatory()`. This matches the `Command` method [`.requiredOption()`](#required-option).
|
|
455
458
|
|
|
456
459
|
### Custom option processing
|
|
457
460
|
|
|
@@ -519,7 +522,9 @@ $ custom --list x,y,z
|
|
|
519
522
|
|
|
520
523
|
## Commands
|
|
521
524
|
|
|
522
|
-
You can specify (sub)commands using `.command()` or `.addCommand()`. There are two ways these can be implemented: using an action handler attached to the command
|
|
525
|
+
You can specify (sub)commands using `.command()` or `.addCommand()`. There are two ways these can be implemented: using an `.action()` handler attached to the command; or as a stand-alone executable file. (More detail about this later.)
|
|
526
|
+
|
|
527
|
+
Subcommands may be nested. Example file: [nestedCommands.js](./examples/nestedCommands.js).
|
|
523
528
|
|
|
524
529
|
In the first parameter to `.command()` you specify the command name. You may append the command-arguments after the command name, or specify them separately using `.argument()`. The arguments may be `<required>` or `[optional]`, and the last argument may also be `variadic...`.
|
|
525
530
|
|
|
@@ -551,21 +556,20 @@ program
|
|
|
551
556
|
|
|
552
557
|
Configuration options can be passed with the call to `.command()` and `.addCommand()`. Specifying `hidden: true` will
|
|
553
558
|
remove the command from the generated help output. Specifying `isDefault: true` will run the subcommand if no other
|
|
554
|
-
subcommand is specified ([
|
|
559
|
+
subcommand is specified. (Example file: [defaultCommand.js](./examples/defaultCommand.js).)
|
|
555
560
|
|
|
556
|
-
You can add alternative names for a command with `.alias()`. ([
|
|
561
|
+
You can add alternative names for a command with `.alias()`. (Example file: [alias.js](./examples/alias.js).)
|
|
557
562
|
|
|
558
|
-
`.command()` automatically copies the inherited settings from the parent command to the newly created subcommand. This is only done during creation
|
|
563
|
+
`.command()` automatically copies the inherited settings from the parent command to the newly created subcommand. This is only done during creation; any later setting changes to the parent are not inherited.
|
|
559
564
|
|
|
560
565
|
For safety, `.addCommand()` does not automatically copy the inherited settings from the parent command. There is a helper routine `.copyInheritedSettings()` for copying the settings when they are wanted.
|
|
561
566
|
|
|
562
567
|
### Command-arguments
|
|
563
568
|
|
|
564
569
|
For subcommands, you can specify the argument syntax in the call to `.command()` (as shown above). This
|
|
565
|
-
is the only method usable for subcommands implemented using a stand-alone executable
|
|
566
|
-
you can instead use the following method.
|
|
570
|
+
is the only method usable for subcommands implemented using a stand-alone executable.
|
|
567
571
|
|
|
568
|
-
To configure a command, you can use `.argument()` to specify each expected command-argument.
|
|
572
|
+
Alternatively, you can instead use the following method. To configure a command, you can use `.argument()` to specify each expected command-argument.
|
|
569
573
|
You supply the argument name and an optional description. The argument may be `<required>` or `[optional]`.
|
|
570
574
|
You can specify a default value for an optional command-argument.
|
|
571
575
|
|
|
@@ -582,8 +586,10 @@ program
|
|
|
582
586
|
});
|
|
583
587
|
```
|
|
584
588
|
|
|
585
|
-
|
|
586
|
-
|
|
589
|
+
The last argument of a command can be variadic, and _only_ the last argument. To make an argument variadic, simply
|
|
590
|
+
append `...` to the argument name.
|
|
591
|
+
|
|
592
|
+
A variadic argument is passed to the action handler as an array.
|
|
587
593
|
|
|
588
594
|
```js
|
|
589
595
|
program
|
|
@@ -660,7 +666,7 @@ program
|
|
|
660
666
|
});
|
|
661
667
|
```
|
|
662
668
|
|
|
663
|
-
If you prefer, you can work with the command directly and skip declaring the parameters for the action handler.
|
|
669
|
+
If you prefer, you can work with the command directly and skip declaring the parameters for the action handler. If you use a function expression (but not an arrow function), the `this` keyword is set to the running command.
|
|
664
670
|
|
|
665
671
|
Example file: [action-this.js](./examples/action-this.js)
|
|
666
672
|
|
|
@@ -674,7 +680,7 @@ program
|
|
|
674
680
|
});
|
|
675
681
|
```
|
|
676
682
|
|
|
677
|
-
You may supply an `async` action handler, in which case you call `.parseAsync` rather than `.parse`.
|
|
683
|
+
You may supply an `async` action handler, in which case you call `.parseAsync()` rather than `.parse()`.
|
|
678
684
|
|
|
679
685
|
```js
|
|
680
686
|
async function run() { /* code goes here */ }
|
|
@@ -687,12 +693,14 @@ async function main() {
|
|
|
687
693
|
}
|
|
688
694
|
```
|
|
689
695
|
|
|
690
|
-
A command's options and arguments on the command line are validated when the command is used. Any unknown options
|
|
696
|
+
A command's options and arguments on the command line are validated when the command is used. Any unknown options, missing arguments, or excess arguments will be reported as an error.
|
|
697
|
+
|
|
698
|
+
You can suppress the unknown option check with `.allowUnknownOption()`. You can suppress the excess arguments check with `.allowExcessArguments()`.
|
|
691
699
|
|
|
692
700
|
### Stand-alone executable (sub)commands
|
|
693
701
|
|
|
694
702
|
When `.command()` is invoked with a description argument, this tells Commander that you're going to use stand-alone executables for subcommands.
|
|
695
|
-
Commander will search the files in the directory of the entry script for a file with the name combination `command-subcommand
|
|
703
|
+
Commander will search the files in the directory of the entry script for a file with the name combination `command-subcommand` (like `pm-install` or `pm-search` in the example below). The search includes trying common file extensions, like `.js`.
|
|
696
704
|
You may specify a custom name (and path) with the `executableFile` configuration option.
|
|
697
705
|
You may specify a custom search directory for subcommands with `.executableDir()`.
|
|
698
706
|
|
|
@@ -732,7 +740,7 @@ program
|
|
|
732
740
|
});
|
|
733
741
|
```
|
|
734
742
|
|
|
735
|
-
The callback hook can be `async`, in which case you call `.parseAsync` rather than `.parse`. You can add multiple hooks per event.
|
|
743
|
+
The callback hook can be `async`, in which case you call `.parseAsync()` rather than `.parse()`. You can add multiple hooks per event.
|
|
736
744
|
|
|
737
745
|
The supported events are:
|
|
738
746
|
|
|
@@ -741,7 +749,7 @@ The supported events are:
|
|
|
741
749
|
| `preAction`, `postAction` | before/after action handler for this command and its nested subcommands | `(thisCommand, actionCommand)` |
|
|
742
750
|
| `preSubcommand` | before parsing direct subcommand | `(thisCommand, subcommand)` |
|
|
743
751
|
|
|
744
|
-
For an overview of the life cycle events see [parsing life cycle and hooks](./docs/parsing-and-hooks.md).
|
|
752
|
+
For an overview of the life cycle events, see [parsing life cycle and hooks](./docs/parsing-and-hooks.md).
|
|
745
753
|
|
|
746
754
|
## Automated help
|
|
747
755
|
|
|
@@ -816,8 +824,8 @@ The positions "beforeAll" and "afterAll" apply to the command and all its subcom
|
|
|
816
824
|
|
|
817
825
|
The second parameter can be a string, or a function returning a string. The function is passed a context object for your convenience. The properties are:
|
|
818
826
|
|
|
819
|
-
- error
|
|
820
|
-
- command
|
|
827
|
+
- `error`: a boolean for whether the help is being displayed due to a usage error
|
|
828
|
+
- `command`: the `Command` which is displaying the help
|
|
821
829
|
|
|
822
830
|
### Display help after errors
|
|
823
831
|
|
|
@@ -861,7 +869,7 @@ error: unknown option '--hepl'
|
|
|
861
869
|
|
|
862
870
|
The command name appears in the help, and is also used for locating stand-alone executable subcommands.
|
|
863
871
|
|
|
864
|
-
You may specify the program name using `.name()` or in the Command constructor. For the program, Commander will
|
|
872
|
+
You may specify the program name using `.name()` or in the `Command` constructor. For the program, Commander will
|
|
865
873
|
fall back to using the script name from the full arguments passed into `.parse()`. However, the script name varies
|
|
866
874
|
depending on how your program is launched, so you may wish to specify it explicitly.
|
|
867
875
|
|
|
@@ -871,7 +879,7 @@ const pm = new Command('pm');
|
|
|
871
879
|
```
|
|
872
880
|
|
|
873
881
|
Subcommands get a name when specified using `.command()`. If you create the subcommand yourself to use with `.addCommand()`,
|
|
874
|
-
then set the name using `.name()` or in the Command constructor.
|
|
882
|
+
then set the name using `.name()` or in the `Command` constructor.
|
|
875
883
|
|
|
876
884
|
### .usage
|
|
877
885
|
|
|
@@ -905,18 +913,18 @@ This may require additional disk space.
|
|
|
905
913
|
|
|
906
914
|
### .helpOption(flags, description)
|
|
907
915
|
|
|
908
|
-
By default, every command has a help option. You may change the default help flags and description. Pass false to disable the built-in help option.
|
|
916
|
+
By default, every command has a help option. You may change the default help flags and description. Pass `false` to disable the built-in help option.
|
|
909
917
|
|
|
910
918
|
```js
|
|
911
919
|
program
|
|
912
920
|
.helpOption('-e, --HELP', 'read more information');
|
|
913
921
|
```
|
|
914
922
|
|
|
915
|
-
|
|
923
|
+
Alternatively, use `.addHelpOption()` to add an option you construct yourself.
|
|
916
924
|
|
|
917
925
|
### .helpCommand()
|
|
918
926
|
|
|
919
|
-
A help command is added by default if your command has subcommands. You can explicitly turn
|
|
927
|
+
A help command is added by default if your command has subcommands. You can explicitly turn the implicit help command on or off with `.helpCommand(true)` and `.helpCommand(false)`.
|
|
920
928
|
|
|
921
929
|
You can both turn on and customise the help command by supplying the name and description:
|
|
922
930
|
|
|
@@ -924,20 +932,30 @@ You can both turn on and customise the help command by supplying the name and de
|
|
|
924
932
|
program.helpCommand('assist [command]', 'show assistance');
|
|
925
933
|
```
|
|
926
934
|
|
|
927
|
-
|
|
935
|
+
Alternatively, use `.addHelpCommand()` to add a command you construct yourself.
|
|
936
|
+
|
|
937
|
+
### Help Groups
|
|
938
|
+
|
|
939
|
+
The help by default lists options under the the heading `Options:` and commands under `Commands:`. You can create your own groups
|
|
940
|
+
with different headings.
|
|
941
|
+
|
|
942
|
+
- The high-level way is to set the desired group heading while adding the options and commands, using `.optionsGroup()` and `.commandsGroup()`.
|
|
943
|
+
- The low-level way is using `.helpGroup()` on an individual `Option` or `Command`.
|
|
944
|
+
|
|
945
|
+
Example file: [help-groups.js](./examples/help-groups.js)
|
|
928
946
|
|
|
929
947
|
### More configuration
|
|
930
948
|
|
|
931
|
-
The built-in help is formatted using the Help class.
|
|
932
|
-
You can configure the help by modifying data properties and methods using `.configureHelp()`, or by subclassing Help using `.createHelp()` .
|
|
949
|
+
The built-in help is formatted using the `Help` class.
|
|
950
|
+
You can configure the help by modifying data properties and methods using `.configureHelp()`, or by subclassing `Help` using `.createHelp()` .
|
|
933
951
|
|
|
934
|
-
Simple properties include `sortSubcommands`, `sortOptions`, and `showGlobalOptions`. You can add color using the style methods like
|
|
952
|
+
Simple properties include `sortSubcommands`, `sortOptions`, and `showGlobalOptions`. You can add color using the style methods like `.styleTitle()`.
|
|
935
953
|
|
|
936
|
-
For more detail and examples of changing the displayed text, color, and layout see (./docs/help-in-depth.md)
|
|
954
|
+
For more detail and examples of changing the displayed text, color, and layout, see: [Help in Depth](./docs/help-in-depth.md).
|
|
937
955
|
|
|
938
956
|
## Custom event listeners
|
|
939
957
|
|
|
940
|
-
You can execute custom actions by listening to command and option events.
|
|
958
|
+
You can execute custom actions by listening to `command` and `option` events.
|
|
941
959
|
|
|
942
960
|
```js
|
|
943
961
|
program.on('option:verbose', function () {
|
|
@@ -951,7 +969,7 @@ program.on('option:verbose', function () {
|
|
|
951
969
|
|
|
952
970
|
Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
|
|
953
971
|
|
|
954
|
-
Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
|
|
972
|
+
Or, call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
|
|
955
973
|
|
|
956
974
|
- `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
|
|
957
975
|
- `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
|
|
@@ -965,7 +983,7 @@ program.parse(process.argv); // assume argv[0] is app and argv[1] is script
|
|
|
965
983
|
program.parse(['--port', '80'], { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
|
966
984
|
```
|
|
967
985
|
|
|
968
|
-
Use parseAsync instead of parse if any of your action handlers are async.
|
|
986
|
+
Use `.parseAsync()` instead of `.parse()` if any of your action handlers are async.
|
|
969
987
|
|
|
970
988
|
### Parsing Configuration
|
|
971
989
|
|
|
@@ -999,14 +1017,16 @@ program arg --port=80
|
|
|
999
1017
|
|
|
1000
1018
|
By default, the option processing shows an error for an unknown option. To have an unknown option treated as an ordinary command-argument and continue looking for options, use `.allowUnknownOption()`. This lets you mix known and unknown options.
|
|
1001
1019
|
|
|
1002
|
-
By default, the argument processing
|
|
1003
|
-
To
|
|
1020
|
+
By default, the argument processing displays an error for more command-arguments than expected.
|
|
1021
|
+
To suppress the error for excess arguments, use `.allowExcessArguments()`.
|
|
1004
1022
|
|
|
1005
1023
|
### Legacy options as properties
|
|
1006
1024
|
|
|
1007
1025
|
Before Commander 7, the option values were stored as properties on the command.
|
|
1008
1026
|
This was convenient to code, but the downside was possible clashes with
|
|
1009
|
-
existing properties of `Command`.
|
|
1027
|
+
existing properties of `Command`.
|
|
1028
|
+
|
|
1029
|
+
You can revert to the old behaviour to run unmodified legacy code by using `.storeOptionsAsProperties()`.
|
|
1010
1030
|
|
|
1011
1031
|
```js
|
|
1012
1032
|
program
|
|
@@ -1021,15 +1041,15 @@ program
|
|
|
1021
1041
|
|
|
1022
1042
|
### TypeScript
|
|
1023
1043
|
|
|
1024
|
-
extra-typings
|
|
1044
|
+
**extra-typings:** There is an optional project to infer extra type information from the option and argument definitions.
|
|
1025
1045
|
This adds strong typing to the options returned by `.opts()` and the parameters to `.action()`.
|
|
1026
|
-
|
|
1046
|
+
For more, see the repo: [commander-js/extra-typings](https://github.com/commander-js/extra-typings).
|
|
1027
1047
|
|
|
1028
|
-
```
|
|
1048
|
+
```ts
|
|
1029
1049
|
import { Command } from '@commander-js/extra-typings';
|
|
1030
1050
|
```
|
|
1031
1051
|
|
|
1032
|
-
ts-node
|
|
1052
|
+
**ts-node:** If you use `ts-node` and stand-alone executable subcommands written as `.ts` files, you need to call your program through node to get the subcommands called correctly, e.g.:
|
|
1033
1053
|
|
|
1034
1054
|
```sh
|
|
1035
1055
|
node -r ts-node/register pm.ts
|
|
@@ -1044,16 +1064,16 @@ const { createCommand } = require('commander');
|
|
|
1044
1064
|
const program = createCommand();
|
|
1045
1065
|
```
|
|
1046
1066
|
|
|
1047
|
-
`createCommand` is also a method of the Command object, and creates a new command rather than a subcommand. This gets used internally
|
|
1067
|
+
`createCommand()` is also a method of the `Command` object, and creates a new command rather than a subcommand. This gets used internally
|
|
1048
1068
|
when creating subcommands using `.command()`, and you may override it to
|
|
1049
|
-
customise the new subcommand
|
|
1069
|
+
customise the new subcommand. Example file: [custom-command-class.js](./examples/custom-command-class.js).
|
|
1050
1070
|
|
|
1051
1071
|
### Node options such as `--harmony`
|
|
1052
1072
|
|
|
1053
1073
|
You can enable `--harmony` option in two ways:
|
|
1054
1074
|
|
|
1055
|
-
- Use `#! /usr/bin/env node --harmony` in the subcommands scripts. (Note Windows does not support this pattern.)
|
|
1056
|
-
- Use the `--harmony` option when
|
|
1075
|
+
- Use `#! /usr/bin/env node --harmony` in the subcommands scripts. (Note: Windows does not support this pattern.)
|
|
1076
|
+
- Use the `--harmony` option when calling the command, like `node --harmony examples/pm publish`. The `--harmony` option will be preserved when spawning subcommand processes.
|
|
1057
1077
|
|
|
1058
1078
|
### Debugging stand-alone executable subcommands
|
|
1059
1079
|
|
|
@@ -1062,14 +1082,14 @@ An executable subcommand is launched as a separate child process.
|
|
|
1062
1082
|
If you are using the node inspector for [debugging](https://nodejs.org/en/docs/guides/debugging-getting-started/) executable subcommands using `node --inspect` et al.,
|
|
1063
1083
|
the inspector port is incremented by 1 for the spawned subcommand.
|
|
1064
1084
|
|
|
1065
|
-
If you are using VSCode to debug executable subcommands you need to set the `"autoAttachChildProcesses": true` flag in your launch.json configuration.
|
|
1085
|
+
If you are using VSCode to debug executable subcommands you need to set the `"autoAttachChildProcesses": true` flag in your `launch.json` configuration.
|
|
1066
1086
|
|
|
1067
1087
|
### npm run-script
|
|
1068
1088
|
|
|
1069
|
-
By default, when you call your program using run-script
|
|
1089
|
+
By default, when you call your program using `run-script`, `npm` will parse any options on the command-line and they will not reach your program. Use
|
|
1070
1090
|
`--` to stop the npm option parsing and pass through all the arguments.
|
|
1071
1091
|
|
|
1072
|
-
The synopsis for [npm run-script](https://docs.npmjs.com/cli/v9/commands/npm-run-script) explicitly shows the `--` for this reason:
|
|
1092
|
+
The synopsis for [`npm run-script`](https://docs.npmjs.com/cli/v9/commands/npm-run-script) explicitly shows the `--` for this reason:
|
|
1073
1093
|
|
|
1074
1094
|
```console
|
|
1075
1095
|
npm run-script <command> [-- <args>]
|
|
@@ -1079,7 +1099,7 @@ npm run-script <command> [-- <args>]
|
|
|
1079
1099
|
|
|
1080
1100
|
This routine is available to invoke the Commander error handling for your own error conditions. (See also the next section about exit handling.)
|
|
1081
1101
|
|
|
1082
|
-
As well as the error message, you can optionally specify the `exitCode` (used with `process.exit`)
|
|
1102
|
+
As well as the error message, you can optionally specify the `exitCode` (used with `process.exit()`)
|
|
1083
1103
|
and `code` (used with `CommanderError`).
|
|
1084
1104
|
|
|
1085
1105
|
```js
|
|
@@ -1089,12 +1109,16 @@ program.error('Custom processing has failed', { exitCode: 2, code: 'my.custom.er
|
|
|
1089
1109
|
|
|
1090
1110
|
### Override exit and output handling
|
|
1091
1111
|
|
|
1092
|
-
By default, Commander calls `process.exit` when it detects errors, or after displaying the help or version. You can override
|
|
1112
|
+
By default, Commander calls `process.exit()` when it detects errors, or after displaying the help or version. You can override
|
|
1093
1113
|
this behaviour and optionally supply a callback. The default override throws a `CommanderError`.
|
|
1094
1114
|
|
|
1095
|
-
The override callback is passed a `CommanderError` with properties
|
|
1096
|
-
|
|
1097
|
-
|
|
1115
|
+
The override callback is passed a `CommanderError` with the properties:
|
|
1116
|
+
- `exitCode`: number
|
|
1117
|
+
- `code`: string
|
|
1118
|
+
- `message`: string
|
|
1119
|
+
|
|
1120
|
+
Commander expects the callback to terminate the normal program flow, and will call `process.exit()` if the callback returns.
|
|
1121
|
+
The normal display of error messages or version or help is not affected by the override, which is called after the display.
|
|
1098
1122
|
|
|
1099
1123
|
```js
|
|
1100
1124
|
program.exitOverride();
|
|
@@ -1132,13 +1156,16 @@ program
|
|
|
1132
1156
|
There is more information available about:
|
|
1133
1157
|
|
|
1134
1158
|
- [deprecated](./docs/deprecated.md) features still supported for backwards compatibility
|
|
1159
|
+
- [Help in Depth](./docs/help-in-depth.md) configuring help output
|
|
1135
1160
|
- [options taking varying arguments](./docs/options-in-depth.md)
|
|
1136
1161
|
- [parsing life cycle and hooks](./docs/parsing-and-hooks.md)
|
|
1162
|
+
- [Release Policy](./docs/release-policy.md)
|
|
1137
1163
|
|
|
1138
1164
|
## Support
|
|
1139
1165
|
|
|
1140
|
-
The current version of Commander is fully supported on Long Term Support versions of Node.js, and requires at least
|
|
1141
|
-
|
|
1166
|
+
The current version of Commander is fully supported on Long Term Support versions of Node.js, and requires at least v20.
|
|
1167
|
+
|
|
1168
|
+
Older major versions of Commander receive security updates for 12 months. For more see: [Release Policy](./docs/release-policy.md).
|
|
1142
1169
|
|
|
1143
1170
|
The main forum for free and community support is the project [Issues](https://github.com/tj/commander.js/issues) on GitHub.
|
|
1144
1171
|
|
|
@@ -33,7 +33,7 @@ class Argument {
|
|
|
33
33
|
break;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
if (this._name.
|
|
36
|
+
if (this._name.endsWith('...')) {
|
|
37
37
|
this.variadic = true;
|
|
38
38
|
this._name = this._name.slice(0, -3);
|
|
39
39
|
}
|
|
@@ -53,12 +53,13 @@ class Argument {
|
|
|
53
53
|
* @package
|
|
54
54
|
*/
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
_collectValue(value, previous) {
|
|
57
57
|
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
58
58
|
return [value];
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
previous.push(value);
|
|
62
|
+
return previous;
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
/**
|
|
@@ -103,7 +104,7 @@ class Argument {
|
|
|
103
104
|
);
|
|
104
105
|
}
|
|
105
106
|
if (this.variadic) {
|
|
106
|
-
return this.
|
|
107
|
+
return this._collectValue(arg, previous);
|
|
107
108
|
}
|
|
108
109
|
return arg;
|
|
109
110
|
};
|