@unpackjs/core 1.5.4 → 1.6.0
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/openChrome.applescript +94 -0
- package/compiled/chokidar/index.d.ts +327 -0
- package/compiled/chokidar/index.js +1773 -0
- package/compiled/chokidar/license +21 -0
- package/compiled/chokidar/package.json +1 -0
- package/compiled/commander/index.d.ts +971 -0
- package/compiled/commander/index.js +2190 -0
- package/compiled/commander/license +22 -0
- package/compiled/commander/package.json +1 -0
- package/compiled/css-loader/api.js +85 -0
- package/compiled/css-loader/getUrl.js +26 -0
- package/compiled/css-loader/index.d.ts +1 -0
- package/compiled/css-loader/index.js +8004 -0
- package/compiled/css-loader/license +20 -0
- package/compiled/css-loader/noSourceMaps.js +5 -0
- package/compiled/css-loader/package.json +1 -0
- package/compiled/css-loader/sourceMaps.js +16 -0
- package/compiled/fast-glob/index.d.ts +237 -0
- package/compiled/fast-glob/index.js +5726 -0
- package/compiled/fast-glob/license +21 -0
- package/compiled/fast-glob/package.json +1 -0
- package/compiled/less-loader/index.d.ts +1 -0
- package/compiled/less-loader/index.js +340 -0
- package/compiled/less-loader/license +20 -0
- package/compiled/less-loader/package.json +1 -0
- package/compiled/line-diff/index.d.ts +1 -0
- package/compiled/line-diff/index.js +160 -0
- package/compiled/line-diff/license +21 -0
- package/compiled/line-diff/package.json +1 -0
- package/compiled/log-update/index.d.ts +1 -0
- package/compiled/log-update/index.js +1970 -0
- package/compiled/log-update/package.json +1 -0
- package/compiled/portfinder/index.d.ts +64 -0
- package/compiled/portfinder/index.js +3401 -0
- package/compiled/portfinder/license +22 -0
- package/compiled/portfinder/package.json +1 -0
- package/compiled/postcss-loader/index.d.ts +1 -0
- package/compiled/postcss-loader/index.js +94945 -0
- package/compiled/postcss-loader/license +20 -0
- package/compiled/postcss-loader/package.json +1 -0
- package/compiled/sass-loader/index.d.ts +961 -0
- package/compiled/sass-loader/index.js +5610 -0
- package/compiled/sass-loader/index1.js +65 -0
- package/compiled/sass-loader/license +20 -0
- package/compiled/sass-loader/package.json +1 -0
- package/compiled/sass-loader/sass.node.js +12 -0
- package/compiled/semver/index.d.ts +1 -0
- package/compiled/semver/index.js +1940 -0
- package/compiled/semver/license +15 -0
- package/compiled/semver/package.json +1 -0
- package/compiled/style-loader/index.d.ts +1 -0
- package/compiled/style-loader/index.js +370 -0
- package/compiled/style-loader/license +20 -0
- package/compiled/style-loader/package.json +1 -0
- package/compiled/style-loader/runtime/injectStylesIntoLinkTag.js +29 -0
- package/compiled/style-loader/runtime/injectStylesIntoStyleTag.js +84 -0
- package/compiled/style-loader/runtime/insertBySelector.js +34 -0
- package/compiled/style-loader/runtime/insertStyleElement.js +10 -0
- package/compiled/style-loader/runtime/isEqualLocals.js +28 -0
- package/compiled/style-loader/runtime/isOldIE.js +17 -0
- package/compiled/style-loader/runtime/setAttributesWithAttributes.js +13 -0
- package/compiled/style-loader/runtime/setAttributesWithAttributesAndNonce.js +9 -0
- package/compiled/style-loader/runtime/setAttributesWithoutAttributes.js +10 -0
- package/compiled/style-loader/runtime/singletonStyleDomAPI.js +86 -0
- package/compiled/style-loader/runtime/styleDomAPI.js +61 -0
- package/compiled/style-loader/runtime/styleTagTransform.js +14 -0
- package/compiled/webpack-bundle-analyzer/index.d.ts +1 -0
- package/compiled/webpack-bundle-analyzer/index.js +13276 -0
- package/compiled/webpack-bundle-analyzer/license +20 -0
- package/compiled/webpack-bundle-analyzer/package.json +1 -0
- package/compiled/webpack-bundle-analyzer/public/viewer.js +16 -0
- package/compiled/webpack-bundle-analyzer/public/viewer.js.LICENSE.txt +10 -0
- package/compiled/webpack-merge/index.d.ts +31 -0
- package/compiled/webpack-merge/index.js +1200 -0
- package/compiled/webpack-merge/license +20 -0
- package/compiled/webpack-merge/package.json +1 -0
- package/dist/bundleRequire.cjs +200 -0
- package/dist/bundleRequire.d.ts +5 -0
- package/dist/bundleRequire.d.ts.map +1 -0
- package/dist/bundleRequire.js +173 -0
- package/dist/bundler-config/chunkSplit.cjs +151 -0
- package/dist/bundler-config/chunkSplit.d.ts +6 -0
- package/dist/bundler-config/chunkSplit.d.ts.map +1 -0
- package/dist/bundler-config/chunkSplit.js +127 -0
- package/dist/bundler-config/css.cjs +168 -0
- package/dist/bundler-config/css.d.ts +6 -0
- package/dist/bundler-config/css.d.ts.map +1 -0
- package/dist/bundler-config/css.js +158 -0
- package/dist/bundler-config/experimentCss.cjs +167 -0
- package/dist/bundler-config/experimentCss.d.ts +6 -0
- package/dist/bundler-config/experimentCss.d.ts.map +1 -0
- package/dist/bundler-config/experimentCss.js +157 -0
- package/dist/bundler-config/helper.cjs +81 -0
- package/dist/bundler-config/helper.d.ts +8 -0
- package/dist/bundler-config/helper.d.ts.map +1 -0
- package/dist/bundler-config/helper.js +56 -0
- package/dist/bundler-config/index.cjs +206 -0
- package/dist/bundler-config/index.d.ts +3 -0
- package/dist/bundler-config/index.d.ts.map +1 -0
- package/dist/bundler-config/index.js +190 -0
- package/dist/colors.cjs +60 -0
- package/dist/colors.d.ts +6 -0
- package/dist/colors.d.ts.map +1 -0
- package/dist/colors.js +40 -0
- package/dist/{config/index.cjs → config.cjs} +26 -20
- package/dist/{config/index.d.ts → config.d.ts} +4 -3
- package/dist/config.d.ts.map +1 -0
- package/dist/{config/index.js → config.js} +19 -21
- package/dist/constants.cjs +86 -0
- package/dist/constants.d.ts +25 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +61 -0
- package/dist/createService.cjs +65 -0
- package/dist/createService.d.ts +8 -0
- package/dist/createService.d.ts.map +1 -0
- package/dist/createService.js +41 -0
- package/dist/index.cjs +27 -48
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -51
- package/dist/lightningcss/cache.cjs +36 -0
- package/dist/lightningcss/cache.d.ts +2 -0
- package/dist/lightningcss/cache.d.ts.map +1 -0
- package/dist/lightningcss/cache.js +22 -0
- package/dist/lightningcss/index.cjs +21 -0
- package/dist/lightningcss/index.d.ts +2 -0
- package/dist/lightningcss/index.d.ts.map +1 -0
- package/dist/lightningcss/index.js +10 -0
- package/dist/lightningcss/loader.cjs +56 -0
- package/dist/lightningcss/loader.d.ts +5 -0
- package/dist/lightningcss/loader.d.ts.map +1 -0
- package/dist/lightningcss/loader.js +36 -0
- package/dist/lightningcss/minimizer.cjs +114 -0
- package/dist/lightningcss/minimizer.d.ts +11 -0
- package/dist/lightningcss/minimizer.d.ts.map +1 -0
- package/dist/lightningcss/minimizer.js +90 -0
- package/dist/logger.cjs +103 -0
- package/dist/logger.d.ts +3 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +79 -0
- package/dist/openBrowser.cjs +85 -0
- package/dist/openBrowser.d.ts +2 -0
- package/dist/openBrowser.d.ts.map +1 -0
- package/dist/openBrowser.js +61 -0
- package/dist/plugin-progress/rspack.cjs +74 -0
- package/dist/plugin-progress/rspack.d.ts +9 -0
- package/dist/plugin-progress/rspack.d.ts.map +1 -0
- package/dist/plugin-progress/rspack.js +50 -0
- package/dist/plugin-progress/webpack.cjs +84 -0
- package/dist/plugin-progress/webpack.d.ts +9 -0
- package/dist/plugin-progress/webpack.d.ts.map +1 -0
- package/dist/plugin-progress/webpack.js +60 -0
- package/dist/plugin.cjs +33 -0
- package/dist/plugin.d.ts +3 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +19 -0
- package/dist/progressBar.cjs +70 -0
- package/dist/progressBar.d.ts +14 -0
- package/dist/progressBar.d.ts.map +1 -0
- package/dist/progressBar.js +46 -0
- package/dist/reporter.cjs +133 -0
- package/dist/reporter.d.ts +8 -0
- package/dist/reporter.d.ts.map +1 -0
- package/dist/reporter.js +109 -0
- package/dist/run/build.cjs +77 -0
- package/dist/run/build.d.ts +3 -0
- package/dist/run/build.d.ts.map +1 -0
- package/dist/run/build.js +53 -0
- package/dist/run/dev.cjs +107 -0
- package/dist/run/dev.d.ts +3 -0
- package/dist/run/dev.d.ts.map +1 -0
- package/dist/run/dev.js +83 -0
- package/dist/run/index.cjs +23 -0
- package/dist/run/index.d.ts +3 -0
- package/dist/run/index.d.ts.map +1 -0
- package/dist/run/index.js +11 -0
- package/dist/thread-loader/WorkerError.cjs +41 -0
- package/dist/thread-loader/WorkerError.js +31 -0
- package/dist/thread-loader/WorkerPool.cjs +407 -0
- package/dist/thread-loader/WorkerPool.js +387 -0
- package/dist/thread-loader/index.cjs +100 -0
- package/dist/thread-loader/index.js +85 -0
- package/dist/thread-loader/readBuffer.cjs +55 -0
- package/dist/thread-loader/readBuffer.js +45 -0
- package/dist/thread-loader/serializer.cjs +46 -0
- package/dist/thread-loader/serializer.js +31 -0
- package/dist/thread-loader/utils.cjs +84 -0
- package/dist/thread-loader/utils.js +60 -0
- package/dist/thread-loader/worker.cjs +377 -0
- package/dist/thread-loader/worker.js +382 -0
- package/dist/thread-loader/workerPools.cjs +57 -0
- package/dist/thread-loader/workerPools.js +33 -0
- package/dist/typed-css-modules/index.cjs +21 -0
- package/dist/typed-css-modules/index.d.ts +2 -0
- package/dist/typed-css-modules/index.d.ts.map +1 -0
- package/dist/typed-css-modules/index.js +10 -0
- package/dist/typed-css-modules/loader.cjs +195 -0
- package/dist/typed-css-modules/loader.d.ts +10 -0
- package/dist/typed-css-modules/loader.d.ts.map +1 -0
- package/dist/typed-css-modules/loader.js +170 -0
- package/dist/typed-css-modules/plugin.cjs +96 -0
- package/dist/typed-css-modules/plugin.d.ts +16 -0
- package/dist/typed-css-modules/plugin.d.ts.map +1 -0
- package/dist/typed-css-modules/plugin.js +72 -0
- package/dist/typed-css-modules/utils.cjs +45 -0
- package/dist/typed-css-modules/utils.d.ts +6 -0
- package/dist/typed-css-modules/utils.d.ts.map +1 -0
- package/dist/typed-css-modules/utils.js +31 -0
- package/dist/types/chunkSplit.cjs +15 -0
- package/dist/types/chunkSplit.d.ts +35 -0
- package/dist/types/chunkSplit.d.ts.map +1 -0
- package/dist/types/chunkSplit.js +9 -0
- package/dist/types/config.cjs +15 -0
- package/dist/types/config.d.ts +176 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +9 -0
- package/dist/types/index.cjs +29 -0
- package/dist/types/index.d.ts +16 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +14 -0
- package/dist/types/lightningcss.cjs +15 -0
- package/dist/types/lightningcss.d.ts +11 -0
- package/dist/types/lightningcss.d.ts.map +1 -0
- package/dist/types/lightningcss.js +9 -0
- package/dist/types/logger.cjs +35 -0
- package/dist/types/logger.d.ts +16 -0
- package/dist/types/logger.d.ts.map +1 -0
- package/dist/types/logger.js +21 -0
- package/dist/types/plugin.cjs +15 -0
- package/dist/types/plugin.d.ts +18 -0
- package/dist/types/plugin.d.ts.map +1 -0
- package/dist/types/plugin.js +9 -0
- package/dist/utils.cjs +293 -0
- package/dist/utils.d.ts +39 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +242 -0
- package/package.json +95 -6
- package/dist/config/index.d.ts.map +0 -1
|
@@ -0,0 +1,2190 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
var __webpack_modules__ = {
|
|
3
|
+
718: (module) => {
|
|
4
|
+
"use strict";
|
|
5
|
+
module.exports = require("node:child_process");
|
|
6
|
+
},
|
|
7
|
+
673: (module) => {
|
|
8
|
+
"use strict";
|
|
9
|
+
module.exports = require("node:events");
|
|
10
|
+
},
|
|
11
|
+
561: (module) => {
|
|
12
|
+
"use strict";
|
|
13
|
+
module.exports = require("node:fs");
|
|
14
|
+
},
|
|
15
|
+
411: (module) => {
|
|
16
|
+
"use strict";
|
|
17
|
+
module.exports = require("node:path");
|
|
18
|
+
},
|
|
19
|
+
742: (module) => {
|
|
20
|
+
"use strict";
|
|
21
|
+
module.exports = require("node:process");
|
|
22
|
+
},
|
|
23
|
+
654: (__unused_webpack_module, exports, __nccwpck_require__) => {
|
|
24
|
+
const { InvalidArgumentError } = __nccwpck_require__(829);
|
|
25
|
+
class Argument {
|
|
26
|
+
constructor(name, description) {
|
|
27
|
+
this.description = description || "";
|
|
28
|
+
this.variadic = false;
|
|
29
|
+
this.parseArg = undefined;
|
|
30
|
+
this.defaultValue = undefined;
|
|
31
|
+
this.defaultValueDescription = undefined;
|
|
32
|
+
this.argChoices = undefined;
|
|
33
|
+
switch (name[0]) {
|
|
34
|
+
case "<":
|
|
35
|
+
this.required = true;
|
|
36
|
+
this._name = name.slice(1, -1);
|
|
37
|
+
break;
|
|
38
|
+
case "[":
|
|
39
|
+
this.required = false;
|
|
40
|
+
this._name = name.slice(1, -1);
|
|
41
|
+
break;
|
|
42
|
+
default:
|
|
43
|
+
this.required = true;
|
|
44
|
+
this._name = name;
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
if (this._name.length > 3 && this._name.slice(-3) === "...") {
|
|
48
|
+
this.variadic = true;
|
|
49
|
+
this._name = this._name.slice(0, -3);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
name() {
|
|
53
|
+
return this._name;
|
|
54
|
+
}
|
|
55
|
+
_concatValue(value, previous) {
|
|
56
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
57
|
+
return [value];
|
|
58
|
+
}
|
|
59
|
+
return previous.concat(value);
|
|
60
|
+
}
|
|
61
|
+
default(value, description) {
|
|
62
|
+
this.defaultValue = value;
|
|
63
|
+
this.defaultValueDescription = description;
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
argParser(fn) {
|
|
67
|
+
this.parseArg = fn;
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
choices(values) {
|
|
71
|
+
this.argChoices = values.slice();
|
|
72
|
+
this.parseArg = (arg, previous) => {
|
|
73
|
+
if (!this.argChoices.includes(arg)) {
|
|
74
|
+
throw new InvalidArgumentError(
|
|
75
|
+
`Allowed choices are ${this.argChoices.join(", ")}.`,
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
if (this.variadic) {
|
|
79
|
+
return this._concatValue(arg, previous);
|
|
80
|
+
}
|
|
81
|
+
return arg;
|
|
82
|
+
};
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
argRequired() {
|
|
86
|
+
this.required = true;
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
argOptional() {
|
|
90
|
+
this.required = false;
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function humanReadableArgName(arg) {
|
|
95
|
+
const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
|
|
96
|
+
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
|
|
97
|
+
}
|
|
98
|
+
exports.Argument = Argument;
|
|
99
|
+
exports.humanReadableArgName = humanReadableArgName;
|
|
100
|
+
},
|
|
101
|
+
955: (__unused_webpack_module, exports, __nccwpck_require__) => {
|
|
102
|
+
const EventEmitter = __nccwpck_require__(673).EventEmitter;
|
|
103
|
+
const childProcess = __nccwpck_require__(718);
|
|
104
|
+
const path = __nccwpck_require__(411);
|
|
105
|
+
const fs = __nccwpck_require__(561);
|
|
106
|
+
const process = __nccwpck_require__(742);
|
|
107
|
+
const { Argument, humanReadableArgName } = __nccwpck_require__(654);
|
|
108
|
+
const { CommanderError } = __nccwpck_require__(829);
|
|
109
|
+
const { Help } = __nccwpck_require__(567);
|
|
110
|
+
const { Option, DualOptions } = __nccwpck_require__(230);
|
|
111
|
+
const { suggestSimilar } = __nccwpck_require__(241);
|
|
112
|
+
class Command extends EventEmitter {
|
|
113
|
+
constructor(name) {
|
|
114
|
+
super();
|
|
115
|
+
this.commands = [];
|
|
116
|
+
this.options = [];
|
|
117
|
+
this.parent = null;
|
|
118
|
+
this._allowUnknownOption = false;
|
|
119
|
+
this._allowExcessArguments = true;
|
|
120
|
+
this.registeredArguments = [];
|
|
121
|
+
this._args = this.registeredArguments;
|
|
122
|
+
this.args = [];
|
|
123
|
+
this.rawArgs = [];
|
|
124
|
+
this.processedArgs = [];
|
|
125
|
+
this._scriptPath = null;
|
|
126
|
+
this._name = name || "";
|
|
127
|
+
this._optionValues = {};
|
|
128
|
+
this._optionValueSources = {};
|
|
129
|
+
this._storeOptionsAsProperties = false;
|
|
130
|
+
this._actionHandler = null;
|
|
131
|
+
this._executableHandler = false;
|
|
132
|
+
this._executableFile = null;
|
|
133
|
+
this._executableDir = null;
|
|
134
|
+
this._defaultCommandName = null;
|
|
135
|
+
this._exitCallback = null;
|
|
136
|
+
this._aliases = [];
|
|
137
|
+
this._combineFlagAndOptionalValue = true;
|
|
138
|
+
this._description = "";
|
|
139
|
+
this._summary = "";
|
|
140
|
+
this._argsDescription = undefined;
|
|
141
|
+
this._enablePositionalOptions = false;
|
|
142
|
+
this._passThroughOptions = false;
|
|
143
|
+
this._lifeCycleHooks = {};
|
|
144
|
+
this._showHelpAfterError = false;
|
|
145
|
+
this._showSuggestionAfterError = true;
|
|
146
|
+
this._outputConfiguration = {
|
|
147
|
+
writeOut: (str) => process.stdout.write(str),
|
|
148
|
+
writeErr: (str) => process.stderr.write(str),
|
|
149
|
+
getOutHelpWidth: () =>
|
|
150
|
+
process.stdout.isTTY ? process.stdout.columns : undefined,
|
|
151
|
+
getErrHelpWidth: () =>
|
|
152
|
+
process.stderr.isTTY ? process.stderr.columns : undefined,
|
|
153
|
+
outputError: (str, write) => write(str),
|
|
154
|
+
};
|
|
155
|
+
this._hidden = false;
|
|
156
|
+
this._helpOption = undefined;
|
|
157
|
+
this._addImplicitHelpCommand = undefined;
|
|
158
|
+
this._helpCommand = undefined;
|
|
159
|
+
this._helpConfiguration = {};
|
|
160
|
+
}
|
|
161
|
+
copyInheritedSettings(sourceCommand) {
|
|
162
|
+
this._outputConfiguration = sourceCommand._outputConfiguration;
|
|
163
|
+
this._helpOption = sourceCommand._helpOption;
|
|
164
|
+
this._helpCommand = sourceCommand._helpCommand;
|
|
165
|
+
this._helpConfiguration = sourceCommand._helpConfiguration;
|
|
166
|
+
this._exitCallback = sourceCommand._exitCallback;
|
|
167
|
+
this._storeOptionsAsProperties =
|
|
168
|
+
sourceCommand._storeOptionsAsProperties;
|
|
169
|
+
this._combineFlagAndOptionalValue =
|
|
170
|
+
sourceCommand._combineFlagAndOptionalValue;
|
|
171
|
+
this._allowExcessArguments = sourceCommand._allowExcessArguments;
|
|
172
|
+
this._enablePositionalOptions =
|
|
173
|
+
sourceCommand._enablePositionalOptions;
|
|
174
|
+
this._showHelpAfterError = sourceCommand._showHelpAfterError;
|
|
175
|
+
this._showSuggestionAfterError =
|
|
176
|
+
sourceCommand._showSuggestionAfterError;
|
|
177
|
+
return this;
|
|
178
|
+
}
|
|
179
|
+
_getCommandAndAncestors() {
|
|
180
|
+
const result = [];
|
|
181
|
+
for (let command = this; command; command = command.parent) {
|
|
182
|
+
result.push(command);
|
|
183
|
+
}
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
|
|
187
|
+
let desc = actionOptsOrExecDesc;
|
|
188
|
+
let opts = execOpts;
|
|
189
|
+
if (typeof desc === "object" && desc !== null) {
|
|
190
|
+
opts = desc;
|
|
191
|
+
desc = null;
|
|
192
|
+
}
|
|
193
|
+
opts = opts || {};
|
|
194
|
+
const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
195
|
+
const cmd = this.createCommand(name);
|
|
196
|
+
if (desc) {
|
|
197
|
+
cmd.description(desc);
|
|
198
|
+
cmd._executableHandler = true;
|
|
199
|
+
}
|
|
200
|
+
if (opts.isDefault) this._defaultCommandName = cmd._name;
|
|
201
|
+
cmd._hidden = !!(opts.noHelp || opts.hidden);
|
|
202
|
+
cmd._executableFile = opts.executableFile || null;
|
|
203
|
+
if (args) cmd.arguments(args);
|
|
204
|
+
this._registerCommand(cmd);
|
|
205
|
+
cmd.parent = this;
|
|
206
|
+
cmd.copyInheritedSettings(this);
|
|
207
|
+
if (desc) return this;
|
|
208
|
+
return cmd;
|
|
209
|
+
}
|
|
210
|
+
createCommand(name) {
|
|
211
|
+
return new Command(name);
|
|
212
|
+
}
|
|
213
|
+
createHelp() {
|
|
214
|
+
return Object.assign(new Help(), this.configureHelp());
|
|
215
|
+
}
|
|
216
|
+
configureHelp(configuration) {
|
|
217
|
+
if (configuration === undefined) return this._helpConfiguration;
|
|
218
|
+
this._helpConfiguration = configuration;
|
|
219
|
+
return this;
|
|
220
|
+
}
|
|
221
|
+
configureOutput(configuration) {
|
|
222
|
+
if (configuration === undefined) return this._outputConfiguration;
|
|
223
|
+
Object.assign(this._outputConfiguration, configuration);
|
|
224
|
+
return this;
|
|
225
|
+
}
|
|
226
|
+
showHelpAfterError(displayHelp = true) {
|
|
227
|
+
if (typeof displayHelp !== "string") displayHelp = !!displayHelp;
|
|
228
|
+
this._showHelpAfterError = displayHelp;
|
|
229
|
+
return this;
|
|
230
|
+
}
|
|
231
|
+
showSuggestionAfterError(displaySuggestion = true) {
|
|
232
|
+
this._showSuggestionAfterError = !!displaySuggestion;
|
|
233
|
+
return this;
|
|
234
|
+
}
|
|
235
|
+
addCommand(cmd, opts) {
|
|
236
|
+
if (!cmd._name) {
|
|
237
|
+
throw new Error(
|
|
238
|
+
`Command passed to .addCommand() must have a name\n- specify the name in Command constructor or using .name()`,
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
opts = opts || {};
|
|
242
|
+
if (opts.isDefault) this._defaultCommandName = cmd._name;
|
|
243
|
+
if (opts.noHelp || opts.hidden) cmd._hidden = true;
|
|
244
|
+
this._registerCommand(cmd);
|
|
245
|
+
cmd.parent = this;
|
|
246
|
+
cmd._checkForBrokenPassThrough();
|
|
247
|
+
return this;
|
|
248
|
+
}
|
|
249
|
+
createArgument(name, description) {
|
|
250
|
+
return new Argument(name, description);
|
|
251
|
+
}
|
|
252
|
+
argument(name, description, fn, defaultValue) {
|
|
253
|
+
const argument = this.createArgument(name, description);
|
|
254
|
+
if (typeof fn === "function") {
|
|
255
|
+
argument.default(defaultValue).argParser(fn);
|
|
256
|
+
} else {
|
|
257
|
+
argument.default(fn);
|
|
258
|
+
}
|
|
259
|
+
this.addArgument(argument);
|
|
260
|
+
return this;
|
|
261
|
+
}
|
|
262
|
+
arguments(names) {
|
|
263
|
+
names
|
|
264
|
+
.trim()
|
|
265
|
+
.split(/ +/)
|
|
266
|
+
.forEach((detail) => {
|
|
267
|
+
this.argument(detail);
|
|
268
|
+
});
|
|
269
|
+
return this;
|
|
270
|
+
}
|
|
271
|
+
addArgument(argument) {
|
|
272
|
+
const previousArgument = this.registeredArguments.slice(-1)[0];
|
|
273
|
+
if (previousArgument && previousArgument.variadic) {
|
|
274
|
+
throw new Error(
|
|
275
|
+
`only the last argument can be variadic '${previousArgument.name()}'`,
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
if (
|
|
279
|
+
argument.required &&
|
|
280
|
+
argument.defaultValue !== undefined &&
|
|
281
|
+
argument.parseArg === undefined
|
|
282
|
+
) {
|
|
283
|
+
throw new Error(
|
|
284
|
+
`a default value for a required argument is never used: '${argument.name()}'`,
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
this.registeredArguments.push(argument);
|
|
288
|
+
return this;
|
|
289
|
+
}
|
|
290
|
+
helpCommand(enableOrNameAndArgs, description) {
|
|
291
|
+
if (typeof enableOrNameAndArgs === "boolean") {
|
|
292
|
+
this._addImplicitHelpCommand = enableOrNameAndArgs;
|
|
293
|
+
return this;
|
|
294
|
+
}
|
|
295
|
+
enableOrNameAndArgs = enableOrNameAndArgs ?? "help [command]";
|
|
296
|
+
const [, helpName, helpArgs] =
|
|
297
|
+
enableOrNameAndArgs.match(/([^ ]+) *(.*)/);
|
|
298
|
+
const helpDescription = description ?? "display help for command";
|
|
299
|
+
const helpCommand = this.createCommand(helpName);
|
|
300
|
+
helpCommand.helpOption(false);
|
|
301
|
+
if (helpArgs) helpCommand.arguments(helpArgs);
|
|
302
|
+
if (helpDescription) helpCommand.description(helpDescription);
|
|
303
|
+
this._addImplicitHelpCommand = true;
|
|
304
|
+
this._helpCommand = helpCommand;
|
|
305
|
+
return this;
|
|
306
|
+
}
|
|
307
|
+
addHelpCommand(helpCommand, deprecatedDescription) {
|
|
308
|
+
if (typeof helpCommand !== "object") {
|
|
309
|
+
this.helpCommand(helpCommand, deprecatedDescription);
|
|
310
|
+
return this;
|
|
311
|
+
}
|
|
312
|
+
this._addImplicitHelpCommand = true;
|
|
313
|
+
this._helpCommand = helpCommand;
|
|
314
|
+
return this;
|
|
315
|
+
}
|
|
316
|
+
_getHelpCommand() {
|
|
317
|
+
const hasImplicitHelpCommand =
|
|
318
|
+
this._addImplicitHelpCommand ??
|
|
319
|
+
(this.commands.length &&
|
|
320
|
+
!this._actionHandler &&
|
|
321
|
+
!this._findCommand("help"));
|
|
322
|
+
if (hasImplicitHelpCommand) {
|
|
323
|
+
if (this._helpCommand === undefined) {
|
|
324
|
+
this.helpCommand(undefined, undefined);
|
|
325
|
+
}
|
|
326
|
+
return this._helpCommand;
|
|
327
|
+
}
|
|
328
|
+
return null;
|
|
329
|
+
}
|
|
330
|
+
hook(event, listener) {
|
|
331
|
+
const allowedValues = ["preSubcommand", "preAction", "postAction"];
|
|
332
|
+
if (!allowedValues.includes(event)) {
|
|
333
|
+
throw new Error(
|
|
334
|
+
`Unexpected value for event passed to hook : '${event}'.\nExpecting one of '${allowedValues.join("', '")}'`,
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
if (this._lifeCycleHooks[event]) {
|
|
338
|
+
this._lifeCycleHooks[event].push(listener);
|
|
339
|
+
} else {
|
|
340
|
+
this._lifeCycleHooks[event] = [listener];
|
|
341
|
+
}
|
|
342
|
+
return this;
|
|
343
|
+
}
|
|
344
|
+
exitOverride(fn) {
|
|
345
|
+
if (fn) {
|
|
346
|
+
this._exitCallback = fn;
|
|
347
|
+
} else {
|
|
348
|
+
this._exitCallback = (err) => {
|
|
349
|
+
if (err.code !== "commander.executeSubCommandAsync") {
|
|
350
|
+
throw err;
|
|
351
|
+
} else {
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
return this;
|
|
356
|
+
}
|
|
357
|
+
_exit(exitCode, code, message) {
|
|
358
|
+
if (this._exitCallback) {
|
|
359
|
+
this._exitCallback(new CommanderError(exitCode, code, message));
|
|
360
|
+
}
|
|
361
|
+
process.exit(exitCode);
|
|
362
|
+
}
|
|
363
|
+
action(fn) {
|
|
364
|
+
const listener = (args) => {
|
|
365
|
+
const expectedArgsCount = this.registeredArguments.length;
|
|
366
|
+
const actionArgs = args.slice(0, expectedArgsCount);
|
|
367
|
+
if (this._storeOptionsAsProperties) {
|
|
368
|
+
actionArgs[expectedArgsCount] = this;
|
|
369
|
+
} else {
|
|
370
|
+
actionArgs[expectedArgsCount] = this.opts();
|
|
371
|
+
}
|
|
372
|
+
actionArgs.push(this);
|
|
373
|
+
return fn.apply(this, actionArgs);
|
|
374
|
+
};
|
|
375
|
+
this._actionHandler = listener;
|
|
376
|
+
return this;
|
|
377
|
+
}
|
|
378
|
+
createOption(flags, description) {
|
|
379
|
+
return new Option(flags, description);
|
|
380
|
+
}
|
|
381
|
+
_callParseArg(target, value, previous, invalidArgumentMessage) {
|
|
382
|
+
try {
|
|
383
|
+
return target.parseArg(value, previous);
|
|
384
|
+
} catch (err) {
|
|
385
|
+
if (err.code === "commander.invalidArgument") {
|
|
386
|
+
const message = `${invalidArgumentMessage} ${err.message}`;
|
|
387
|
+
this.error(message, { exitCode: err.exitCode, code: err.code });
|
|
388
|
+
}
|
|
389
|
+
throw err;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
_registerOption(option) {
|
|
393
|
+
const matchingOption =
|
|
394
|
+
(option.short && this._findOption(option.short)) ||
|
|
395
|
+
(option.long && this._findOption(option.long));
|
|
396
|
+
if (matchingOption) {
|
|
397
|
+
const matchingFlag =
|
|
398
|
+
option.long && this._findOption(option.long)
|
|
399
|
+
? option.long
|
|
400
|
+
: option.short;
|
|
401
|
+
throw new Error(
|
|
402
|
+
`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'\n- already used by option '${matchingOption.flags}'`,
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
this.options.push(option);
|
|
406
|
+
}
|
|
407
|
+
_registerCommand(command) {
|
|
408
|
+
const knownBy = (cmd) => [cmd.name()].concat(cmd.aliases());
|
|
409
|
+
const alreadyUsed = knownBy(command).find((name) =>
|
|
410
|
+
this._findCommand(name),
|
|
411
|
+
);
|
|
412
|
+
if (alreadyUsed) {
|
|
413
|
+
const existingCmd = knownBy(this._findCommand(alreadyUsed)).join(
|
|
414
|
+
"|",
|
|
415
|
+
);
|
|
416
|
+
const newCmd = knownBy(command).join("|");
|
|
417
|
+
throw new Error(
|
|
418
|
+
`cannot add command '${newCmd}' as already have command '${existingCmd}'`,
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
this.commands.push(command);
|
|
422
|
+
}
|
|
423
|
+
addOption(option) {
|
|
424
|
+
this._registerOption(option);
|
|
425
|
+
const oname = option.name();
|
|
426
|
+
const name = option.attributeName();
|
|
427
|
+
if (option.negate) {
|
|
428
|
+
const positiveLongFlag = option.long.replace(/^--no-/, "--");
|
|
429
|
+
if (!this._findOption(positiveLongFlag)) {
|
|
430
|
+
this.setOptionValueWithSource(
|
|
431
|
+
name,
|
|
432
|
+
option.defaultValue === undefined ? true : option.defaultValue,
|
|
433
|
+
"default",
|
|
434
|
+
);
|
|
435
|
+
}
|
|
436
|
+
} else if (option.defaultValue !== undefined) {
|
|
437
|
+
this.setOptionValueWithSource(name, option.defaultValue, "default");
|
|
438
|
+
}
|
|
439
|
+
const handleOptionValue = (val, invalidValueMessage, valueSource) => {
|
|
440
|
+
if (val == null && option.presetArg !== undefined) {
|
|
441
|
+
val = option.presetArg;
|
|
442
|
+
}
|
|
443
|
+
const oldValue = this.getOptionValue(name);
|
|
444
|
+
if (val !== null && option.parseArg) {
|
|
445
|
+
val = this._callParseArg(
|
|
446
|
+
option,
|
|
447
|
+
val,
|
|
448
|
+
oldValue,
|
|
449
|
+
invalidValueMessage,
|
|
450
|
+
);
|
|
451
|
+
} else if (val !== null && option.variadic) {
|
|
452
|
+
val = option._concatValue(val, oldValue);
|
|
453
|
+
}
|
|
454
|
+
if (val == null) {
|
|
455
|
+
if (option.negate) {
|
|
456
|
+
val = false;
|
|
457
|
+
} else if (option.isBoolean() || option.optional) {
|
|
458
|
+
val = true;
|
|
459
|
+
} else {
|
|
460
|
+
val = "";
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
this.setOptionValueWithSource(name, val, valueSource);
|
|
464
|
+
};
|
|
465
|
+
this.on("option:" + oname, (val) => {
|
|
466
|
+
const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
|
|
467
|
+
handleOptionValue(val, invalidValueMessage, "cli");
|
|
468
|
+
});
|
|
469
|
+
if (option.envVar) {
|
|
470
|
+
this.on("optionEnv:" + oname, (val) => {
|
|
471
|
+
const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
|
|
472
|
+
handleOptionValue(val, invalidValueMessage, "env");
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
return this;
|
|
476
|
+
}
|
|
477
|
+
_optionEx(config, flags, description, fn, defaultValue) {
|
|
478
|
+
if (typeof flags === "object" && flags instanceof Option) {
|
|
479
|
+
throw new Error(
|
|
480
|
+
"To add an Option object use addOption() instead of option() or requiredOption()",
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
const option = this.createOption(flags, description);
|
|
484
|
+
option.makeOptionMandatory(!!config.mandatory);
|
|
485
|
+
if (typeof fn === "function") {
|
|
486
|
+
option.default(defaultValue).argParser(fn);
|
|
487
|
+
} else if (fn instanceof RegExp) {
|
|
488
|
+
const regex = fn;
|
|
489
|
+
fn = (val, def) => {
|
|
490
|
+
const m = regex.exec(val);
|
|
491
|
+
return m ? m[0] : def;
|
|
492
|
+
};
|
|
493
|
+
option.default(defaultValue).argParser(fn);
|
|
494
|
+
} else {
|
|
495
|
+
option.default(fn);
|
|
496
|
+
}
|
|
497
|
+
return this.addOption(option);
|
|
498
|
+
}
|
|
499
|
+
option(flags, description, parseArg, defaultValue) {
|
|
500
|
+
return this._optionEx({}, flags, description, parseArg, defaultValue);
|
|
501
|
+
}
|
|
502
|
+
requiredOption(flags, description, parseArg, defaultValue) {
|
|
503
|
+
return this._optionEx(
|
|
504
|
+
{ mandatory: true },
|
|
505
|
+
flags,
|
|
506
|
+
description,
|
|
507
|
+
parseArg,
|
|
508
|
+
defaultValue,
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
combineFlagAndOptionalValue(combine = true) {
|
|
512
|
+
this._combineFlagAndOptionalValue = !!combine;
|
|
513
|
+
return this;
|
|
514
|
+
}
|
|
515
|
+
allowUnknownOption(allowUnknown = true) {
|
|
516
|
+
this._allowUnknownOption = !!allowUnknown;
|
|
517
|
+
return this;
|
|
518
|
+
}
|
|
519
|
+
allowExcessArguments(allowExcess = true) {
|
|
520
|
+
this._allowExcessArguments = !!allowExcess;
|
|
521
|
+
return this;
|
|
522
|
+
}
|
|
523
|
+
enablePositionalOptions(positional = true) {
|
|
524
|
+
this._enablePositionalOptions = !!positional;
|
|
525
|
+
return this;
|
|
526
|
+
}
|
|
527
|
+
passThroughOptions(passThrough = true) {
|
|
528
|
+
this._passThroughOptions = !!passThrough;
|
|
529
|
+
this._checkForBrokenPassThrough();
|
|
530
|
+
return this;
|
|
531
|
+
}
|
|
532
|
+
_checkForBrokenPassThrough() {
|
|
533
|
+
if (
|
|
534
|
+
this.parent &&
|
|
535
|
+
this._passThroughOptions &&
|
|
536
|
+
!this.parent._enablePositionalOptions
|
|
537
|
+
) {
|
|
538
|
+
throw new Error(
|
|
539
|
+
`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`,
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
storeOptionsAsProperties(storeAsProperties = true) {
|
|
544
|
+
if (this.options.length) {
|
|
545
|
+
throw new Error(
|
|
546
|
+
"call .storeOptionsAsProperties() before adding options",
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
if (Object.keys(this._optionValues).length) {
|
|
550
|
+
throw new Error(
|
|
551
|
+
"call .storeOptionsAsProperties() before setting option values",
|
|
552
|
+
);
|
|
553
|
+
}
|
|
554
|
+
this._storeOptionsAsProperties = !!storeAsProperties;
|
|
555
|
+
return this;
|
|
556
|
+
}
|
|
557
|
+
getOptionValue(key) {
|
|
558
|
+
if (this._storeOptionsAsProperties) {
|
|
559
|
+
return this[key];
|
|
560
|
+
}
|
|
561
|
+
return this._optionValues[key];
|
|
562
|
+
}
|
|
563
|
+
setOptionValue(key, value) {
|
|
564
|
+
return this.setOptionValueWithSource(key, value, undefined);
|
|
565
|
+
}
|
|
566
|
+
setOptionValueWithSource(key, value, source) {
|
|
567
|
+
if (this._storeOptionsAsProperties) {
|
|
568
|
+
this[key] = value;
|
|
569
|
+
} else {
|
|
570
|
+
this._optionValues[key] = value;
|
|
571
|
+
}
|
|
572
|
+
this._optionValueSources[key] = source;
|
|
573
|
+
return this;
|
|
574
|
+
}
|
|
575
|
+
getOptionValueSource(key) {
|
|
576
|
+
return this._optionValueSources[key];
|
|
577
|
+
}
|
|
578
|
+
getOptionValueSourceWithGlobals(key) {
|
|
579
|
+
let source;
|
|
580
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
581
|
+
if (cmd.getOptionValueSource(key) !== undefined) {
|
|
582
|
+
source = cmd.getOptionValueSource(key);
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
return source;
|
|
586
|
+
}
|
|
587
|
+
_prepareUserArgs(argv, parseOptions) {
|
|
588
|
+
if (argv !== undefined && !Array.isArray(argv)) {
|
|
589
|
+
throw new Error(
|
|
590
|
+
"first parameter to parse must be array or undefined",
|
|
591
|
+
);
|
|
592
|
+
}
|
|
593
|
+
parseOptions = parseOptions || {};
|
|
594
|
+
if (argv === undefined && parseOptions.from === undefined) {
|
|
595
|
+
if (process.versions?.electron) {
|
|
596
|
+
parseOptions.from = "electron";
|
|
597
|
+
}
|
|
598
|
+
const execArgv = process.execArgv ?? [];
|
|
599
|
+
if (
|
|
600
|
+
execArgv.includes("-e") ||
|
|
601
|
+
execArgv.includes("--eval") ||
|
|
602
|
+
execArgv.includes("-p") ||
|
|
603
|
+
execArgv.includes("--print")
|
|
604
|
+
) {
|
|
605
|
+
parseOptions.from = "eval";
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
if (argv === undefined) {
|
|
609
|
+
argv = process.argv;
|
|
610
|
+
}
|
|
611
|
+
this.rawArgs = argv.slice();
|
|
612
|
+
let userArgs;
|
|
613
|
+
switch (parseOptions.from) {
|
|
614
|
+
case undefined:
|
|
615
|
+
case "node":
|
|
616
|
+
this._scriptPath = argv[1];
|
|
617
|
+
userArgs = argv.slice(2);
|
|
618
|
+
break;
|
|
619
|
+
case "electron":
|
|
620
|
+
if (process.defaultApp) {
|
|
621
|
+
this._scriptPath = argv[1];
|
|
622
|
+
userArgs = argv.slice(2);
|
|
623
|
+
} else {
|
|
624
|
+
userArgs = argv.slice(1);
|
|
625
|
+
}
|
|
626
|
+
break;
|
|
627
|
+
case "user":
|
|
628
|
+
userArgs = argv.slice(0);
|
|
629
|
+
break;
|
|
630
|
+
case "eval":
|
|
631
|
+
userArgs = argv.slice(1);
|
|
632
|
+
break;
|
|
633
|
+
default:
|
|
634
|
+
throw new Error(
|
|
635
|
+
`unexpected parse option { from: '${parseOptions.from}' }`,
|
|
636
|
+
);
|
|
637
|
+
}
|
|
638
|
+
if (!this._name && this._scriptPath)
|
|
639
|
+
this.nameFromFilename(this._scriptPath);
|
|
640
|
+
this._name = this._name || "program";
|
|
641
|
+
return userArgs;
|
|
642
|
+
}
|
|
643
|
+
parse(argv, parseOptions) {
|
|
644
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
645
|
+
this._parseCommand([], userArgs);
|
|
646
|
+
return this;
|
|
647
|
+
}
|
|
648
|
+
async parseAsync(argv, parseOptions) {
|
|
649
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
650
|
+
await this._parseCommand([], userArgs);
|
|
651
|
+
return this;
|
|
652
|
+
}
|
|
653
|
+
_executeSubCommand(subcommand, args) {
|
|
654
|
+
args = args.slice();
|
|
655
|
+
let launchWithNode = false;
|
|
656
|
+
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
657
|
+
function findFile(baseDir, baseName) {
|
|
658
|
+
const localBin = path.resolve(baseDir, baseName);
|
|
659
|
+
if (fs.existsSync(localBin)) return localBin;
|
|
660
|
+
if (sourceExt.includes(path.extname(baseName))) return undefined;
|
|
661
|
+
const foundExt = sourceExt.find((ext) =>
|
|
662
|
+
fs.existsSync(`${localBin}${ext}`),
|
|
663
|
+
);
|
|
664
|
+
if (foundExt) return `${localBin}${foundExt}`;
|
|
665
|
+
return undefined;
|
|
666
|
+
}
|
|
667
|
+
this._checkForMissingMandatoryOptions();
|
|
668
|
+
this._checkForConflictingOptions();
|
|
669
|
+
let executableFile =
|
|
670
|
+
subcommand._executableFile || `${this._name}-${subcommand._name}`;
|
|
671
|
+
let executableDir = this._executableDir || "";
|
|
672
|
+
if (this._scriptPath) {
|
|
673
|
+
let resolvedScriptPath;
|
|
674
|
+
try {
|
|
675
|
+
resolvedScriptPath = fs.realpathSync(this._scriptPath);
|
|
676
|
+
} catch (err) {
|
|
677
|
+
resolvedScriptPath = this._scriptPath;
|
|
678
|
+
}
|
|
679
|
+
executableDir = path.resolve(
|
|
680
|
+
path.dirname(resolvedScriptPath),
|
|
681
|
+
executableDir,
|
|
682
|
+
);
|
|
683
|
+
}
|
|
684
|
+
if (executableDir) {
|
|
685
|
+
let localFile = findFile(executableDir, executableFile);
|
|
686
|
+
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
687
|
+
const legacyName = path.basename(
|
|
688
|
+
this._scriptPath,
|
|
689
|
+
path.extname(this._scriptPath),
|
|
690
|
+
);
|
|
691
|
+
if (legacyName !== this._name) {
|
|
692
|
+
localFile = findFile(
|
|
693
|
+
executableDir,
|
|
694
|
+
`${legacyName}-${subcommand._name}`,
|
|
695
|
+
);
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
executableFile = localFile || executableFile;
|
|
699
|
+
}
|
|
700
|
+
launchWithNode = sourceExt.includes(path.extname(executableFile));
|
|
701
|
+
let proc;
|
|
702
|
+
if (process.platform !== "win32") {
|
|
703
|
+
if (launchWithNode) {
|
|
704
|
+
args.unshift(executableFile);
|
|
705
|
+
args = incrementNodeInspectorPort(process.execArgv).concat(args);
|
|
706
|
+
proc = childProcess.spawn(process.argv[0], args, {
|
|
707
|
+
stdio: "inherit",
|
|
708
|
+
});
|
|
709
|
+
} else {
|
|
710
|
+
proc = childProcess.spawn(executableFile, args, {
|
|
711
|
+
stdio: "inherit",
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
} else {
|
|
715
|
+
args.unshift(executableFile);
|
|
716
|
+
args = incrementNodeInspectorPort(process.execArgv).concat(args);
|
|
717
|
+
proc = childProcess.spawn(process.execPath, args, {
|
|
718
|
+
stdio: "inherit",
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
if (!proc.killed) {
|
|
722
|
+
const signals = [
|
|
723
|
+
"SIGUSR1",
|
|
724
|
+
"SIGUSR2",
|
|
725
|
+
"SIGTERM",
|
|
726
|
+
"SIGINT",
|
|
727
|
+
"SIGHUP",
|
|
728
|
+
];
|
|
729
|
+
signals.forEach((signal) => {
|
|
730
|
+
process.on(signal, () => {
|
|
731
|
+
if (proc.killed === false && proc.exitCode === null) {
|
|
732
|
+
proc.kill(signal);
|
|
733
|
+
}
|
|
734
|
+
});
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
const exitCallback = this._exitCallback;
|
|
738
|
+
proc.on("close", (code) => {
|
|
739
|
+
code = code ?? 1;
|
|
740
|
+
if (!exitCallback) {
|
|
741
|
+
process.exit(code);
|
|
742
|
+
} else {
|
|
743
|
+
exitCallback(
|
|
744
|
+
new CommanderError(
|
|
745
|
+
code,
|
|
746
|
+
"commander.executeSubCommandAsync",
|
|
747
|
+
"(close)",
|
|
748
|
+
),
|
|
749
|
+
);
|
|
750
|
+
}
|
|
751
|
+
});
|
|
752
|
+
proc.on("error", (err) => {
|
|
753
|
+
if (err.code === "ENOENT") {
|
|
754
|
+
const executableDirMessage = executableDir
|
|
755
|
+
? `searched for local subcommand relative to directory '${executableDir}'`
|
|
756
|
+
: "no directory for search for local subcommand, use .executableDir() to supply a custom directory";
|
|
757
|
+
const executableMissing = `'${executableFile}' does not exist\n - if '${subcommand._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead\n - if the default executable name is not suitable, use the executableFile option to supply a custom name or path\n - ${executableDirMessage}`;
|
|
758
|
+
throw new Error(executableMissing);
|
|
759
|
+
} else if (err.code === "EACCES") {
|
|
760
|
+
throw new Error(`'${executableFile}' not executable`);
|
|
761
|
+
}
|
|
762
|
+
if (!exitCallback) {
|
|
763
|
+
process.exit(1);
|
|
764
|
+
} else {
|
|
765
|
+
const wrappedError = new CommanderError(
|
|
766
|
+
1,
|
|
767
|
+
"commander.executeSubCommandAsync",
|
|
768
|
+
"(error)",
|
|
769
|
+
);
|
|
770
|
+
wrappedError.nestedError = err;
|
|
771
|
+
exitCallback(wrappedError);
|
|
772
|
+
}
|
|
773
|
+
});
|
|
774
|
+
this.runningCommand = proc;
|
|
775
|
+
}
|
|
776
|
+
_dispatchSubcommand(commandName, operands, unknown) {
|
|
777
|
+
const subCommand = this._findCommand(commandName);
|
|
778
|
+
if (!subCommand) this.help({ error: true });
|
|
779
|
+
let promiseChain;
|
|
780
|
+
promiseChain = this._chainOrCallSubCommandHook(
|
|
781
|
+
promiseChain,
|
|
782
|
+
subCommand,
|
|
783
|
+
"preSubcommand",
|
|
784
|
+
);
|
|
785
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
786
|
+
if (subCommand._executableHandler) {
|
|
787
|
+
this._executeSubCommand(subCommand, operands.concat(unknown));
|
|
788
|
+
} else {
|
|
789
|
+
return subCommand._parseCommand(operands, unknown);
|
|
790
|
+
}
|
|
791
|
+
});
|
|
792
|
+
return promiseChain;
|
|
793
|
+
}
|
|
794
|
+
_dispatchHelpCommand(subcommandName) {
|
|
795
|
+
if (!subcommandName) {
|
|
796
|
+
this.help();
|
|
797
|
+
}
|
|
798
|
+
const subCommand = this._findCommand(subcommandName);
|
|
799
|
+
if (subCommand && !subCommand._executableHandler) {
|
|
800
|
+
subCommand.help();
|
|
801
|
+
}
|
|
802
|
+
return this._dispatchSubcommand(
|
|
803
|
+
subcommandName,
|
|
804
|
+
[],
|
|
805
|
+
[
|
|
806
|
+
this._getHelpOption()?.long ??
|
|
807
|
+
this._getHelpOption()?.short ??
|
|
808
|
+
"--help",
|
|
809
|
+
],
|
|
810
|
+
);
|
|
811
|
+
}
|
|
812
|
+
_checkNumberOfArguments() {
|
|
813
|
+
this.registeredArguments.forEach((arg, i) => {
|
|
814
|
+
if (arg.required && this.args[i] == null) {
|
|
815
|
+
this.missingArgument(arg.name());
|
|
816
|
+
}
|
|
817
|
+
});
|
|
818
|
+
if (
|
|
819
|
+
this.registeredArguments.length > 0 &&
|
|
820
|
+
this.registeredArguments[this.registeredArguments.length - 1]
|
|
821
|
+
.variadic
|
|
822
|
+
) {
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
825
|
+
if (this.args.length > this.registeredArguments.length) {
|
|
826
|
+
this._excessArguments(this.args);
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
_processArguments() {
|
|
830
|
+
const myParseArg = (argument, value, previous) => {
|
|
831
|
+
let parsedValue = value;
|
|
832
|
+
if (value !== null && argument.parseArg) {
|
|
833
|
+
const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
|
|
834
|
+
parsedValue = this._callParseArg(
|
|
835
|
+
argument,
|
|
836
|
+
value,
|
|
837
|
+
previous,
|
|
838
|
+
invalidValueMessage,
|
|
839
|
+
);
|
|
840
|
+
}
|
|
841
|
+
return parsedValue;
|
|
842
|
+
};
|
|
843
|
+
this._checkNumberOfArguments();
|
|
844
|
+
const processedArgs = [];
|
|
845
|
+
this.registeredArguments.forEach((declaredArg, index) => {
|
|
846
|
+
let value = declaredArg.defaultValue;
|
|
847
|
+
if (declaredArg.variadic) {
|
|
848
|
+
if (index < this.args.length) {
|
|
849
|
+
value = this.args.slice(index);
|
|
850
|
+
if (declaredArg.parseArg) {
|
|
851
|
+
value = value.reduce(
|
|
852
|
+
(processed, v) => myParseArg(declaredArg, v, processed),
|
|
853
|
+
declaredArg.defaultValue,
|
|
854
|
+
);
|
|
855
|
+
}
|
|
856
|
+
} else if (value === undefined) {
|
|
857
|
+
value = [];
|
|
858
|
+
}
|
|
859
|
+
} else if (index < this.args.length) {
|
|
860
|
+
value = this.args[index];
|
|
861
|
+
if (declaredArg.parseArg) {
|
|
862
|
+
value = myParseArg(
|
|
863
|
+
declaredArg,
|
|
864
|
+
value,
|
|
865
|
+
declaredArg.defaultValue,
|
|
866
|
+
);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
processedArgs[index] = value;
|
|
870
|
+
});
|
|
871
|
+
this.processedArgs = processedArgs;
|
|
872
|
+
}
|
|
873
|
+
_chainOrCall(promise, fn) {
|
|
874
|
+
if (promise && promise.then && typeof promise.then === "function") {
|
|
875
|
+
return promise.then(() => fn());
|
|
876
|
+
}
|
|
877
|
+
return fn();
|
|
878
|
+
}
|
|
879
|
+
_chainOrCallHooks(promise, event) {
|
|
880
|
+
let result = promise;
|
|
881
|
+
const hooks = [];
|
|
882
|
+
this._getCommandAndAncestors()
|
|
883
|
+
.reverse()
|
|
884
|
+
.filter((cmd) => cmd._lifeCycleHooks[event] !== undefined)
|
|
885
|
+
.forEach((hookedCommand) => {
|
|
886
|
+
hookedCommand._lifeCycleHooks[event].forEach((callback) => {
|
|
887
|
+
hooks.push({ hookedCommand, callback });
|
|
888
|
+
});
|
|
889
|
+
});
|
|
890
|
+
if (event === "postAction") {
|
|
891
|
+
hooks.reverse();
|
|
892
|
+
}
|
|
893
|
+
hooks.forEach((hookDetail) => {
|
|
894
|
+
result = this._chainOrCall(result, () =>
|
|
895
|
+
hookDetail.callback(hookDetail.hookedCommand, this),
|
|
896
|
+
);
|
|
897
|
+
});
|
|
898
|
+
return result;
|
|
899
|
+
}
|
|
900
|
+
_chainOrCallSubCommandHook(promise, subCommand, event) {
|
|
901
|
+
let result = promise;
|
|
902
|
+
if (this._lifeCycleHooks[event] !== undefined) {
|
|
903
|
+
this._lifeCycleHooks[event].forEach((hook) => {
|
|
904
|
+
result = this._chainOrCall(result, () => hook(this, subCommand));
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
return result;
|
|
908
|
+
}
|
|
909
|
+
_parseCommand(operands, unknown) {
|
|
910
|
+
const parsed = this.parseOptions(unknown);
|
|
911
|
+
this._parseOptionsEnv();
|
|
912
|
+
this._parseOptionsImplied();
|
|
913
|
+
operands = operands.concat(parsed.operands);
|
|
914
|
+
unknown = parsed.unknown;
|
|
915
|
+
this.args = operands.concat(unknown);
|
|
916
|
+
if (operands && this._findCommand(operands[0])) {
|
|
917
|
+
return this._dispatchSubcommand(
|
|
918
|
+
operands[0],
|
|
919
|
+
operands.slice(1),
|
|
920
|
+
unknown,
|
|
921
|
+
);
|
|
922
|
+
}
|
|
923
|
+
if (
|
|
924
|
+
this._getHelpCommand() &&
|
|
925
|
+
operands[0] === this._getHelpCommand().name()
|
|
926
|
+
) {
|
|
927
|
+
return this._dispatchHelpCommand(operands[1]);
|
|
928
|
+
}
|
|
929
|
+
if (this._defaultCommandName) {
|
|
930
|
+
this._outputHelpIfRequested(unknown);
|
|
931
|
+
return this._dispatchSubcommand(
|
|
932
|
+
this._defaultCommandName,
|
|
933
|
+
operands,
|
|
934
|
+
unknown,
|
|
935
|
+
);
|
|
936
|
+
}
|
|
937
|
+
if (
|
|
938
|
+
this.commands.length &&
|
|
939
|
+
this.args.length === 0 &&
|
|
940
|
+
!this._actionHandler &&
|
|
941
|
+
!this._defaultCommandName
|
|
942
|
+
) {
|
|
943
|
+
this.help({ error: true });
|
|
944
|
+
}
|
|
945
|
+
this._outputHelpIfRequested(parsed.unknown);
|
|
946
|
+
this._checkForMissingMandatoryOptions();
|
|
947
|
+
this._checkForConflictingOptions();
|
|
948
|
+
const checkForUnknownOptions = () => {
|
|
949
|
+
if (parsed.unknown.length > 0) {
|
|
950
|
+
this.unknownOption(parsed.unknown[0]);
|
|
951
|
+
}
|
|
952
|
+
};
|
|
953
|
+
const commandEvent = `command:${this.name()}`;
|
|
954
|
+
if (this._actionHandler) {
|
|
955
|
+
checkForUnknownOptions();
|
|
956
|
+
this._processArguments();
|
|
957
|
+
let promiseChain;
|
|
958
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
|
|
959
|
+
promiseChain = this._chainOrCall(promiseChain, () =>
|
|
960
|
+
this._actionHandler(this.processedArgs),
|
|
961
|
+
);
|
|
962
|
+
if (this.parent) {
|
|
963
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
964
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
|
|
968
|
+
return promiseChain;
|
|
969
|
+
}
|
|
970
|
+
if (this.parent && this.parent.listenerCount(commandEvent)) {
|
|
971
|
+
checkForUnknownOptions();
|
|
972
|
+
this._processArguments();
|
|
973
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
974
|
+
} else if (operands.length) {
|
|
975
|
+
if (this._findCommand("*")) {
|
|
976
|
+
return this._dispatchSubcommand("*", operands, unknown);
|
|
977
|
+
}
|
|
978
|
+
if (this.listenerCount("command:*")) {
|
|
979
|
+
this.emit("command:*", operands, unknown);
|
|
980
|
+
} else if (this.commands.length) {
|
|
981
|
+
this.unknownCommand();
|
|
982
|
+
} else {
|
|
983
|
+
checkForUnknownOptions();
|
|
984
|
+
this._processArguments();
|
|
985
|
+
}
|
|
986
|
+
} else if (this.commands.length) {
|
|
987
|
+
checkForUnknownOptions();
|
|
988
|
+
this.help({ error: true });
|
|
989
|
+
} else {
|
|
990
|
+
checkForUnknownOptions();
|
|
991
|
+
this._processArguments();
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
_findCommand(name) {
|
|
995
|
+
if (!name) return undefined;
|
|
996
|
+
return this.commands.find(
|
|
997
|
+
(cmd) => cmd._name === name || cmd._aliases.includes(name),
|
|
998
|
+
);
|
|
999
|
+
}
|
|
1000
|
+
_findOption(arg) {
|
|
1001
|
+
return this.options.find((option) => option.is(arg));
|
|
1002
|
+
}
|
|
1003
|
+
_checkForMissingMandatoryOptions() {
|
|
1004
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1005
|
+
cmd.options.forEach((anOption) => {
|
|
1006
|
+
if (
|
|
1007
|
+
anOption.mandatory &&
|
|
1008
|
+
cmd.getOptionValue(anOption.attributeName()) === undefined
|
|
1009
|
+
) {
|
|
1010
|
+
cmd.missingMandatoryOptionValue(anOption);
|
|
1011
|
+
}
|
|
1012
|
+
});
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
_checkForConflictingLocalOptions() {
|
|
1016
|
+
const definedNonDefaultOptions = this.options.filter((option) => {
|
|
1017
|
+
const optionKey = option.attributeName();
|
|
1018
|
+
if (this.getOptionValue(optionKey) === undefined) {
|
|
1019
|
+
return false;
|
|
1020
|
+
}
|
|
1021
|
+
return this.getOptionValueSource(optionKey) !== "default";
|
|
1022
|
+
});
|
|
1023
|
+
const optionsWithConflicting = definedNonDefaultOptions.filter(
|
|
1024
|
+
(option) => option.conflictsWith.length > 0,
|
|
1025
|
+
);
|
|
1026
|
+
optionsWithConflicting.forEach((option) => {
|
|
1027
|
+
const conflictingAndDefined = definedNonDefaultOptions.find(
|
|
1028
|
+
(defined) =>
|
|
1029
|
+
option.conflictsWith.includes(defined.attributeName()),
|
|
1030
|
+
);
|
|
1031
|
+
if (conflictingAndDefined) {
|
|
1032
|
+
this._conflictingOption(option, conflictingAndDefined);
|
|
1033
|
+
}
|
|
1034
|
+
});
|
|
1035
|
+
}
|
|
1036
|
+
_checkForConflictingOptions() {
|
|
1037
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1038
|
+
cmd._checkForConflictingLocalOptions();
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
parseOptions(argv) {
|
|
1042
|
+
const operands = [];
|
|
1043
|
+
const unknown = [];
|
|
1044
|
+
let dest = operands;
|
|
1045
|
+
const args = argv.slice();
|
|
1046
|
+
function maybeOption(arg) {
|
|
1047
|
+
return arg.length > 1 && arg[0] === "-";
|
|
1048
|
+
}
|
|
1049
|
+
let activeVariadicOption = null;
|
|
1050
|
+
while (args.length) {
|
|
1051
|
+
const arg = args.shift();
|
|
1052
|
+
if (arg === "--") {
|
|
1053
|
+
if (dest === unknown) dest.push(arg);
|
|
1054
|
+
dest.push(...args);
|
|
1055
|
+
break;
|
|
1056
|
+
}
|
|
1057
|
+
if (activeVariadicOption && !maybeOption(arg)) {
|
|
1058
|
+
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
1059
|
+
continue;
|
|
1060
|
+
}
|
|
1061
|
+
activeVariadicOption = null;
|
|
1062
|
+
if (maybeOption(arg)) {
|
|
1063
|
+
const option = this._findOption(arg);
|
|
1064
|
+
if (option) {
|
|
1065
|
+
if (option.required) {
|
|
1066
|
+
const value = args.shift();
|
|
1067
|
+
if (value === undefined) this.optionMissingArgument(option);
|
|
1068
|
+
this.emit(`option:${option.name()}`, value);
|
|
1069
|
+
} else if (option.optional) {
|
|
1070
|
+
let value = null;
|
|
1071
|
+
if (args.length > 0 && !maybeOption(args[0])) {
|
|
1072
|
+
value = args.shift();
|
|
1073
|
+
}
|
|
1074
|
+
this.emit(`option:${option.name()}`, value);
|
|
1075
|
+
} else {
|
|
1076
|
+
this.emit(`option:${option.name()}`);
|
|
1077
|
+
}
|
|
1078
|
+
activeVariadicOption = option.variadic ? option : null;
|
|
1079
|
+
continue;
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
|
|
1083
|
+
const option = this._findOption(`-${arg[1]}`);
|
|
1084
|
+
if (option) {
|
|
1085
|
+
if (
|
|
1086
|
+
option.required ||
|
|
1087
|
+
(option.optional && this._combineFlagAndOptionalValue)
|
|
1088
|
+
) {
|
|
1089
|
+
this.emit(`option:${option.name()}`, arg.slice(2));
|
|
1090
|
+
} else {
|
|
1091
|
+
this.emit(`option:${option.name()}`);
|
|
1092
|
+
args.unshift(`-${arg.slice(2)}`);
|
|
1093
|
+
}
|
|
1094
|
+
continue;
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
if (/^--[^=]+=/.test(arg)) {
|
|
1098
|
+
const index = arg.indexOf("=");
|
|
1099
|
+
const option = this._findOption(arg.slice(0, index));
|
|
1100
|
+
if (option && (option.required || option.optional)) {
|
|
1101
|
+
this.emit(`option:${option.name()}`, arg.slice(index + 1));
|
|
1102
|
+
continue;
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
if (maybeOption(arg)) {
|
|
1106
|
+
dest = unknown;
|
|
1107
|
+
}
|
|
1108
|
+
if (
|
|
1109
|
+
(this._enablePositionalOptions || this._passThroughOptions) &&
|
|
1110
|
+
operands.length === 0 &&
|
|
1111
|
+
unknown.length === 0
|
|
1112
|
+
) {
|
|
1113
|
+
if (this._findCommand(arg)) {
|
|
1114
|
+
operands.push(arg);
|
|
1115
|
+
if (args.length > 0) unknown.push(...args);
|
|
1116
|
+
break;
|
|
1117
|
+
} else if (
|
|
1118
|
+
this._getHelpCommand() &&
|
|
1119
|
+
arg === this._getHelpCommand().name()
|
|
1120
|
+
) {
|
|
1121
|
+
operands.push(arg);
|
|
1122
|
+
if (args.length > 0) operands.push(...args);
|
|
1123
|
+
break;
|
|
1124
|
+
} else if (this._defaultCommandName) {
|
|
1125
|
+
unknown.push(arg);
|
|
1126
|
+
if (args.length > 0) unknown.push(...args);
|
|
1127
|
+
break;
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
if (this._passThroughOptions) {
|
|
1131
|
+
dest.push(arg);
|
|
1132
|
+
if (args.length > 0) dest.push(...args);
|
|
1133
|
+
break;
|
|
1134
|
+
}
|
|
1135
|
+
dest.push(arg);
|
|
1136
|
+
}
|
|
1137
|
+
return { operands, unknown };
|
|
1138
|
+
}
|
|
1139
|
+
opts() {
|
|
1140
|
+
if (this._storeOptionsAsProperties) {
|
|
1141
|
+
const result = {};
|
|
1142
|
+
const len = this.options.length;
|
|
1143
|
+
for (let i = 0; i < len; i++) {
|
|
1144
|
+
const key = this.options[i].attributeName();
|
|
1145
|
+
result[key] =
|
|
1146
|
+
key === this._versionOptionName ? this._version : this[key];
|
|
1147
|
+
}
|
|
1148
|
+
return result;
|
|
1149
|
+
}
|
|
1150
|
+
return this._optionValues;
|
|
1151
|
+
}
|
|
1152
|
+
optsWithGlobals() {
|
|
1153
|
+
return this._getCommandAndAncestors().reduce(
|
|
1154
|
+
(combinedOptions, cmd) =>
|
|
1155
|
+
Object.assign(combinedOptions, cmd.opts()),
|
|
1156
|
+
{},
|
|
1157
|
+
);
|
|
1158
|
+
}
|
|
1159
|
+
error(message, errorOptions) {
|
|
1160
|
+
this._outputConfiguration.outputError(
|
|
1161
|
+
`${message}\n`,
|
|
1162
|
+
this._outputConfiguration.writeErr,
|
|
1163
|
+
);
|
|
1164
|
+
if (typeof this._showHelpAfterError === "string") {
|
|
1165
|
+
this._outputConfiguration.writeErr(`${this._showHelpAfterError}\n`);
|
|
1166
|
+
} else if (this._showHelpAfterError) {
|
|
1167
|
+
this._outputConfiguration.writeErr("\n");
|
|
1168
|
+
this.outputHelp({ error: true });
|
|
1169
|
+
}
|
|
1170
|
+
const config = errorOptions || {};
|
|
1171
|
+
const exitCode = config.exitCode || 1;
|
|
1172
|
+
const code = config.code || "commander.error";
|
|
1173
|
+
this._exit(exitCode, code, message);
|
|
1174
|
+
}
|
|
1175
|
+
_parseOptionsEnv() {
|
|
1176
|
+
this.options.forEach((option) => {
|
|
1177
|
+
if (option.envVar && option.envVar in process.env) {
|
|
1178
|
+
const optionKey = option.attributeName();
|
|
1179
|
+
if (
|
|
1180
|
+
this.getOptionValue(optionKey) === undefined ||
|
|
1181
|
+
["default", "config", "env"].includes(
|
|
1182
|
+
this.getOptionValueSource(optionKey),
|
|
1183
|
+
)
|
|
1184
|
+
) {
|
|
1185
|
+
if (option.required || option.optional) {
|
|
1186
|
+
this.emit(
|
|
1187
|
+
`optionEnv:${option.name()}`,
|
|
1188
|
+
process.env[option.envVar],
|
|
1189
|
+
);
|
|
1190
|
+
} else {
|
|
1191
|
+
this.emit(`optionEnv:${option.name()}`);
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
_parseOptionsImplied() {
|
|
1198
|
+
const dualHelper = new DualOptions(this.options);
|
|
1199
|
+
const hasCustomOptionValue = (optionKey) =>
|
|
1200
|
+
this.getOptionValue(optionKey) !== undefined &&
|
|
1201
|
+
!["default", "implied"].includes(
|
|
1202
|
+
this.getOptionValueSource(optionKey),
|
|
1203
|
+
);
|
|
1204
|
+
this.options
|
|
1205
|
+
.filter(
|
|
1206
|
+
(option) =>
|
|
1207
|
+
option.implied !== undefined &&
|
|
1208
|
+
hasCustomOptionValue(option.attributeName()) &&
|
|
1209
|
+
dualHelper.valueFromOption(
|
|
1210
|
+
this.getOptionValue(option.attributeName()),
|
|
1211
|
+
option,
|
|
1212
|
+
),
|
|
1213
|
+
)
|
|
1214
|
+
.forEach((option) => {
|
|
1215
|
+
Object.keys(option.implied)
|
|
1216
|
+
.filter((impliedKey) => !hasCustomOptionValue(impliedKey))
|
|
1217
|
+
.forEach((impliedKey) => {
|
|
1218
|
+
this.setOptionValueWithSource(
|
|
1219
|
+
impliedKey,
|
|
1220
|
+
option.implied[impliedKey],
|
|
1221
|
+
"implied",
|
|
1222
|
+
);
|
|
1223
|
+
});
|
|
1224
|
+
});
|
|
1225
|
+
}
|
|
1226
|
+
missingArgument(name) {
|
|
1227
|
+
const message = `error: missing required argument '${name}'`;
|
|
1228
|
+
this.error(message, { code: "commander.missingArgument" });
|
|
1229
|
+
}
|
|
1230
|
+
optionMissingArgument(option) {
|
|
1231
|
+
const message = `error: option '${option.flags}' argument missing`;
|
|
1232
|
+
this.error(message, { code: "commander.optionMissingArgument" });
|
|
1233
|
+
}
|
|
1234
|
+
missingMandatoryOptionValue(option) {
|
|
1235
|
+
const message = `error: required option '${option.flags}' not specified`;
|
|
1236
|
+
this.error(message, {
|
|
1237
|
+
code: "commander.missingMandatoryOptionValue",
|
|
1238
|
+
});
|
|
1239
|
+
}
|
|
1240
|
+
_conflictingOption(option, conflictingOption) {
|
|
1241
|
+
const findBestOptionFromValue = (option) => {
|
|
1242
|
+
const optionKey = option.attributeName();
|
|
1243
|
+
const optionValue = this.getOptionValue(optionKey);
|
|
1244
|
+
const negativeOption = this.options.find(
|
|
1245
|
+
(target) => target.negate && optionKey === target.attributeName(),
|
|
1246
|
+
);
|
|
1247
|
+
const positiveOption = this.options.find(
|
|
1248
|
+
(target) =>
|
|
1249
|
+
!target.negate && optionKey === target.attributeName(),
|
|
1250
|
+
);
|
|
1251
|
+
if (
|
|
1252
|
+
negativeOption &&
|
|
1253
|
+
((negativeOption.presetArg === undefined &&
|
|
1254
|
+
optionValue === false) ||
|
|
1255
|
+
(negativeOption.presetArg !== undefined &&
|
|
1256
|
+
optionValue === negativeOption.presetArg))
|
|
1257
|
+
) {
|
|
1258
|
+
return negativeOption;
|
|
1259
|
+
}
|
|
1260
|
+
return positiveOption || option;
|
|
1261
|
+
};
|
|
1262
|
+
const getErrorMessage = (option) => {
|
|
1263
|
+
const bestOption = findBestOptionFromValue(option);
|
|
1264
|
+
const optionKey = bestOption.attributeName();
|
|
1265
|
+
const source = this.getOptionValueSource(optionKey);
|
|
1266
|
+
if (source === "env") {
|
|
1267
|
+
return `environment variable '${bestOption.envVar}'`;
|
|
1268
|
+
}
|
|
1269
|
+
return `option '${bestOption.flags}'`;
|
|
1270
|
+
};
|
|
1271
|
+
const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
|
|
1272
|
+
this.error(message, { code: "commander.conflictingOption" });
|
|
1273
|
+
}
|
|
1274
|
+
unknownOption(flag) {
|
|
1275
|
+
if (this._allowUnknownOption) return;
|
|
1276
|
+
let suggestion = "";
|
|
1277
|
+
if (flag.startsWith("--") && this._showSuggestionAfterError) {
|
|
1278
|
+
let candidateFlags = [];
|
|
1279
|
+
let command = this;
|
|
1280
|
+
do {
|
|
1281
|
+
const moreFlags = command
|
|
1282
|
+
.createHelp()
|
|
1283
|
+
.visibleOptions(command)
|
|
1284
|
+
.filter((option) => option.long)
|
|
1285
|
+
.map((option) => option.long);
|
|
1286
|
+
candidateFlags = candidateFlags.concat(moreFlags);
|
|
1287
|
+
command = command.parent;
|
|
1288
|
+
} while (command && !command._enablePositionalOptions);
|
|
1289
|
+
suggestion = suggestSimilar(flag, candidateFlags);
|
|
1290
|
+
}
|
|
1291
|
+
const message = `error: unknown option '${flag}'${suggestion}`;
|
|
1292
|
+
this.error(message, { code: "commander.unknownOption" });
|
|
1293
|
+
}
|
|
1294
|
+
_excessArguments(receivedArgs) {
|
|
1295
|
+
if (this._allowExcessArguments) return;
|
|
1296
|
+
const expected = this.registeredArguments.length;
|
|
1297
|
+
const s = expected === 1 ? "" : "s";
|
|
1298
|
+
const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
|
|
1299
|
+
const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
|
|
1300
|
+
this.error(message, { code: "commander.excessArguments" });
|
|
1301
|
+
}
|
|
1302
|
+
unknownCommand() {
|
|
1303
|
+
const unknownName = this.args[0];
|
|
1304
|
+
let suggestion = "";
|
|
1305
|
+
if (this._showSuggestionAfterError) {
|
|
1306
|
+
const candidateNames = [];
|
|
1307
|
+
this.createHelp()
|
|
1308
|
+
.visibleCommands(this)
|
|
1309
|
+
.forEach((command) => {
|
|
1310
|
+
candidateNames.push(command.name());
|
|
1311
|
+
if (command.alias()) candidateNames.push(command.alias());
|
|
1312
|
+
});
|
|
1313
|
+
suggestion = suggestSimilar(unknownName, candidateNames);
|
|
1314
|
+
}
|
|
1315
|
+
const message = `error: unknown command '${unknownName}'${suggestion}`;
|
|
1316
|
+
this.error(message, { code: "commander.unknownCommand" });
|
|
1317
|
+
}
|
|
1318
|
+
version(str, flags, description) {
|
|
1319
|
+
if (str === undefined) return this._version;
|
|
1320
|
+
this._version = str;
|
|
1321
|
+
flags = flags || "-V, --version";
|
|
1322
|
+
description = description || "output the version number";
|
|
1323
|
+
const versionOption = this.createOption(flags, description);
|
|
1324
|
+
this._versionOptionName = versionOption.attributeName();
|
|
1325
|
+
this._registerOption(versionOption);
|
|
1326
|
+
this.on("option:" + versionOption.name(), () => {
|
|
1327
|
+
this._outputConfiguration.writeOut(`${str}\n`);
|
|
1328
|
+
this._exit(0, "commander.version", str);
|
|
1329
|
+
});
|
|
1330
|
+
return this;
|
|
1331
|
+
}
|
|
1332
|
+
description(str, argsDescription) {
|
|
1333
|
+
if (str === undefined && argsDescription === undefined)
|
|
1334
|
+
return this._description;
|
|
1335
|
+
this._description = str;
|
|
1336
|
+
if (argsDescription) {
|
|
1337
|
+
this._argsDescription = argsDescription;
|
|
1338
|
+
}
|
|
1339
|
+
return this;
|
|
1340
|
+
}
|
|
1341
|
+
summary(str) {
|
|
1342
|
+
if (str === undefined) return this._summary;
|
|
1343
|
+
this._summary = str;
|
|
1344
|
+
return this;
|
|
1345
|
+
}
|
|
1346
|
+
alias(alias) {
|
|
1347
|
+
if (alias === undefined) return this._aliases[0];
|
|
1348
|
+
let command = this;
|
|
1349
|
+
if (
|
|
1350
|
+
this.commands.length !== 0 &&
|
|
1351
|
+
this.commands[this.commands.length - 1]._executableHandler
|
|
1352
|
+
) {
|
|
1353
|
+
command = this.commands[this.commands.length - 1];
|
|
1354
|
+
}
|
|
1355
|
+
if (alias === command._name)
|
|
1356
|
+
throw new Error("Command alias can't be the same as its name");
|
|
1357
|
+
const matchingCommand = this.parent?._findCommand(alias);
|
|
1358
|
+
if (matchingCommand) {
|
|
1359
|
+
const existingCmd = [matchingCommand.name()]
|
|
1360
|
+
.concat(matchingCommand.aliases())
|
|
1361
|
+
.join("|");
|
|
1362
|
+
throw new Error(
|
|
1363
|
+
`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`,
|
|
1364
|
+
);
|
|
1365
|
+
}
|
|
1366
|
+
command._aliases.push(alias);
|
|
1367
|
+
return this;
|
|
1368
|
+
}
|
|
1369
|
+
aliases(aliases) {
|
|
1370
|
+
if (aliases === undefined) return this._aliases;
|
|
1371
|
+
aliases.forEach((alias) => this.alias(alias));
|
|
1372
|
+
return this;
|
|
1373
|
+
}
|
|
1374
|
+
usage(str) {
|
|
1375
|
+
if (str === undefined) {
|
|
1376
|
+
if (this._usage) return this._usage;
|
|
1377
|
+
const args = this.registeredArguments.map((arg) =>
|
|
1378
|
+
humanReadableArgName(arg),
|
|
1379
|
+
);
|
|
1380
|
+
return []
|
|
1381
|
+
.concat(
|
|
1382
|
+
this.options.length || this._helpOption !== null
|
|
1383
|
+
? "[options]"
|
|
1384
|
+
: [],
|
|
1385
|
+
this.commands.length ? "[command]" : [],
|
|
1386
|
+
this.registeredArguments.length ? args : [],
|
|
1387
|
+
)
|
|
1388
|
+
.join(" ");
|
|
1389
|
+
}
|
|
1390
|
+
this._usage = str;
|
|
1391
|
+
return this;
|
|
1392
|
+
}
|
|
1393
|
+
name(str) {
|
|
1394
|
+
if (str === undefined) return this._name;
|
|
1395
|
+
this._name = str;
|
|
1396
|
+
return this;
|
|
1397
|
+
}
|
|
1398
|
+
nameFromFilename(filename) {
|
|
1399
|
+
this._name = path.basename(filename, path.extname(filename));
|
|
1400
|
+
return this;
|
|
1401
|
+
}
|
|
1402
|
+
executableDir(path) {
|
|
1403
|
+
if (path === undefined) return this._executableDir;
|
|
1404
|
+
this._executableDir = path;
|
|
1405
|
+
return this;
|
|
1406
|
+
}
|
|
1407
|
+
helpInformation(contextOptions) {
|
|
1408
|
+
const helper = this.createHelp();
|
|
1409
|
+
if (helper.helpWidth === undefined) {
|
|
1410
|
+
helper.helpWidth =
|
|
1411
|
+
contextOptions && contextOptions.error
|
|
1412
|
+
? this._outputConfiguration.getErrHelpWidth()
|
|
1413
|
+
: this._outputConfiguration.getOutHelpWidth();
|
|
1414
|
+
}
|
|
1415
|
+
return helper.formatHelp(this, helper);
|
|
1416
|
+
}
|
|
1417
|
+
_getHelpContext(contextOptions) {
|
|
1418
|
+
contextOptions = contextOptions || {};
|
|
1419
|
+
const context = { error: !!contextOptions.error };
|
|
1420
|
+
let write;
|
|
1421
|
+
if (context.error) {
|
|
1422
|
+
write = (arg) => this._outputConfiguration.writeErr(arg);
|
|
1423
|
+
} else {
|
|
1424
|
+
write = (arg) => this._outputConfiguration.writeOut(arg);
|
|
1425
|
+
}
|
|
1426
|
+
context.write = contextOptions.write || write;
|
|
1427
|
+
context.command = this;
|
|
1428
|
+
return context;
|
|
1429
|
+
}
|
|
1430
|
+
outputHelp(contextOptions) {
|
|
1431
|
+
let deprecatedCallback;
|
|
1432
|
+
if (typeof contextOptions === "function") {
|
|
1433
|
+
deprecatedCallback = contextOptions;
|
|
1434
|
+
contextOptions = undefined;
|
|
1435
|
+
}
|
|
1436
|
+
const context = this._getHelpContext(contextOptions);
|
|
1437
|
+
this._getCommandAndAncestors()
|
|
1438
|
+
.reverse()
|
|
1439
|
+
.forEach((command) => command.emit("beforeAllHelp", context));
|
|
1440
|
+
this.emit("beforeHelp", context);
|
|
1441
|
+
let helpInformation = this.helpInformation(context);
|
|
1442
|
+
if (deprecatedCallback) {
|
|
1443
|
+
helpInformation = deprecatedCallback(helpInformation);
|
|
1444
|
+
if (
|
|
1445
|
+
typeof helpInformation !== "string" &&
|
|
1446
|
+
!Buffer.isBuffer(helpInformation)
|
|
1447
|
+
) {
|
|
1448
|
+
throw new Error(
|
|
1449
|
+
"outputHelp callback must return a string or a Buffer",
|
|
1450
|
+
);
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
context.write(helpInformation);
|
|
1454
|
+
if (this._getHelpOption()?.long) {
|
|
1455
|
+
this.emit(this._getHelpOption().long);
|
|
1456
|
+
}
|
|
1457
|
+
this.emit("afterHelp", context);
|
|
1458
|
+
this._getCommandAndAncestors().forEach((command) =>
|
|
1459
|
+
command.emit("afterAllHelp", context),
|
|
1460
|
+
);
|
|
1461
|
+
}
|
|
1462
|
+
helpOption(flags, description) {
|
|
1463
|
+
if (typeof flags === "boolean") {
|
|
1464
|
+
if (flags) {
|
|
1465
|
+
this._helpOption = this._helpOption ?? undefined;
|
|
1466
|
+
} else {
|
|
1467
|
+
this._helpOption = null;
|
|
1468
|
+
}
|
|
1469
|
+
return this;
|
|
1470
|
+
}
|
|
1471
|
+
flags = flags ?? "-h, --help";
|
|
1472
|
+
description = description ?? "display help for command";
|
|
1473
|
+
this._helpOption = this.createOption(flags, description);
|
|
1474
|
+
return this;
|
|
1475
|
+
}
|
|
1476
|
+
_getHelpOption() {
|
|
1477
|
+
if (this._helpOption === undefined) {
|
|
1478
|
+
this.helpOption(undefined, undefined);
|
|
1479
|
+
}
|
|
1480
|
+
return this._helpOption;
|
|
1481
|
+
}
|
|
1482
|
+
addHelpOption(option) {
|
|
1483
|
+
this._helpOption = option;
|
|
1484
|
+
return this;
|
|
1485
|
+
}
|
|
1486
|
+
help(contextOptions) {
|
|
1487
|
+
this.outputHelp(contextOptions);
|
|
1488
|
+
let exitCode = process.exitCode || 0;
|
|
1489
|
+
if (
|
|
1490
|
+
exitCode === 0 &&
|
|
1491
|
+
contextOptions &&
|
|
1492
|
+
typeof contextOptions !== "function" &&
|
|
1493
|
+
contextOptions.error
|
|
1494
|
+
) {
|
|
1495
|
+
exitCode = 1;
|
|
1496
|
+
}
|
|
1497
|
+
this._exit(exitCode, "commander.help", "(outputHelp)");
|
|
1498
|
+
}
|
|
1499
|
+
addHelpText(position, text) {
|
|
1500
|
+
const allowedValues = ["beforeAll", "before", "after", "afterAll"];
|
|
1501
|
+
if (!allowedValues.includes(position)) {
|
|
1502
|
+
throw new Error(
|
|
1503
|
+
`Unexpected value for position to addHelpText.\nExpecting one of '${allowedValues.join("', '")}'`,
|
|
1504
|
+
);
|
|
1505
|
+
}
|
|
1506
|
+
const helpEvent = `${position}Help`;
|
|
1507
|
+
this.on(helpEvent, (context) => {
|
|
1508
|
+
let helpStr;
|
|
1509
|
+
if (typeof text === "function") {
|
|
1510
|
+
helpStr = text({
|
|
1511
|
+
error: context.error,
|
|
1512
|
+
command: context.command,
|
|
1513
|
+
});
|
|
1514
|
+
} else {
|
|
1515
|
+
helpStr = text;
|
|
1516
|
+
}
|
|
1517
|
+
if (helpStr) {
|
|
1518
|
+
context.write(`${helpStr}\n`);
|
|
1519
|
+
}
|
|
1520
|
+
});
|
|
1521
|
+
return this;
|
|
1522
|
+
}
|
|
1523
|
+
_outputHelpIfRequested(args) {
|
|
1524
|
+
const helpOption = this._getHelpOption();
|
|
1525
|
+
const helpRequested =
|
|
1526
|
+
helpOption && args.find((arg) => helpOption.is(arg));
|
|
1527
|
+
if (helpRequested) {
|
|
1528
|
+
this.outputHelp();
|
|
1529
|
+
this._exit(0, "commander.helpDisplayed", "(outputHelp)");
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
function incrementNodeInspectorPort(args) {
|
|
1534
|
+
return args.map((arg) => {
|
|
1535
|
+
if (!arg.startsWith("--inspect")) {
|
|
1536
|
+
return arg;
|
|
1537
|
+
}
|
|
1538
|
+
let debugOption;
|
|
1539
|
+
let debugHost = "127.0.0.1";
|
|
1540
|
+
let debugPort = "9229";
|
|
1541
|
+
let match;
|
|
1542
|
+
if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
|
|
1543
|
+
debugOption = match[1];
|
|
1544
|
+
} else if (
|
|
1545
|
+
(match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null
|
|
1546
|
+
) {
|
|
1547
|
+
debugOption = match[1];
|
|
1548
|
+
if (/^\d+$/.test(match[3])) {
|
|
1549
|
+
debugPort = match[3];
|
|
1550
|
+
} else {
|
|
1551
|
+
debugHost = match[3];
|
|
1552
|
+
}
|
|
1553
|
+
} else if (
|
|
1554
|
+
(match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !==
|
|
1555
|
+
null
|
|
1556
|
+
) {
|
|
1557
|
+
debugOption = match[1];
|
|
1558
|
+
debugHost = match[3];
|
|
1559
|
+
debugPort = match[4];
|
|
1560
|
+
}
|
|
1561
|
+
if (debugOption && debugPort !== "0") {
|
|
1562
|
+
return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
|
|
1563
|
+
}
|
|
1564
|
+
return arg;
|
|
1565
|
+
});
|
|
1566
|
+
}
|
|
1567
|
+
exports.Command = Command;
|
|
1568
|
+
},
|
|
1569
|
+
829: (__unused_webpack_module, exports) => {
|
|
1570
|
+
class CommanderError extends Error {
|
|
1571
|
+
constructor(exitCode, code, message) {
|
|
1572
|
+
super(message);
|
|
1573
|
+
Error.captureStackTrace(this, this.constructor);
|
|
1574
|
+
this.name = this.constructor.name;
|
|
1575
|
+
this.code = code;
|
|
1576
|
+
this.exitCode = exitCode;
|
|
1577
|
+
this.nestedError = undefined;
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
class InvalidArgumentError extends CommanderError {
|
|
1581
|
+
constructor(message) {
|
|
1582
|
+
super(1, "commander.invalidArgument", message);
|
|
1583
|
+
Error.captureStackTrace(this, this.constructor);
|
|
1584
|
+
this.name = this.constructor.name;
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
exports.CommanderError = CommanderError;
|
|
1588
|
+
exports.InvalidArgumentError = InvalidArgumentError;
|
|
1589
|
+
},
|
|
1590
|
+
567: (__unused_webpack_module, exports, __nccwpck_require__) => {
|
|
1591
|
+
const { humanReadableArgName } = __nccwpck_require__(654);
|
|
1592
|
+
class Help {
|
|
1593
|
+
constructor() {
|
|
1594
|
+
this.helpWidth = undefined;
|
|
1595
|
+
this.sortSubcommands = false;
|
|
1596
|
+
this.sortOptions = false;
|
|
1597
|
+
this.showGlobalOptions = false;
|
|
1598
|
+
}
|
|
1599
|
+
visibleCommands(cmd) {
|
|
1600
|
+
const visibleCommands = cmd.commands.filter((cmd) => !cmd._hidden);
|
|
1601
|
+
const helpCommand = cmd._getHelpCommand();
|
|
1602
|
+
if (helpCommand && !helpCommand._hidden) {
|
|
1603
|
+
visibleCommands.push(helpCommand);
|
|
1604
|
+
}
|
|
1605
|
+
if (this.sortSubcommands) {
|
|
1606
|
+
visibleCommands.sort((a, b) => a.name().localeCompare(b.name()));
|
|
1607
|
+
}
|
|
1608
|
+
return visibleCommands;
|
|
1609
|
+
}
|
|
1610
|
+
compareOptions(a, b) {
|
|
1611
|
+
const getSortKey = (option) =>
|
|
1612
|
+
option.short
|
|
1613
|
+
? option.short.replace(/^-/, "")
|
|
1614
|
+
: option.long.replace(/^--/, "");
|
|
1615
|
+
return getSortKey(a).localeCompare(getSortKey(b));
|
|
1616
|
+
}
|
|
1617
|
+
visibleOptions(cmd) {
|
|
1618
|
+
const visibleOptions = cmd.options.filter((option) => !option.hidden);
|
|
1619
|
+
const helpOption = cmd._getHelpOption();
|
|
1620
|
+
if (helpOption && !helpOption.hidden) {
|
|
1621
|
+
const removeShort =
|
|
1622
|
+
helpOption.short && cmd._findOption(helpOption.short);
|
|
1623
|
+
const removeLong =
|
|
1624
|
+
helpOption.long && cmd._findOption(helpOption.long);
|
|
1625
|
+
if (!removeShort && !removeLong) {
|
|
1626
|
+
visibleOptions.push(helpOption);
|
|
1627
|
+
} else if (helpOption.long && !removeLong) {
|
|
1628
|
+
visibleOptions.push(
|
|
1629
|
+
cmd.createOption(helpOption.long, helpOption.description),
|
|
1630
|
+
);
|
|
1631
|
+
} else if (helpOption.short && !removeShort) {
|
|
1632
|
+
visibleOptions.push(
|
|
1633
|
+
cmd.createOption(helpOption.short, helpOption.description),
|
|
1634
|
+
);
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
if (this.sortOptions) {
|
|
1638
|
+
visibleOptions.sort(this.compareOptions);
|
|
1639
|
+
}
|
|
1640
|
+
return visibleOptions;
|
|
1641
|
+
}
|
|
1642
|
+
visibleGlobalOptions(cmd) {
|
|
1643
|
+
if (!this.showGlobalOptions) return [];
|
|
1644
|
+
const globalOptions = [];
|
|
1645
|
+
for (
|
|
1646
|
+
let ancestorCmd = cmd.parent;
|
|
1647
|
+
ancestorCmd;
|
|
1648
|
+
ancestorCmd = ancestorCmd.parent
|
|
1649
|
+
) {
|
|
1650
|
+
const visibleOptions = ancestorCmd.options.filter(
|
|
1651
|
+
(option) => !option.hidden,
|
|
1652
|
+
);
|
|
1653
|
+
globalOptions.push(...visibleOptions);
|
|
1654
|
+
}
|
|
1655
|
+
if (this.sortOptions) {
|
|
1656
|
+
globalOptions.sort(this.compareOptions);
|
|
1657
|
+
}
|
|
1658
|
+
return globalOptions;
|
|
1659
|
+
}
|
|
1660
|
+
visibleArguments(cmd) {
|
|
1661
|
+
if (cmd._argsDescription) {
|
|
1662
|
+
cmd.registeredArguments.forEach((argument) => {
|
|
1663
|
+
argument.description =
|
|
1664
|
+
argument.description ||
|
|
1665
|
+
cmd._argsDescription[argument.name()] ||
|
|
1666
|
+
"";
|
|
1667
|
+
});
|
|
1668
|
+
}
|
|
1669
|
+
if (
|
|
1670
|
+
cmd.registeredArguments.find((argument) => argument.description)
|
|
1671
|
+
) {
|
|
1672
|
+
return cmd.registeredArguments;
|
|
1673
|
+
}
|
|
1674
|
+
return [];
|
|
1675
|
+
}
|
|
1676
|
+
subcommandTerm(cmd) {
|
|
1677
|
+
const args = cmd.registeredArguments
|
|
1678
|
+
.map((arg) => humanReadableArgName(arg))
|
|
1679
|
+
.join(" ");
|
|
1680
|
+
return (
|
|
1681
|
+
cmd._name +
|
|
1682
|
+
(cmd._aliases[0] ? "|" + cmd._aliases[0] : "") +
|
|
1683
|
+
(cmd.options.length ? " [options]" : "") +
|
|
1684
|
+
(args ? " " + args : "")
|
|
1685
|
+
);
|
|
1686
|
+
}
|
|
1687
|
+
optionTerm(option) {
|
|
1688
|
+
return option.flags;
|
|
1689
|
+
}
|
|
1690
|
+
argumentTerm(argument) {
|
|
1691
|
+
return argument.name();
|
|
1692
|
+
}
|
|
1693
|
+
longestSubcommandTermLength(cmd, helper) {
|
|
1694
|
+
return helper
|
|
1695
|
+
.visibleCommands(cmd)
|
|
1696
|
+
.reduce(
|
|
1697
|
+
(max, command) =>
|
|
1698
|
+
Math.max(max, helper.subcommandTerm(command).length),
|
|
1699
|
+
0,
|
|
1700
|
+
);
|
|
1701
|
+
}
|
|
1702
|
+
longestOptionTermLength(cmd, helper) {
|
|
1703
|
+
return helper
|
|
1704
|
+
.visibleOptions(cmd)
|
|
1705
|
+
.reduce(
|
|
1706
|
+
(max, option) => Math.max(max, helper.optionTerm(option).length),
|
|
1707
|
+
0,
|
|
1708
|
+
);
|
|
1709
|
+
}
|
|
1710
|
+
longestGlobalOptionTermLength(cmd, helper) {
|
|
1711
|
+
return helper
|
|
1712
|
+
.visibleGlobalOptions(cmd)
|
|
1713
|
+
.reduce(
|
|
1714
|
+
(max, option) => Math.max(max, helper.optionTerm(option).length),
|
|
1715
|
+
0,
|
|
1716
|
+
);
|
|
1717
|
+
}
|
|
1718
|
+
longestArgumentTermLength(cmd, helper) {
|
|
1719
|
+
return helper
|
|
1720
|
+
.visibleArguments(cmd)
|
|
1721
|
+
.reduce(
|
|
1722
|
+
(max, argument) =>
|
|
1723
|
+
Math.max(max, helper.argumentTerm(argument).length),
|
|
1724
|
+
0,
|
|
1725
|
+
);
|
|
1726
|
+
}
|
|
1727
|
+
commandUsage(cmd) {
|
|
1728
|
+
let cmdName = cmd._name;
|
|
1729
|
+
if (cmd._aliases[0]) {
|
|
1730
|
+
cmdName = cmdName + "|" + cmd._aliases[0];
|
|
1731
|
+
}
|
|
1732
|
+
let ancestorCmdNames = "";
|
|
1733
|
+
for (
|
|
1734
|
+
let ancestorCmd = cmd.parent;
|
|
1735
|
+
ancestorCmd;
|
|
1736
|
+
ancestorCmd = ancestorCmd.parent
|
|
1737
|
+
) {
|
|
1738
|
+
ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
|
|
1739
|
+
}
|
|
1740
|
+
return ancestorCmdNames + cmdName + " " + cmd.usage();
|
|
1741
|
+
}
|
|
1742
|
+
commandDescription(cmd) {
|
|
1743
|
+
return cmd.description();
|
|
1744
|
+
}
|
|
1745
|
+
subcommandDescription(cmd) {
|
|
1746
|
+
return cmd.summary() || cmd.description();
|
|
1747
|
+
}
|
|
1748
|
+
optionDescription(option) {
|
|
1749
|
+
const extraInfo = [];
|
|
1750
|
+
if (option.argChoices) {
|
|
1751
|
+
extraInfo.push(
|
|
1752
|
+
`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`,
|
|
1753
|
+
);
|
|
1754
|
+
}
|
|
1755
|
+
if (option.defaultValue !== undefined) {
|
|
1756
|
+
const showDefault =
|
|
1757
|
+
option.required ||
|
|
1758
|
+
option.optional ||
|
|
1759
|
+
(option.isBoolean() && typeof option.defaultValue === "boolean");
|
|
1760
|
+
if (showDefault) {
|
|
1761
|
+
extraInfo.push(
|
|
1762
|
+
`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`,
|
|
1763
|
+
);
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1766
|
+
if (option.presetArg !== undefined && option.optional) {
|
|
1767
|
+
extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
|
|
1768
|
+
}
|
|
1769
|
+
if (option.envVar !== undefined) {
|
|
1770
|
+
extraInfo.push(`env: ${option.envVar}`);
|
|
1771
|
+
}
|
|
1772
|
+
if (extraInfo.length > 0) {
|
|
1773
|
+
return `${option.description} (${extraInfo.join(", ")})`;
|
|
1774
|
+
}
|
|
1775
|
+
return option.description;
|
|
1776
|
+
}
|
|
1777
|
+
argumentDescription(argument) {
|
|
1778
|
+
const extraInfo = [];
|
|
1779
|
+
if (argument.argChoices) {
|
|
1780
|
+
extraInfo.push(
|
|
1781
|
+
`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`,
|
|
1782
|
+
);
|
|
1783
|
+
}
|
|
1784
|
+
if (argument.defaultValue !== undefined) {
|
|
1785
|
+
extraInfo.push(
|
|
1786
|
+
`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`,
|
|
1787
|
+
);
|
|
1788
|
+
}
|
|
1789
|
+
if (extraInfo.length > 0) {
|
|
1790
|
+
const extraDescripton = `(${extraInfo.join(", ")})`;
|
|
1791
|
+
if (argument.description) {
|
|
1792
|
+
return `${argument.description} ${extraDescripton}`;
|
|
1793
|
+
}
|
|
1794
|
+
return extraDescripton;
|
|
1795
|
+
}
|
|
1796
|
+
return argument.description;
|
|
1797
|
+
}
|
|
1798
|
+
formatHelp(cmd, helper) {
|
|
1799
|
+
const termWidth = helper.padWidth(cmd, helper);
|
|
1800
|
+
const helpWidth = helper.helpWidth || 80;
|
|
1801
|
+
const itemIndentWidth = 2;
|
|
1802
|
+
const itemSeparatorWidth = 2;
|
|
1803
|
+
function formatItem(term, description) {
|
|
1804
|
+
if (description) {
|
|
1805
|
+
const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;
|
|
1806
|
+
return helper.wrap(
|
|
1807
|
+
fullText,
|
|
1808
|
+
helpWidth - itemIndentWidth,
|
|
1809
|
+
termWidth + itemSeparatorWidth,
|
|
1810
|
+
);
|
|
1811
|
+
}
|
|
1812
|
+
return term;
|
|
1813
|
+
}
|
|
1814
|
+
function formatList(textArray) {
|
|
1815
|
+
return textArray
|
|
1816
|
+
.join("\n")
|
|
1817
|
+
.replace(/^/gm, " ".repeat(itemIndentWidth));
|
|
1818
|
+
}
|
|
1819
|
+
let output = [`Usage: ${helper.commandUsage(cmd)}`, ""];
|
|
1820
|
+
const commandDescription = helper.commandDescription(cmd);
|
|
1821
|
+
if (commandDescription.length > 0) {
|
|
1822
|
+
output = output.concat([
|
|
1823
|
+
helper.wrap(commandDescription, helpWidth, 0),
|
|
1824
|
+
"",
|
|
1825
|
+
]);
|
|
1826
|
+
}
|
|
1827
|
+
const argumentList = helper
|
|
1828
|
+
.visibleArguments(cmd)
|
|
1829
|
+
.map((argument) =>
|
|
1830
|
+
formatItem(
|
|
1831
|
+
helper.argumentTerm(argument),
|
|
1832
|
+
helper.argumentDescription(argument),
|
|
1833
|
+
),
|
|
1834
|
+
);
|
|
1835
|
+
if (argumentList.length > 0) {
|
|
1836
|
+
output = output.concat([
|
|
1837
|
+
"Arguments:",
|
|
1838
|
+
formatList(argumentList),
|
|
1839
|
+
"",
|
|
1840
|
+
]);
|
|
1841
|
+
}
|
|
1842
|
+
const optionList = helper
|
|
1843
|
+
.visibleOptions(cmd)
|
|
1844
|
+
.map((option) =>
|
|
1845
|
+
formatItem(
|
|
1846
|
+
helper.optionTerm(option),
|
|
1847
|
+
helper.optionDescription(option),
|
|
1848
|
+
),
|
|
1849
|
+
);
|
|
1850
|
+
if (optionList.length > 0) {
|
|
1851
|
+
output = output.concat(["Options:", formatList(optionList), ""]);
|
|
1852
|
+
}
|
|
1853
|
+
if (this.showGlobalOptions) {
|
|
1854
|
+
const globalOptionList = helper
|
|
1855
|
+
.visibleGlobalOptions(cmd)
|
|
1856
|
+
.map((option) =>
|
|
1857
|
+
formatItem(
|
|
1858
|
+
helper.optionTerm(option),
|
|
1859
|
+
helper.optionDescription(option),
|
|
1860
|
+
),
|
|
1861
|
+
);
|
|
1862
|
+
if (globalOptionList.length > 0) {
|
|
1863
|
+
output = output.concat([
|
|
1864
|
+
"Global Options:",
|
|
1865
|
+
formatList(globalOptionList),
|
|
1866
|
+
"",
|
|
1867
|
+
]);
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
const commandList = helper
|
|
1871
|
+
.visibleCommands(cmd)
|
|
1872
|
+
.map((cmd) =>
|
|
1873
|
+
formatItem(
|
|
1874
|
+
helper.subcommandTerm(cmd),
|
|
1875
|
+
helper.subcommandDescription(cmd),
|
|
1876
|
+
),
|
|
1877
|
+
);
|
|
1878
|
+
if (commandList.length > 0) {
|
|
1879
|
+
output = output.concat(["Commands:", formatList(commandList), ""]);
|
|
1880
|
+
}
|
|
1881
|
+
return output.join("\n");
|
|
1882
|
+
}
|
|
1883
|
+
padWidth(cmd, helper) {
|
|
1884
|
+
return Math.max(
|
|
1885
|
+
helper.longestOptionTermLength(cmd, helper),
|
|
1886
|
+
helper.longestGlobalOptionTermLength(cmd, helper),
|
|
1887
|
+
helper.longestSubcommandTermLength(cmd, helper),
|
|
1888
|
+
helper.longestArgumentTermLength(cmd, helper),
|
|
1889
|
+
);
|
|
1890
|
+
}
|
|
1891
|
+
wrap(str, width, indent, minColumnWidth = 40) {
|
|
1892
|
+
const indents = " \\f\\t\\v - \ufeff";
|
|
1893
|
+
const manualIndent = new RegExp(`[\\n][${indents}]+`);
|
|
1894
|
+
if (str.match(manualIndent)) return str;
|
|
1895
|
+
const columnWidth = width - indent;
|
|
1896
|
+
if (columnWidth < minColumnWidth) return str;
|
|
1897
|
+
const leadingStr = str.slice(0, indent);
|
|
1898
|
+
const columnText = str.slice(indent).replace("\r\n", "\n");
|
|
1899
|
+
const indentString = " ".repeat(indent);
|
|
1900
|
+
const zeroWidthSpace = "";
|
|
1901
|
+
const breaks = `\\s${zeroWidthSpace}`;
|
|
1902
|
+
const regex = new RegExp(
|
|
1903
|
+
`\n|.{1,${columnWidth - 1}}([${breaks}]|$)|[^${breaks}]+?([${breaks}]|$)`,
|
|
1904
|
+
"g",
|
|
1905
|
+
);
|
|
1906
|
+
const lines = columnText.match(regex) || [];
|
|
1907
|
+
return (
|
|
1908
|
+
leadingStr +
|
|
1909
|
+
lines
|
|
1910
|
+
.map((line, i) => {
|
|
1911
|
+
if (line === "\n") return "";
|
|
1912
|
+
return (i > 0 ? indentString : "") + line.trimEnd();
|
|
1913
|
+
})
|
|
1914
|
+
.join("\n")
|
|
1915
|
+
);
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
exports.Help = Help;
|
|
1919
|
+
},
|
|
1920
|
+
230: (__unused_webpack_module, exports, __nccwpck_require__) => {
|
|
1921
|
+
const { InvalidArgumentError } = __nccwpck_require__(829);
|
|
1922
|
+
class Option {
|
|
1923
|
+
constructor(flags, description) {
|
|
1924
|
+
this.flags = flags;
|
|
1925
|
+
this.description = description || "";
|
|
1926
|
+
this.required = flags.includes("<");
|
|
1927
|
+
this.optional = flags.includes("[");
|
|
1928
|
+
this.variadic = /\w\.\.\.[>\]]$/.test(flags);
|
|
1929
|
+
this.mandatory = false;
|
|
1930
|
+
const optionFlags = splitOptionFlags(flags);
|
|
1931
|
+
this.short = optionFlags.shortFlag;
|
|
1932
|
+
this.long = optionFlags.longFlag;
|
|
1933
|
+
this.negate = false;
|
|
1934
|
+
if (this.long) {
|
|
1935
|
+
this.negate = this.long.startsWith("--no-");
|
|
1936
|
+
}
|
|
1937
|
+
this.defaultValue = undefined;
|
|
1938
|
+
this.defaultValueDescription = undefined;
|
|
1939
|
+
this.presetArg = undefined;
|
|
1940
|
+
this.envVar = undefined;
|
|
1941
|
+
this.parseArg = undefined;
|
|
1942
|
+
this.hidden = false;
|
|
1943
|
+
this.argChoices = undefined;
|
|
1944
|
+
this.conflictsWith = [];
|
|
1945
|
+
this.implied = undefined;
|
|
1946
|
+
}
|
|
1947
|
+
default(value, description) {
|
|
1948
|
+
this.defaultValue = value;
|
|
1949
|
+
this.defaultValueDescription = description;
|
|
1950
|
+
return this;
|
|
1951
|
+
}
|
|
1952
|
+
preset(arg) {
|
|
1953
|
+
this.presetArg = arg;
|
|
1954
|
+
return this;
|
|
1955
|
+
}
|
|
1956
|
+
conflicts(names) {
|
|
1957
|
+
this.conflictsWith = this.conflictsWith.concat(names);
|
|
1958
|
+
return this;
|
|
1959
|
+
}
|
|
1960
|
+
implies(impliedOptionValues) {
|
|
1961
|
+
let newImplied = impliedOptionValues;
|
|
1962
|
+
if (typeof impliedOptionValues === "string") {
|
|
1963
|
+
newImplied = { [impliedOptionValues]: true };
|
|
1964
|
+
}
|
|
1965
|
+
this.implied = Object.assign(this.implied || {}, newImplied);
|
|
1966
|
+
return this;
|
|
1967
|
+
}
|
|
1968
|
+
env(name) {
|
|
1969
|
+
this.envVar = name;
|
|
1970
|
+
return this;
|
|
1971
|
+
}
|
|
1972
|
+
argParser(fn) {
|
|
1973
|
+
this.parseArg = fn;
|
|
1974
|
+
return this;
|
|
1975
|
+
}
|
|
1976
|
+
makeOptionMandatory(mandatory = true) {
|
|
1977
|
+
this.mandatory = !!mandatory;
|
|
1978
|
+
return this;
|
|
1979
|
+
}
|
|
1980
|
+
hideHelp(hide = true) {
|
|
1981
|
+
this.hidden = !!hide;
|
|
1982
|
+
return this;
|
|
1983
|
+
}
|
|
1984
|
+
_concatValue(value, previous) {
|
|
1985
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
1986
|
+
return [value];
|
|
1987
|
+
}
|
|
1988
|
+
return previous.concat(value);
|
|
1989
|
+
}
|
|
1990
|
+
choices(values) {
|
|
1991
|
+
this.argChoices = values.slice();
|
|
1992
|
+
this.parseArg = (arg, previous) => {
|
|
1993
|
+
if (!this.argChoices.includes(arg)) {
|
|
1994
|
+
throw new InvalidArgumentError(
|
|
1995
|
+
`Allowed choices are ${this.argChoices.join(", ")}.`,
|
|
1996
|
+
);
|
|
1997
|
+
}
|
|
1998
|
+
if (this.variadic) {
|
|
1999
|
+
return this._concatValue(arg, previous);
|
|
2000
|
+
}
|
|
2001
|
+
return arg;
|
|
2002
|
+
};
|
|
2003
|
+
return this;
|
|
2004
|
+
}
|
|
2005
|
+
name() {
|
|
2006
|
+
if (this.long) {
|
|
2007
|
+
return this.long.replace(/^--/, "");
|
|
2008
|
+
}
|
|
2009
|
+
return this.short.replace(/^-/, "");
|
|
2010
|
+
}
|
|
2011
|
+
attributeName() {
|
|
2012
|
+
return camelcase(this.name().replace(/^no-/, ""));
|
|
2013
|
+
}
|
|
2014
|
+
is(arg) {
|
|
2015
|
+
return this.short === arg || this.long === arg;
|
|
2016
|
+
}
|
|
2017
|
+
isBoolean() {
|
|
2018
|
+
return !this.required && !this.optional && !this.negate;
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
class DualOptions {
|
|
2022
|
+
constructor(options) {
|
|
2023
|
+
this.positiveOptions = new Map();
|
|
2024
|
+
this.negativeOptions = new Map();
|
|
2025
|
+
this.dualOptions = new Set();
|
|
2026
|
+
options.forEach((option) => {
|
|
2027
|
+
if (option.negate) {
|
|
2028
|
+
this.negativeOptions.set(option.attributeName(), option);
|
|
2029
|
+
} else {
|
|
2030
|
+
this.positiveOptions.set(option.attributeName(), option);
|
|
2031
|
+
}
|
|
2032
|
+
});
|
|
2033
|
+
this.negativeOptions.forEach((value, key) => {
|
|
2034
|
+
if (this.positiveOptions.has(key)) {
|
|
2035
|
+
this.dualOptions.add(key);
|
|
2036
|
+
}
|
|
2037
|
+
});
|
|
2038
|
+
}
|
|
2039
|
+
valueFromOption(value, option) {
|
|
2040
|
+
const optionKey = option.attributeName();
|
|
2041
|
+
if (!this.dualOptions.has(optionKey)) return true;
|
|
2042
|
+
const preset = this.negativeOptions.get(optionKey).presetArg;
|
|
2043
|
+
const negativeValue = preset !== undefined ? preset : false;
|
|
2044
|
+
return option.negate === (negativeValue === value);
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
function camelcase(str) {
|
|
2048
|
+
return str
|
|
2049
|
+
.split("-")
|
|
2050
|
+
.reduce((str, word) => str + word[0].toUpperCase() + word.slice(1));
|
|
2051
|
+
}
|
|
2052
|
+
function splitOptionFlags(flags) {
|
|
2053
|
+
let shortFlag;
|
|
2054
|
+
let longFlag;
|
|
2055
|
+
const flagParts = flags.split(/[ |,]+/);
|
|
2056
|
+
if (flagParts.length > 1 && !/^[[<]/.test(flagParts[1]))
|
|
2057
|
+
shortFlag = flagParts.shift();
|
|
2058
|
+
longFlag = flagParts.shift();
|
|
2059
|
+
if (!shortFlag && /^-[^-]$/.test(longFlag)) {
|
|
2060
|
+
shortFlag = longFlag;
|
|
2061
|
+
longFlag = undefined;
|
|
2062
|
+
}
|
|
2063
|
+
return { shortFlag, longFlag };
|
|
2064
|
+
}
|
|
2065
|
+
exports.Option = Option;
|
|
2066
|
+
exports.DualOptions = DualOptions;
|
|
2067
|
+
},
|
|
2068
|
+
241: (__unused_webpack_module, exports) => {
|
|
2069
|
+
const maxDistance = 3;
|
|
2070
|
+
function editDistance(a, b) {
|
|
2071
|
+
if (Math.abs(a.length - b.length) > maxDistance)
|
|
2072
|
+
return Math.max(a.length, b.length);
|
|
2073
|
+
const d = [];
|
|
2074
|
+
for (let i = 0; i <= a.length; i++) {
|
|
2075
|
+
d[i] = [i];
|
|
2076
|
+
}
|
|
2077
|
+
for (let j = 0; j <= b.length; j++) {
|
|
2078
|
+
d[0][j] = j;
|
|
2079
|
+
}
|
|
2080
|
+
for (let j = 1; j <= b.length; j++) {
|
|
2081
|
+
for (let i = 1; i <= a.length; i++) {
|
|
2082
|
+
let cost = 1;
|
|
2083
|
+
if (a[i - 1] === b[j - 1]) {
|
|
2084
|
+
cost = 0;
|
|
2085
|
+
} else {
|
|
2086
|
+
cost = 1;
|
|
2087
|
+
}
|
|
2088
|
+
d[i][j] = Math.min(
|
|
2089
|
+
d[i - 1][j] + 1,
|
|
2090
|
+
d[i][j - 1] + 1,
|
|
2091
|
+
d[i - 1][j - 1] + cost,
|
|
2092
|
+
);
|
|
2093
|
+
if (
|
|
2094
|
+
i > 1 &&
|
|
2095
|
+
j > 1 &&
|
|
2096
|
+
a[i - 1] === b[j - 2] &&
|
|
2097
|
+
a[i - 2] === b[j - 1]
|
|
2098
|
+
) {
|
|
2099
|
+
d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2103
|
+
return d[a.length][b.length];
|
|
2104
|
+
}
|
|
2105
|
+
function suggestSimilar(word, candidates) {
|
|
2106
|
+
if (!candidates || candidates.length === 0) return "";
|
|
2107
|
+
candidates = Array.from(new Set(candidates));
|
|
2108
|
+
const searchingOptions = word.startsWith("--");
|
|
2109
|
+
if (searchingOptions) {
|
|
2110
|
+
word = word.slice(2);
|
|
2111
|
+
candidates = candidates.map((candidate) => candidate.slice(2));
|
|
2112
|
+
}
|
|
2113
|
+
let similar = [];
|
|
2114
|
+
let bestDistance = maxDistance;
|
|
2115
|
+
const minSimilarity = 0.4;
|
|
2116
|
+
candidates.forEach((candidate) => {
|
|
2117
|
+
if (candidate.length <= 1) return;
|
|
2118
|
+
const distance = editDistance(word, candidate);
|
|
2119
|
+
const length = Math.max(word.length, candidate.length);
|
|
2120
|
+
const similarity = (length - distance) / length;
|
|
2121
|
+
if (similarity > minSimilarity) {
|
|
2122
|
+
if (distance < bestDistance) {
|
|
2123
|
+
bestDistance = distance;
|
|
2124
|
+
similar = [candidate];
|
|
2125
|
+
} else if (distance === bestDistance) {
|
|
2126
|
+
similar.push(candidate);
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
});
|
|
2130
|
+
similar.sort((a, b) => a.localeCompare(b));
|
|
2131
|
+
if (searchingOptions) {
|
|
2132
|
+
similar = similar.map((candidate) => `--${candidate}`);
|
|
2133
|
+
}
|
|
2134
|
+
if (similar.length > 1) {
|
|
2135
|
+
return `\n(Did you mean one of ${similar.join(", ")}?)`;
|
|
2136
|
+
}
|
|
2137
|
+
if (similar.length === 1) {
|
|
2138
|
+
return `\n(Did you mean ${similar[0]}?)`;
|
|
2139
|
+
}
|
|
2140
|
+
return "";
|
|
2141
|
+
}
|
|
2142
|
+
exports.suggestSimilar = suggestSimilar;
|
|
2143
|
+
},
|
|
2144
|
+
};
|
|
2145
|
+
var __webpack_module_cache__ = {};
|
|
2146
|
+
function __nccwpck_require__(moduleId) {
|
|
2147
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
2148
|
+
if (cachedModule !== undefined) {
|
|
2149
|
+
return cachedModule.exports;
|
|
2150
|
+
}
|
|
2151
|
+
var module = (__webpack_module_cache__[moduleId] = { exports: {} });
|
|
2152
|
+
var threw = true;
|
|
2153
|
+
try {
|
|
2154
|
+
__webpack_modules__[moduleId](
|
|
2155
|
+
module,
|
|
2156
|
+
module.exports,
|
|
2157
|
+
__nccwpck_require__,
|
|
2158
|
+
);
|
|
2159
|
+
threw = false;
|
|
2160
|
+
} finally {
|
|
2161
|
+
if (threw) delete __webpack_module_cache__[moduleId];
|
|
2162
|
+
}
|
|
2163
|
+
return module.exports;
|
|
2164
|
+
}
|
|
2165
|
+
if (typeof __nccwpck_require__ !== "undefined")
|
|
2166
|
+
__nccwpck_require__.ab = __dirname + "/";
|
|
2167
|
+
var __webpack_exports__ = {};
|
|
2168
|
+
(() => {
|
|
2169
|
+
var exports = __webpack_exports__;
|
|
2170
|
+
const { Argument } = __nccwpck_require__(654);
|
|
2171
|
+
const { Command } = __nccwpck_require__(955);
|
|
2172
|
+
const { CommanderError, InvalidArgumentError } = __nccwpck_require__(829);
|
|
2173
|
+
const { Help } = __nccwpck_require__(567);
|
|
2174
|
+
const { Option } = __nccwpck_require__(230);
|
|
2175
|
+
exports.program = new Command();
|
|
2176
|
+
exports.createCommand = (name) => new Command(name);
|
|
2177
|
+
exports.createOption = (flags, description) =>
|
|
2178
|
+
new Option(flags, description);
|
|
2179
|
+
exports.createArgument = (name, description) =>
|
|
2180
|
+
new Argument(name, description);
|
|
2181
|
+
exports.Command = Command;
|
|
2182
|
+
exports.Option = Option;
|
|
2183
|
+
exports.Argument = Argument;
|
|
2184
|
+
exports.Help = Help;
|
|
2185
|
+
exports.CommanderError = CommanderError;
|
|
2186
|
+
exports.InvalidArgumentError = InvalidArgumentError;
|
|
2187
|
+
exports.InvalidOptionArgumentError = InvalidArgumentError;
|
|
2188
|
+
})();
|
|
2189
|
+
module.exports = __webpack_exports__;
|
|
2190
|
+
})();
|