@requence/task 1.0.0-alpha.5 → 1.0.0-alpha.51

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.
Files changed (108) hide show
  1. package/CHANGELOG.md +276 -0
  2. package/README.md +383 -0
  3. package/build/chunk-b4h2we9a.js +35 -0
  4. package/build/chunk-b4h2we9a.js.map +10 -0
  5. package/build/cli.js +21 -4874
  6. package/build/cli.js.map +4 -37
  7. package/build/index.js +1011 -233
  8. package/build/index.js.map +22 -8
  9. package/build/types/helpers/src/files/RequenceFile.d.ts +40 -0
  10. package/build/types/helpers/src/files/RequenceFile.d.ts.map +1 -0
  11. package/build/types/helpers/src/files/RequenceStream.d.ts +32 -0
  12. package/build/types/helpers/src/files/RequenceStream.d.ts.map +1 -0
  13. package/build/types/helpers/src/files/fileObject.d.ts +16 -0
  14. package/build/types/helpers/src/files/fileObject.d.ts.map +1 -0
  15. package/build/types/helpers/src/files/index.d.ts +7 -0
  16. package/build/types/helpers/src/files/index.d.ts.map +1 -0
  17. package/build/types/helpers/src/files/isValidMimeType.d.ts +5 -0
  18. package/build/types/helpers/src/files/isValidMimeType.d.ts.map +1 -0
  19. package/build/types/helpers/src/files/mapOutput.d.ts +10 -0
  20. package/build/types/helpers/src/files/mapOutput.d.ts.map +1 -0
  21. package/build/types/helpers/src/files/streamObject.d.ts +14 -0
  22. package/build/types/helpers/src/files/streamObject.d.ts.map +1 -0
  23. package/build/types/helpers/src/files/types.d.ts +4 -0
  24. package/build/types/helpers/src/files/types.d.ts.map +1 -0
  25. package/build/types/helpers/src/index.d.ts +12 -6
  26. package/build/types/helpers/src/index.d.ts.map +1 -1
  27. package/build/types/helpers/src/jsonschema/mapSchema.d.ts +20 -0
  28. package/build/types/helpers/src/jsonschema/mapSchema.d.ts.map +1 -0
  29. package/build/types/helpers/src/jsonschema/types.d.ts +13 -0
  30. package/build/types/helpers/src/jsonschema/types.d.ts.map +1 -0
  31. package/build/types/helpers/src/jsonschema/validate.d.ts +32 -0
  32. package/build/types/helpers/src/jsonschema/validate.d.ts.map +1 -0
  33. package/build/types/helpers/src/jsonschema/zod.d.ts +17 -0
  34. package/build/types/helpers/src/jsonschema/zod.d.ts.map +1 -0
  35. package/build/types/helpers/src/protocol/NodeTree.d.ts +510 -0
  36. package/build/types/helpers/src/protocol/NodeTree.d.ts.map +1 -0
  37. package/build/types/helpers/src/protocol/command.d.ts +507 -0
  38. package/build/types/helpers/src/protocol/command.d.ts.map +1 -0
  39. package/build/types/helpers/src/protocol/helpers.d.ts +7 -0
  40. package/build/types/helpers/src/protocol/helpers.d.ts.map +1 -0
  41. package/build/types/helpers/src/protocol/index.d.ts +8 -0
  42. package/build/types/helpers/src/protocol/index.d.ts.map +1 -0
  43. package/build/types/helpers/src/protocol/nodeType.d.ts +181 -0
  44. package/build/types/helpers/src/protocol/nodeType.d.ts.map +1 -0
  45. package/build/types/helpers/src/protocol/taskOptions.d.ts +23 -0
  46. package/build/types/helpers/src/protocol/taskOptions.d.ts.map +1 -0
  47. package/build/types/helpers/src/protocol/templateNodeTypes.d.ts +267 -0
  48. package/build/types/helpers/src/protocol/templateNodeTypes.d.ts.map +1 -0
  49. package/build/types/helpers/src/protocol/treeNodes.d.ts +874 -0
  50. package/build/types/helpers/src/protocol/treeNodes.d.ts.map +1 -0
  51. package/build/types/helpers/src/protocol/update.d.ts +406 -0
  52. package/build/types/helpers/src/protocol/update.d.ts.map +1 -0
  53. package/build/types/helpers/src/utils/callbackToAsyncIterator.d.ts +3 -0
  54. package/build/types/helpers/src/utils/callbackToAsyncIterator.d.ts.map +1 -0
  55. package/build/types/helpers/src/utils/clone.d.ts +3 -0
  56. package/build/types/helpers/src/utils/clone.d.ts.map +1 -0
  57. package/build/types/helpers/src/utils/createObjectProxy.d.ts +2 -0
  58. package/build/types/helpers/src/utils/createObjectProxy.d.ts.map +1 -0
  59. package/build/types/helpers/src/utils/debounce.d.ts +4 -0
  60. package/build/types/helpers/src/utils/debounce.d.ts.map +1 -0
  61. package/build/types/helpers/src/utils/guards.d.ts +3 -0
  62. package/build/types/helpers/src/utils/guards.d.ts.map +1 -0
  63. package/build/types/helpers/src/utils/mapData.d.ts +18 -0
  64. package/build/types/helpers/src/utils/mapData.d.ts.map +1 -0
  65. package/build/types/helpers/src/{utils.d.ts → utils/matchSchema.d.ts} +2 -2
  66. package/build/types/helpers/src/utils/matchSchema.d.ts.map +1 -0
  67. package/build/types/helpers/src/utils/obfuscate.d.ts.map +1 -0
  68. package/build/types/helpers/src/utils/obj.d.ts +4 -0
  69. package/build/types/helpers/src/utils/obj.d.ts.map +1 -0
  70. package/build/types/helpers/src/utils/requenceCallback.d.ts +17 -0
  71. package/build/types/helpers/src/utils/requenceCallback.d.ts.map +1 -0
  72. package/build/types/helpers/src/utils/resolveRequenceTypes.d.ts +8 -0
  73. package/build/types/helpers/src/utils/resolveRequenceTypes.d.ts.map +1 -0
  74. package/build/types/helpers/src/utils/types.d.ts +7 -0
  75. package/build/types/helpers/src/utils/types.d.ts.map +1 -0
  76. package/build/types/task/src/abortTask.d.ts +8 -0
  77. package/build/types/task/src/abortTask.d.ts.map +1 -0
  78. package/build/types/task/src/ackTask.d.ts +7 -0
  79. package/build/types/task/src/ackTask.d.ts.map +1 -0
  80. package/build/types/task/src/createTask.d.ts +14 -103
  81. package/build/types/task/src/createTask.d.ts.map +1 -1
  82. package/build/types/task/src/getTask.d.ts +26 -0
  83. package/build/types/task/src/getTask.d.ts.map +1 -0
  84. package/build/types/task/src/index.d.ts +7 -1
  85. package/build/types/task/src/index.d.ts.map +1 -1
  86. package/build/types/task/src/protectTask.d.ts +7 -0
  87. package/build/types/task/src/protectTask.d.ts.map +1 -0
  88. package/build/types/task/src/recreateTask.d.ts +10 -0
  89. package/build/types/task/src/recreateTask.d.ts.map +1 -0
  90. package/build/types/task/src/types.d.ts +196 -941
  91. package/build/types/task/src/types.d.ts.map +1 -1
  92. package/build/types/task/src/utils/getAccessToken.d.ts.map +1 -1
  93. package/build/types/task/src/watchTasks.d.ts +13 -97
  94. package/build/types/task/src/watchTasks.d.ts.map +1 -1
  95. package/package.json +12 -7
  96. package/build/chunk-6pjtq0hg.js +0 -66
  97. package/build/chunk-6pjtq0hg.js.map +0 -12
  98. package/build/types/helpers/src/clone.d.ts +0 -3
  99. package/build/types/helpers/src/clone.d.ts.map +0 -1
  100. package/build/types/helpers/src/createObjectProxy.d.ts +0 -2
  101. package/build/types/helpers/src/createObjectProxy.d.ts.map +0 -1
  102. package/build/types/helpers/src/createRemotePromise.d.ts +0 -7
  103. package/build/types/helpers/src/createRemotePromise.d.ts.map +0 -1
  104. package/build/types/helpers/src/obfuscate.d.ts.map +0 -1
  105. package/build/types/helpers/src/utils.d.ts.map +0 -1
  106. package/build/types/task/src/utils/callbackToAsyncIterator.d.ts +0 -5
  107. package/build/types/task/src/utils/callbackToAsyncIterator.d.ts.map +0 -1
  108. /package/build/types/helpers/src/{obfuscate.d.ts → utils/obfuscate.d.ts} +0 -0
package/build/cli.js CHANGED
@@ -1,4876 +1,15 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
- __require,
4
3
  deobfuscate
5
- } from "./chunk-6pjtq0hg.js";
4
+ } from "./chunk-b4h2we9a.js";
6
5
 
7
6
  // src/cli.ts
8
7
  import fs from "node:fs";
9
8
  import path from "node:path";
10
9
  import chalk from "chalk";
11
-
12
- // ../../node_modules/yargs/lib/platform-shims/esm.mjs
13
- import { notStrictEqual, strictEqual } from "assert";
14
-
15
- // ../../node_modules/cliui/build/lib/index.js
16
- var align = {
17
- right: alignRight,
18
- center: alignCenter
19
- };
20
- var top = 0;
21
- var right = 1;
22
- var bottom = 2;
23
- var left = 3;
24
-
25
- class UI {
26
- constructor(opts) {
27
- var _a;
28
- this.width = opts.width;
29
- this.wrap = (_a = opts.wrap) !== null && _a !== undefined ? _a : true;
30
- this.rows = [];
31
- }
32
- span(...args) {
33
- const cols = this.div(...args);
34
- cols.span = true;
35
- }
36
- resetOutput() {
37
- this.rows = [];
38
- }
39
- div(...args) {
40
- if (args.length === 0) {
41
- this.div("");
42
- }
43
- if (this.wrap && this.shouldApplyLayoutDSL(...args) && typeof args[0] === "string") {
44
- return this.applyLayoutDSL(args[0]);
45
- }
46
- const cols = args.map((arg) => {
47
- if (typeof arg === "string") {
48
- return this.colFromString(arg);
49
- }
50
- return arg;
51
- });
52
- this.rows.push(cols);
53
- return cols;
54
- }
55
- shouldApplyLayoutDSL(...args) {
56
- return args.length === 1 && typeof args[0] === "string" && /[\t\n]/.test(args[0]);
57
- }
58
- applyLayoutDSL(str) {
59
- const rows = str.split(`
60
- `).map((row) => row.split("\t"));
61
- let leftColumnWidth = 0;
62
- rows.forEach((columns) => {
63
- if (columns.length > 1 && mixin.stringWidth(columns[0]) > leftColumnWidth) {
64
- leftColumnWidth = Math.min(Math.floor(this.width * 0.5), mixin.stringWidth(columns[0]));
65
- }
66
- });
67
- rows.forEach((columns) => {
68
- this.div(...columns.map((r, i) => {
69
- return {
70
- text: r.trim(),
71
- padding: this.measurePadding(r),
72
- width: i === 0 && columns.length > 1 ? leftColumnWidth : undefined
73
- };
74
- }));
75
- });
76
- return this.rows[this.rows.length - 1];
77
- }
78
- colFromString(text) {
79
- return {
80
- text,
81
- padding: this.measurePadding(text)
82
- };
83
- }
84
- measurePadding(str) {
85
- const noAnsi = mixin.stripAnsi(str);
86
- return [0, noAnsi.match(/\s*$/)[0].length, 0, noAnsi.match(/^\s*/)[0].length];
87
- }
88
- toString() {
89
- const lines = [];
90
- this.rows.forEach((row) => {
91
- this.rowToString(row, lines);
92
- });
93
- return lines.filter((line) => !line.hidden).map((line) => line.text).join(`
94
- `);
95
- }
96
- rowToString(row, lines) {
97
- this.rasterize(row).forEach((rrow, r) => {
98
- let str = "";
99
- rrow.forEach((col, c) => {
100
- const { width } = row[c];
101
- const wrapWidth = this.negatePadding(row[c]);
102
- let ts = col;
103
- if (wrapWidth > mixin.stringWidth(col)) {
104
- ts += " ".repeat(wrapWidth - mixin.stringWidth(col));
105
- }
106
- if (row[c].align && row[c].align !== "left" && this.wrap) {
107
- const fn = align[row[c].align];
108
- ts = fn(ts, wrapWidth);
109
- if (mixin.stringWidth(ts) < wrapWidth) {
110
- ts += " ".repeat((width || 0) - mixin.stringWidth(ts) - 1);
111
- }
112
- }
113
- const padding = row[c].padding || [0, 0, 0, 0];
114
- if (padding[left]) {
115
- str += " ".repeat(padding[left]);
116
- }
117
- str += addBorder(row[c], ts, "| ");
118
- str += ts;
119
- str += addBorder(row[c], ts, " |");
120
- if (padding[right]) {
121
- str += " ".repeat(padding[right]);
122
- }
123
- if (r === 0 && lines.length > 0) {
124
- str = this.renderInline(str, lines[lines.length - 1]);
125
- }
126
- });
127
- lines.push({
128
- text: str.replace(/ +$/, ""),
129
- span: row.span
130
- });
131
- });
132
- return lines;
133
- }
134
- renderInline(source, previousLine) {
135
- const match = source.match(/^ */);
136
- const leadingWhitespace = match ? match[0].length : 0;
137
- const target = previousLine.text;
138
- const targetTextWidth = mixin.stringWidth(target.trimRight());
139
- if (!previousLine.span) {
140
- return source;
141
- }
142
- if (!this.wrap) {
143
- previousLine.hidden = true;
144
- return target + source;
145
- }
146
- if (leadingWhitespace < targetTextWidth) {
147
- return source;
148
- }
149
- previousLine.hidden = true;
150
- return target.trimRight() + " ".repeat(leadingWhitespace - targetTextWidth) + source.trimLeft();
151
- }
152
- rasterize(row) {
153
- const rrows = [];
154
- const widths = this.columnWidths(row);
155
- let wrapped;
156
- row.forEach((col, c) => {
157
- col.width = widths[c];
158
- if (this.wrap) {
159
- wrapped = mixin.wrap(col.text, this.negatePadding(col), { hard: true }).split(`
160
- `);
161
- } else {
162
- wrapped = col.text.split(`
163
- `);
164
- }
165
- if (col.border) {
166
- wrapped.unshift("." + "-".repeat(this.negatePadding(col) + 2) + ".");
167
- wrapped.push("'" + "-".repeat(this.negatePadding(col) + 2) + "'");
168
- }
169
- if (col.padding) {
170
- wrapped.unshift(...new Array(col.padding[top] || 0).fill(""));
171
- wrapped.push(...new Array(col.padding[bottom] || 0).fill(""));
172
- }
173
- wrapped.forEach((str, r) => {
174
- if (!rrows[r]) {
175
- rrows.push([]);
176
- }
177
- const rrow = rrows[r];
178
- for (let i = 0;i < c; i++) {
179
- if (rrow[i] === undefined) {
180
- rrow.push("");
181
- }
182
- }
183
- rrow.push(str);
184
- });
185
- });
186
- return rrows;
187
- }
188
- negatePadding(col) {
189
- let wrapWidth = col.width || 0;
190
- if (col.padding) {
191
- wrapWidth -= (col.padding[left] || 0) + (col.padding[right] || 0);
192
- }
193
- if (col.border) {
194
- wrapWidth -= 4;
195
- }
196
- return wrapWidth;
197
- }
198
- columnWidths(row) {
199
- if (!this.wrap) {
200
- return row.map((col) => {
201
- return col.width || mixin.stringWidth(col.text);
202
- });
203
- }
204
- let unset = row.length;
205
- let remainingWidth = this.width;
206
- const widths = row.map((col) => {
207
- if (col.width) {
208
- unset--;
209
- remainingWidth -= col.width;
210
- return col.width;
211
- }
212
- return;
213
- });
214
- const unsetWidth = unset ? Math.floor(remainingWidth / unset) : 0;
215
- return widths.map((w, i) => {
216
- if (w === undefined) {
217
- return Math.max(unsetWidth, _minWidth(row[i]));
218
- }
219
- return w;
220
- });
221
- }
222
- }
223
- function addBorder(col, ts, style) {
224
- if (col.border) {
225
- if (/[.']-+[.']/.test(ts)) {
226
- return "";
227
- }
228
- if (ts.trim().length !== 0) {
229
- return style;
230
- }
231
- return " ";
232
- }
233
- return "";
234
- }
235
- function _minWidth(col) {
236
- const padding = col.padding || [];
237
- const minWidth = 1 + (padding[left] || 0) + (padding[right] || 0);
238
- if (col.border) {
239
- return minWidth + 4;
240
- }
241
- return minWidth;
242
- }
243
- function getWindowWidth() {
244
- if (typeof process === "object" && process.stdout && process.stdout.columns) {
245
- return process.stdout.columns;
246
- }
247
- return 80;
248
- }
249
- function alignRight(str, width) {
250
- str = str.trim();
251
- const strWidth = mixin.stringWidth(str);
252
- if (strWidth < width) {
253
- return " ".repeat(width - strWidth) + str;
254
- }
255
- return str;
256
- }
257
- function alignCenter(str, width) {
258
- str = str.trim();
259
- const strWidth = mixin.stringWidth(str);
260
- if (strWidth >= width) {
261
- return str;
262
- }
263
- return " ".repeat(width - strWidth >> 1) + str;
264
- }
265
- var mixin;
266
- function cliui(opts, _mixin) {
267
- mixin = _mixin;
268
- return new UI({
269
- width: (opts === null || opts === undefined ? undefined : opts.width) || getWindowWidth(),
270
- wrap: opts === null || opts === undefined ? undefined : opts.wrap
271
- });
272
- }
273
-
274
- // ../../node_modules/cliui/build/lib/string-utils.js
275
- var ansi = new RegExp("\x1B(?:\\[(?:\\d+[ABCDEFGJKSTm]|\\d+;\\d+[Hfm]|" + "\\d+;\\d+;\\d+m|6n|s|u|\\?25[lh])|\\w)", "g");
276
- function stripAnsi(str) {
277
- return str.replace(ansi, "");
278
- }
279
- function wrap(str, width) {
280
- const [start, end] = str.match(ansi) || ["", ""];
281
- str = stripAnsi(str);
282
- let wrapped = "";
283
- for (let i = 0;i < str.length; i++) {
284
- if (i !== 0 && i % width === 0) {
285
- wrapped += `
286
- `;
287
- }
288
- wrapped += str.charAt(i);
289
- }
290
- if (start && end) {
291
- wrapped = `${start}${wrapped}${end}`;
292
- }
293
- return wrapped;
294
- }
295
-
296
- // ../../node_modules/cliui/index.mjs
297
- function ui(opts) {
298
- return cliui(opts, {
299
- stringWidth: (str) => {
300
- return [...str].length;
301
- },
302
- stripAnsi,
303
- wrap
304
- });
305
- }
306
-
307
- // ../../node_modules/escalade/sync/index.mjs
308
- import { dirname, resolve } from "path";
309
- import { readdirSync, statSync } from "fs";
310
- function sync_default(start, callback) {
311
- let dir = resolve(".", start);
312
- let tmp, stats = statSync(dir);
313
- if (!stats.isDirectory()) {
314
- dir = dirname(dir);
315
- }
316
- while (true) {
317
- tmp = callback(dir, readdirSync(dir));
318
- if (tmp)
319
- return resolve(dir, tmp);
320
- dir = dirname(tmp = dir);
321
- if (tmp === dir)
322
- break;
323
- }
324
- }
325
-
326
- // ../../node_modules/yargs/lib/platform-shims/esm.mjs
327
- import { inspect } from "util";
328
- import { readFileSync as readFileSync2 } from "fs";
329
- import { fileURLToPath } from "url";
330
-
331
- // ../../node_modules/yargs-parser/build/lib/index.js
332
- import { format } from "util";
333
- import { normalize, resolve as resolve2 } from "path";
334
-
335
- // ../../node_modules/yargs-parser/build/lib/string-utils.js
336
- function camelCase(str) {
337
- const isCamelCase = str !== str.toLowerCase() && str !== str.toUpperCase();
338
- if (!isCamelCase) {
339
- str = str.toLowerCase();
340
- }
341
- if (str.indexOf("-") === -1 && str.indexOf("_") === -1) {
342
- return str;
343
- } else {
344
- let camelcase = "";
345
- let nextChrUpper = false;
346
- const leadingHyphens = str.match(/^-+/);
347
- for (let i = leadingHyphens ? leadingHyphens[0].length : 0;i < str.length; i++) {
348
- let chr = str.charAt(i);
349
- if (nextChrUpper) {
350
- nextChrUpper = false;
351
- chr = chr.toUpperCase();
352
- }
353
- if (i !== 0 && (chr === "-" || chr === "_")) {
354
- nextChrUpper = true;
355
- } else if (chr !== "-" && chr !== "_") {
356
- camelcase += chr;
357
- }
358
- }
359
- return camelcase;
360
- }
361
- }
362
- function decamelize(str, joinString) {
363
- const lowercase = str.toLowerCase();
364
- joinString = joinString || "-";
365
- let notCamelcase = "";
366
- for (let i = 0;i < str.length; i++) {
367
- const chrLower = lowercase.charAt(i);
368
- const chrString = str.charAt(i);
369
- if (chrLower !== chrString && i > 0) {
370
- notCamelcase += `${joinString}${lowercase.charAt(i)}`;
371
- } else {
372
- notCamelcase += chrString;
373
- }
374
- }
375
- return notCamelcase;
376
- }
377
- function looksLikeNumber(x) {
378
- if (x === null || x === undefined)
379
- return false;
380
- if (typeof x === "number")
381
- return true;
382
- if (/^0x[0-9a-f]+$/i.test(x))
383
- return true;
384
- if (/^0[^.]/.test(x))
385
- return false;
386
- return /^[-]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(x);
387
- }
388
-
389
- // ../../node_modules/yargs-parser/build/lib/tokenize-arg-string.js
390
- function tokenizeArgString(argString) {
391
- if (Array.isArray(argString)) {
392
- return argString.map((e) => typeof e !== "string" ? e + "" : e);
393
- }
394
- argString = argString.trim();
395
- let i = 0;
396
- let prevC = null;
397
- let c = null;
398
- let opening = null;
399
- const args = [];
400
- for (let ii = 0;ii < argString.length; ii++) {
401
- prevC = c;
402
- c = argString.charAt(ii);
403
- if (c === " " && !opening) {
404
- if (!(prevC === " ")) {
405
- i++;
406
- }
407
- continue;
408
- }
409
- if (c === opening) {
410
- opening = null;
411
- } else if ((c === "'" || c === '"') && !opening) {
412
- opening = c;
413
- }
414
- if (!args[i])
415
- args[i] = "";
416
- args[i] += c;
417
- }
418
- return args;
419
- }
420
-
421
- // ../../node_modules/yargs-parser/build/lib/yargs-parser-types.js
422
- var DefaultValuesForTypeKey;
423
- (function(DefaultValuesForTypeKey2) {
424
- DefaultValuesForTypeKey2["BOOLEAN"] = "boolean";
425
- DefaultValuesForTypeKey2["STRING"] = "string";
426
- DefaultValuesForTypeKey2["NUMBER"] = "number";
427
- DefaultValuesForTypeKey2["ARRAY"] = "array";
428
- })(DefaultValuesForTypeKey || (DefaultValuesForTypeKey = {}));
429
-
430
- // ../../node_modules/yargs-parser/build/lib/yargs-parser.js
431
- var mixin2;
432
-
433
- class YargsParser {
434
- constructor(_mixin) {
435
- mixin2 = _mixin;
436
- }
437
- parse(argsInput, options) {
438
- const opts = Object.assign({
439
- alias: undefined,
440
- array: undefined,
441
- boolean: undefined,
442
- config: undefined,
443
- configObjects: undefined,
444
- configuration: undefined,
445
- coerce: undefined,
446
- count: undefined,
447
- default: undefined,
448
- envPrefix: undefined,
449
- narg: undefined,
450
- normalize: undefined,
451
- string: undefined,
452
- number: undefined,
453
- __: undefined,
454
- key: undefined
455
- }, options);
456
- const args = tokenizeArgString(argsInput);
457
- const inputIsString = typeof argsInput === "string";
458
- const aliases = combineAliases(Object.assign(Object.create(null), opts.alias));
459
- const configuration = Object.assign({
460
- "boolean-negation": true,
461
- "camel-case-expansion": true,
462
- "combine-arrays": false,
463
- "dot-notation": true,
464
- "duplicate-arguments-array": true,
465
- "flatten-duplicate-arrays": true,
466
- "greedy-arrays": true,
467
- "halt-at-non-option": false,
468
- "nargs-eats-options": false,
469
- "negation-prefix": "no-",
470
- "parse-numbers": true,
471
- "parse-positional-numbers": true,
472
- "populate--": false,
473
- "set-placeholder-key": false,
474
- "short-option-groups": true,
475
- "strip-aliased": false,
476
- "strip-dashed": false,
477
- "unknown-options-as-args": false
478
- }, opts.configuration);
479
- const defaults = Object.assign(Object.create(null), opts.default);
480
- const configObjects = opts.configObjects || [];
481
- const envPrefix = opts.envPrefix;
482
- const notFlagsOption = configuration["populate--"];
483
- const notFlagsArgv = notFlagsOption ? "--" : "_";
484
- const newAliases = Object.create(null);
485
- const defaulted = Object.create(null);
486
- const __ = opts.__ || mixin2.format;
487
- const flags = {
488
- aliases: Object.create(null),
489
- arrays: Object.create(null),
490
- bools: Object.create(null),
491
- strings: Object.create(null),
492
- numbers: Object.create(null),
493
- counts: Object.create(null),
494
- normalize: Object.create(null),
495
- configs: Object.create(null),
496
- nargs: Object.create(null),
497
- coercions: Object.create(null),
498
- keys: []
499
- };
500
- const negative = /^-([0-9]+(\.[0-9]+)?|\.[0-9]+)$/;
501
- const negatedBoolean = new RegExp("^--" + configuration["negation-prefix"] + "(.+)");
502
- [].concat(opts.array || []).filter(Boolean).forEach(function(opt) {
503
- const key = typeof opt === "object" ? opt.key : opt;
504
- const assignment = Object.keys(opt).map(function(key2) {
505
- const arrayFlagKeys = {
506
- boolean: "bools",
507
- string: "strings",
508
- number: "numbers"
509
- };
510
- return arrayFlagKeys[key2];
511
- }).filter(Boolean).pop();
512
- if (assignment) {
513
- flags[assignment][key] = true;
514
- }
515
- flags.arrays[key] = true;
516
- flags.keys.push(key);
517
- });
518
- [].concat(opts.boolean || []).filter(Boolean).forEach(function(key) {
519
- flags.bools[key] = true;
520
- flags.keys.push(key);
521
- });
522
- [].concat(opts.string || []).filter(Boolean).forEach(function(key) {
523
- flags.strings[key] = true;
524
- flags.keys.push(key);
525
- });
526
- [].concat(opts.number || []).filter(Boolean).forEach(function(key) {
527
- flags.numbers[key] = true;
528
- flags.keys.push(key);
529
- });
530
- [].concat(opts.count || []).filter(Boolean).forEach(function(key) {
531
- flags.counts[key] = true;
532
- flags.keys.push(key);
533
- });
534
- [].concat(opts.normalize || []).filter(Boolean).forEach(function(key) {
535
- flags.normalize[key] = true;
536
- flags.keys.push(key);
537
- });
538
- if (typeof opts.narg === "object") {
539
- Object.entries(opts.narg).forEach(([key, value]) => {
540
- if (typeof value === "number") {
541
- flags.nargs[key] = value;
542
- flags.keys.push(key);
543
- }
544
- });
545
- }
546
- if (typeof opts.coerce === "object") {
547
- Object.entries(opts.coerce).forEach(([key, value]) => {
548
- if (typeof value === "function") {
549
- flags.coercions[key] = value;
550
- flags.keys.push(key);
551
- }
552
- });
553
- }
554
- if (typeof opts.config !== "undefined") {
555
- if (Array.isArray(opts.config) || typeof opts.config === "string") {
556
- [].concat(opts.config).filter(Boolean).forEach(function(key) {
557
- flags.configs[key] = true;
558
- });
559
- } else if (typeof opts.config === "object") {
560
- Object.entries(opts.config).forEach(([key, value]) => {
561
- if (typeof value === "boolean" || typeof value === "function") {
562
- flags.configs[key] = value;
563
- }
564
- });
565
- }
566
- }
567
- extendAliases(opts.key, aliases, opts.default, flags.arrays);
568
- Object.keys(defaults).forEach(function(key) {
569
- (flags.aliases[key] || []).forEach(function(alias) {
570
- defaults[alias] = defaults[key];
571
- });
572
- });
573
- let error = null;
574
- checkConfiguration();
575
- let notFlags = [];
576
- const argv = Object.assign(Object.create(null), { _: [] });
577
- const argvReturn = {};
578
- for (let i = 0;i < args.length; i++) {
579
- const arg = args[i];
580
- const truncatedArg = arg.replace(/^-{3,}/, "---");
581
- let broken;
582
- let key;
583
- let letters;
584
- let m;
585
- let next;
586
- let value;
587
- if (arg !== "--" && /^-/.test(arg) && isUnknownOptionAsArg(arg)) {
588
- pushPositional(arg);
589
- } else if (truncatedArg.match(/^---+(=|$)/)) {
590
- pushPositional(arg);
591
- continue;
592
- } else if (arg.match(/^--.+=/) || !configuration["short-option-groups"] && arg.match(/^-.+=/)) {
593
- m = arg.match(/^--?([^=]+)=([\s\S]*)$/);
594
- if (m !== null && Array.isArray(m) && m.length >= 3) {
595
- if (checkAllAliases(m[1], flags.arrays)) {
596
- i = eatArray(i, m[1], args, m[2]);
597
- } else if (checkAllAliases(m[1], flags.nargs) !== false) {
598
- i = eatNargs(i, m[1], args, m[2]);
599
- } else {
600
- setArg(m[1], m[2], true);
601
- }
602
- }
603
- } else if (arg.match(negatedBoolean) && configuration["boolean-negation"]) {
604
- m = arg.match(negatedBoolean);
605
- if (m !== null && Array.isArray(m) && m.length >= 2) {
606
- key = m[1];
607
- setArg(key, checkAllAliases(key, flags.arrays) ? [false] : false);
608
- }
609
- } else if (arg.match(/^--.+/) || !configuration["short-option-groups"] && arg.match(/^-[^-]+/)) {
610
- m = arg.match(/^--?(.+)/);
611
- if (m !== null && Array.isArray(m) && m.length >= 2) {
612
- key = m[1];
613
- if (checkAllAliases(key, flags.arrays)) {
614
- i = eatArray(i, key, args);
615
- } else if (checkAllAliases(key, flags.nargs) !== false) {
616
- i = eatNargs(i, key, args);
617
- } else {
618
- next = args[i + 1];
619
- if (next !== undefined && (!next.match(/^-/) || next.match(negative)) && !checkAllAliases(key, flags.bools) && !checkAllAliases(key, flags.counts)) {
620
- setArg(key, next);
621
- i++;
622
- } else if (/^(true|false)$/.test(next)) {
623
- setArg(key, next);
624
- i++;
625
- } else {
626
- setArg(key, defaultValue(key));
627
- }
628
- }
629
- }
630
- } else if (arg.match(/^-.\..+=/)) {
631
- m = arg.match(/^-([^=]+)=([\s\S]*)$/);
632
- if (m !== null && Array.isArray(m) && m.length >= 3) {
633
- setArg(m[1], m[2]);
634
- }
635
- } else if (arg.match(/^-.\..+/) && !arg.match(negative)) {
636
- next = args[i + 1];
637
- m = arg.match(/^-(.\..+)/);
638
- if (m !== null && Array.isArray(m) && m.length >= 2) {
639
- key = m[1];
640
- if (next !== undefined && !next.match(/^-/) && !checkAllAliases(key, flags.bools) && !checkAllAliases(key, flags.counts)) {
641
- setArg(key, next);
642
- i++;
643
- } else {
644
- setArg(key, defaultValue(key));
645
- }
646
- }
647
- } else if (arg.match(/^-[^-]+/) && !arg.match(negative)) {
648
- letters = arg.slice(1, -1).split("");
649
- broken = false;
650
- for (let j = 0;j < letters.length; j++) {
651
- next = arg.slice(j + 2);
652
- if (letters[j + 1] && letters[j + 1] === "=") {
653
- value = arg.slice(j + 3);
654
- key = letters[j];
655
- if (checkAllAliases(key, flags.arrays)) {
656
- i = eatArray(i, key, args, value);
657
- } else if (checkAllAliases(key, flags.nargs) !== false) {
658
- i = eatNargs(i, key, args, value);
659
- } else {
660
- setArg(key, value);
661
- }
662
- broken = true;
663
- break;
664
- }
665
- if (next === "-") {
666
- setArg(letters[j], next);
667
- continue;
668
- }
669
- if (/[A-Za-z]/.test(letters[j]) && /^-?\d+(\.\d*)?(e-?\d+)?$/.test(next) && checkAllAliases(next, flags.bools) === false) {
670
- setArg(letters[j], next);
671
- broken = true;
672
- break;
673
- }
674
- if (letters[j + 1] && letters[j + 1].match(/\W/)) {
675
- setArg(letters[j], next);
676
- broken = true;
677
- break;
678
- } else {
679
- setArg(letters[j], defaultValue(letters[j]));
680
- }
681
- }
682
- key = arg.slice(-1)[0];
683
- if (!broken && key !== "-") {
684
- if (checkAllAliases(key, flags.arrays)) {
685
- i = eatArray(i, key, args);
686
- } else if (checkAllAliases(key, flags.nargs) !== false) {
687
- i = eatNargs(i, key, args);
688
- } else {
689
- next = args[i + 1];
690
- if (next !== undefined && (!/^(-|--)[^-]/.test(next) || next.match(negative)) && !checkAllAliases(key, flags.bools) && !checkAllAliases(key, flags.counts)) {
691
- setArg(key, next);
692
- i++;
693
- } else if (/^(true|false)$/.test(next)) {
694
- setArg(key, next);
695
- i++;
696
- } else {
697
- setArg(key, defaultValue(key));
698
- }
699
- }
700
- }
701
- } else if (arg.match(/^-[0-9]$/) && arg.match(negative) && checkAllAliases(arg.slice(1), flags.bools)) {
702
- key = arg.slice(1);
703
- setArg(key, defaultValue(key));
704
- } else if (arg === "--") {
705
- notFlags = args.slice(i + 1);
706
- break;
707
- } else if (configuration["halt-at-non-option"]) {
708
- notFlags = args.slice(i);
709
- break;
710
- } else {
711
- pushPositional(arg);
712
- }
713
- }
714
- applyEnvVars(argv, true);
715
- applyEnvVars(argv, false);
716
- setConfig(argv);
717
- setConfigObjects();
718
- applyDefaultsAndAliases(argv, flags.aliases, defaults, true);
719
- applyCoercions(argv);
720
- if (configuration["set-placeholder-key"])
721
- setPlaceholderKeys(argv);
722
- Object.keys(flags.counts).forEach(function(key) {
723
- if (!hasKey(argv, key.split(".")))
724
- setArg(key, 0);
725
- });
726
- if (notFlagsOption && notFlags.length)
727
- argv[notFlagsArgv] = [];
728
- notFlags.forEach(function(key) {
729
- argv[notFlagsArgv].push(key);
730
- });
731
- if (configuration["camel-case-expansion"] && configuration["strip-dashed"]) {
732
- Object.keys(argv).filter((key) => key !== "--" && key.includes("-")).forEach((key) => {
733
- delete argv[key];
734
- });
735
- }
736
- if (configuration["strip-aliased"]) {
737
- [].concat(...Object.keys(aliases).map((k) => aliases[k])).forEach((alias) => {
738
- if (configuration["camel-case-expansion"] && alias.includes("-")) {
739
- delete argv[alias.split(".").map((prop) => camelCase(prop)).join(".")];
740
- }
741
- delete argv[alias];
742
- });
743
- }
744
- function pushPositional(arg) {
745
- const maybeCoercedNumber = maybeCoerceNumber("_", arg);
746
- if (typeof maybeCoercedNumber === "string" || typeof maybeCoercedNumber === "number") {
747
- argv._.push(maybeCoercedNumber);
748
- }
749
- }
750
- function eatNargs(i, key, args2, argAfterEqualSign) {
751
- let ii;
752
- let toEat = checkAllAliases(key, flags.nargs);
753
- toEat = typeof toEat !== "number" || isNaN(toEat) ? 1 : toEat;
754
- if (toEat === 0) {
755
- if (!isUndefined(argAfterEqualSign)) {
756
- error = Error(__("Argument unexpected for: %s", key));
757
- }
758
- setArg(key, defaultValue(key));
759
- return i;
760
- }
761
- let available = isUndefined(argAfterEqualSign) ? 0 : 1;
762
- if (configuration["nargs-eats-options"]) {
763
- if (args2.length - (i + 1) + available < toEat) {
764
- error = Error(__("Not enough arguments following: %s", key));
765
- }
766
- available = toEat;
767
- } else {
768
- for (ii = i + 1;ii < args2.length; ii++) {
769
- if (!args2[ii].match(/^-[^0-9]/) || args2[ii].match(negative) || isUnknownOptionAsArg(args2[ii]))
770
- available++;
771
- else
772
- break;
773
- }
774
- if (available < toEat)
775
- error = Error(__("Not enough arguments following: %s", key));
776
- }
777
- let consumed = Math.min(available, toEat);
778
- if (!isUndefined(argAfterEqualSign) && consumed > 0) {
779
- setArg(key, argAfterEqualSign);
780
- consumed--;
781
- }
782
- for (ii = i + 1;ii < consumed + i + 1; ii++) {
783
- setArg(key, args2[ii]);
784
- }
785
- return i + consumed;
786
- }
787
- function eatArray(i, key, args2, argAfterEqualSign) {
788
- let argsToSet = [];
789
- let next = argAfterEqualSign || args2[i + 1];
790
- const nargsCount = checkAllAliases(key, flags.nargs);
791
- if (checkAllAliases(key, flags.bools) && !/^(true|false)$/.test(next)) {
792
- argsToSet.push(true);
793
- } else if (isUndefined(next) || isUndefined(argAfterEqualSign) && /^-/.test(next) && !negative.test(next) && !isUnknownOptionAsArg(next)) {
794
- if (defaults[key] !== undefined) {
795
- const defVal = defaults[key];
796
- argsToSet = Array.isArray(defVal) ? defVal : [defVal];
797
- }
798
- } else {
799
- if (!isUndefined(argAfterEqualSign)) {
800
- argsToSet.push(processValue(key, argAfterEqualSign, true));
801
- }
802
- for (let ii = i + 1;ii < args2.length; ii++) {
803
- if (!configuration["greedy-arrays"] && argsToSet.length > 0 || nargsCount && typeof nargsCount === "number" && argsToSet.length >= nargsCount)
804
- break;
805
- next = args2[ii];
806
- if (/^-/.test(next) && !negative.test(next) && !isUnknownOptionAsArg(next))
807
- break;
808
- i = ii;
809
- argsToSet.push(processValue(key, next, inputIsString));
810
- }
811
- }
812
- if (typeof nargsCount === "number" && (nargsCount && argsToSet.length < nargsCount || isNaN(nargsCount) && argsToSet.length === 0)) {
813
- error = Error(__("Not enough arguments following: %s", key));
814
- }
815
- setArg(key, argsToSet);
816
- return i;
817
- }
818
- function setArg(key, val, shouldStripQuotes = inputIsString) {
819
- if (/-/.test(key) && configuration["camel-case-expansion"]) {
820
- const alias = key.split(".").map(function(prop) {
821
- return camelCase(prop);
822
- }).join(".");
823
- addNewAlias(key, alias);
824
- }
825
- const value = processValue(key, val, shouldStripQuotes);
826
- const splitKey = key.split(".");
827
- setKey(argv, splitKey, value);
828
- if (flags.aliases[key]) {
829
- flags.aliases[key].forEach(function(x) {
830
- const keyProperties = x.split(".");
831
- setKey(argv, keyProperties, value);
832
- });
833
- }
834
- if (splitKey.length > 1 && configuration["dot-notation"]) {
835
- (flags.aliases[splitKey[0]] || []).forEach(function(x) {
836
- let keyProperties = x.split(".");
837
- const a = [].concat(splitKey);
838
- a.shift();
839
- keyProperties = keyProperties.concat(a);
840
- if (!(flags.aliases[key] || []).includes(keyProperties.join("."))) {
841
- setKey(argv, keyProperties, value);
842
- }
843
- });
844
- }
845
- if (checkAllAliases(key, flags.normalize) && !checkAllAliases(key, flags.arrays)) {
846
- const keys = [key].concat(flags.aliases[key] || []);
847
- keys.forEach(function(key2) {
848
- Object.defineProperty(argvReturn, key2, {
849
- enumerable: true,
850
- get() {
851
- return val;
852
- },
853
- set(value2) {
854
- val = typeof value2 === "string" ? mixin2.normalize(value2) : value2;
855
- }
856
- });
857
- });
858
- }
859
- }
860
- function addNewAlias(key, alias) {
861
- if (!(flags.aliases[key] && flags.aliases[key].length)) {
862
- flags.aliases[key] = [alias];
863
- newAliases[alias] = true;
864
- }
865
- if (!(flags.aliases[alias] && flags.aliases[alias].length)) {
866
- addNewAlias(alias, key);
867
- }
868
- }
869
- function processValue(key, val, shouldStripQuotes) {
870
- if (shouldStripQuotes) {
871
- val = stripQuotes(val);
872
- }
873
- if (checkAllAliases(key, flags.bools) || checkAllAliases(key, flags.counts)) {
874
- if (typeof val === "string")
875
- val = val === "true";
876
- }
877
- let value = Array.isArray(val) ? val.map(function(v) {
878
- return maybeCoerceNumber(key, v);
879
- }) : maybeCoerceNumber(key, val);
880
- if (checkAllAliases(key, flags.counts) && (isUndefined(value) || typeof value === "boolean")) {
881
- value = increment();
882
- }
883
- if (checkAllAliases(key, flags.normalize) && checkAllAliases(key, flags.arrays)) {
884
- if (Array.isArray(val))
885
- value = val.map((val2) => {
886
- return mixin2.normalize(val2);
887
- });
888
- else
889
- value = mixin2.normalize(val);
890
- }
891
- return value;
892
- }
893
- function maybeCoerceNumber(key, value) {
894
- if (!configuration["parse-positional-numbers"] && key === "_")
895
- return value;
896
- if (!checkAllAliases(key, flags.strings) && !checkAllAliases(key, flags.bools) && !Array.isArray(value)) {
897
- const shouldCoerceNumber = looksLikeNumber(value) && configuration["parse-numbers"] && Number.isSafeInteger(Math.floor(parseFloat(`${value}`)));
898
- if (shouldCoerceNumber || !isUndefined(value) && checkAllAliases(key, flags.numbers)) {
899
- value = Number(value);
900
- }
901
- }
902
- return value;
903
- }
904
- function setConfig(argv2) {
905
- const configLookup = Object.create(null);
906
- applyDefaultsAndAliases(configLookup, flags.aliases, defaults);
907
- Object.keys(flags.configs).forEach(function(configKey) {
908
- const configPath = argv2[configKey] || configLookup[configKey];
909
- if (configPath) {
910
- try {
911
- let config = null;
912
- const resolvedConfigPath = mixin2.resolve(mixin2.cwd(), configPath);
913
- const resolveConfig = flags.configs[configKey];
914
- if (typeof resolveConfig === "function") {
915
- try {
916
- config = resolveConfig(resolvedConfigPath);
917
- } catch (e) {
918
- config = e;
919
- }
920
- if (config instanceof Error) {
921
- error = config;
922
- return;
923
- }
924
- } else {
925
- config = mixin2.require(resolvedConfigPath);
926
- }
927
- setConfigObject(config);
928
- } catch (ex) {
929
- if (ex.name === "PermissionDenied")
930
- error = ex;
931
- else if (argv2[configKey])
932
- error = Error(__("Invalid JSON config file: %s", configPath));
933
- }
934
- }
935
- });
936
- }
937
- function setConfigObject(config, prev) {
938
- Object.keys(config).forEach(function(key) {
939
- const value = config[key];
940
- const fullKey = prev ? prev + "." + key : key;
941
- if (typeof value === "object" && value !== null && !Array.isArray(value) && configuration["dot-notation"]) {
942
- setConfigObject(value, fullKey);
943
- } else {
944
- if (!hasKey(argv, fullKey.split(".")) || checkAllAliases(fullKey, flags.arrays) && configuration["combine-arrays"]) {
945
- setArg(fullKey, value);
946
- }
947
- }
948
- });
949
- }
950
- function setConfigObjects() {
951
- if (typeof configObjects !== "undefined") {
952
- configObjects.forEach(function(configObject) {
953
- setConfigObject(configObject);
954
- });
955
- }
956
- }
957
- function applyEnvVars(argv2, configOnly) {
958
- if (typeof envPrefix === "undefined")
959
- return;
960
- const prefix = typeof envPrefix === "string" ? envPrefix : "";
961
- const env = mixin2.env();
962
- Object.keys(env).forEach(function(envVar) {
963
- if (prefix === "" || envVar.lastIndexOf(prefix, 0) === 0) {
964
- const keys = envVar.split("__").map(function(key, i) {
965
- if (i === 0) {
966
- key = key.substring(prefix.length);
967
- }
968
- return camelCase(key);
969
- });
970
- if ((configOnly && flags.configs[keys.join(".")] || !configOnly) && !hasKey(argv2, keys)) {
971
- setArg(keys.join("."), env[envVar]);
972
- }
973
- }
974
- });
975
- }
976
- function applyCoercions(argv2) {
977
- let coerce;
978
- const applied = new Set;
979
- Object.keys(argv2).forEach(function(key) {
980
- if (!applied.has(key)) {
981
- coerce = checkAllAliases(key, flags.coercions);
982
- if (typeof coerce === "function") {
983
- try {
984
- const value = maybeCoerceNumber(key, coerce(argv2[key]));
985
- [].concat(flags.aliases[key] || [], key).forEach((ali) => {
986
- applied.add(ali);
987
- argv2[ali] = value;
988
- });
989
- } catch (err) {
990
- error = err;
991
- }
992
- }
993
- }
994
- });
995
- }
996
- function setPlaceholderKeys(argv2) {
997
- flags.keys.forEach((key) => {
998
- if (~key.indexOf("."))
999
- return;
1000
- if (typeof argv2[key] === "undefined")
1001
- argv2[key] = undefined;
1002
- });
1003
- return argv2;
1004
- }
1005
- function applyDefaultsAndAliases(obj, aliases2, defaults2, canLog = false) {
1006
- Object.keys(defaults2).forEach(function(key) {
1007
- if (!hasKey(obj, key.split("."))) {
1008
- setKey(obj, key.split("."), defaults2[key]);
1009
- if (canLog)
1010
- defaulted[key] = true;
1011
- (aliases2[key] || []).forEach(function(x) {
1012
- if (hasKey(obj, x.split(".")))
1013
- return;
1014
- setKey(obj, x.split("."), defaults2[key]);
1015
- });
1016
- }
1017
- });
1018
- }
1019
- function hasKey(obj, keys) {
1020
- let o = obj;
1021
- if (!configuration["dot-notation"])
1022
- keys = [keys.join(".")];
1023
- keys.slice(0, -1).forEach(function(key2) {
1024
- o = o[key2] || {};
1025
- });
1026
- const key = keys[keys.length - 1];
1027
- if (typeof o !== "object")
1028
- return false;
1029
- else
1030
- return key in o;
1031
- }
1032
- function setKey(obj, keys, value) {
1033
- let o = obj;
1034
- if (!configuration["dot-notation"])
1035
- keys = [keys.join(".")];
1036
- keys.slice(0, -1).forEach(function(key2) {
1037
- key2 = sanitizeKey(key2);
1038
- if (typeof o === "object" && o[key2] === undefined) {
1039
- o[key2] = {};
1040
- }
1041
- if (typeof o[key2] !== "object" || Array.isArray(o[key2])) {
1042
- if (Array.isArray(o[key2])) {
1043
- o[key2].push({});
1044
- } else {
1045
- o[key2] = [o[key2], {}];
1046
- }
1047
- o = o[key2][o[key2].length - 1];
1048
- } else {
1049
- o = o[key2];
1050
- }
1051
- });
1052
- const key = sanitizeKey(keys[keys.length - 1]);
1053
- const isTypeArray = checkAllAliases(keys.join("."), flags.arrays);
1054
- const isValueArray = Array.isArray(value);
1055
- let duplicate = configuration["duplicate-arguments-array"];
1056
- if (!duplicate && checkAllAliases(key, flags.nargs)) {
1057
- duplicate = true;
1058
- if (!isUndefined(o[key]) && flags.nargs[key] === 1 || Array.isArray(o[key]) && o[key].length === flags.nargs[key]) {
1059
- o[key] = undefined;
1060
- }
1061
- }
1062
- if (value === increment()) {
1063
- o[key] = increment(o[key]);
1064
- } else if (Array.isArray(o[key])) {
1065
- if (duplicate && isTypeArray && isValueArray) {
1066
- o[key] = configuration["flatten-duplicate-arrays"] ? o[key].concat(value) : (Array.isArray(o[key][0]) ? o[key] : [o[key]]).concat([value]);
1067
- } else if (!duplicate && Boolean(isTypeArray) === Boolean(isValueArray)) {
1068
- o[key] = value;
1069
- } else {
1070
- o[key] = o[key].concat([value]);
1071
- }
1072
- } else if (o[key] === undefined && isTypeArray) {
1073
- o[key] = isValueArray ? value : [value];
1074
- } else if (duplicate && !(o[key] === undefined || checkAllAliases(key, flags.counts) || checkAllAliases(key, flags.bools))) {
1075
- o[key] = [o[key], value];
1076
- } else {
1077
- o[key] = value;
1078
- }
1079
- }
1080
- function extendAliases(...args2) {
1081
- args2.forEach(function(obj) {
1082
- Object.keys(obj || {}).forEach(function(key) {
1083
- if (flags.aliases[key])
1084
- return;
1085
- flags.aliases[key] = [].concat(aliases[key] || []);
1086
- flags.aliases[key].concat(key).forEach(function(x) {
1087
- if (/-/.test(x) && configuration["camel-case-expansion"]) {
1088
- const c = camelCase(x);
1089
- if (c !== key && flags.aliases[key].indexOf(c) === -1) {
1090
- flags.aliases[key].push(c);
1091
- newAliases[c] = true;
1092
- }
1093
- }
1094
- });
1095
- flags.aliases[key].concat(key).forEach(function(x) {
1096
- if (x.length > 1 && /[A-Z]/.test(x) && configuration["camel-case-expansion"]) {
1097
- const c = decamelize(x, "-");
1098
- if (c !== key && flags.aliases[key].indexOf(c) === -1) {
1099
- flags.aliases[key].push(c);
1100
- newAliases[c] = true;
1101
- }
1102
- }
1103
- });
1104
- flags.aliases[key].forEach(function(x) {
1105
- flags.aliases[x] = [key].concat(flags.aliases[key].filter(function(y) {
1106
- return x !== y;
1107
- }));
1108
- });
1109
- });
1110
- });
1111
- }
1112
- function checkAllAliases(key, flag) {
1113
- const toCheck = [].concat(flags.aliases[key] || [], key);
1114
- const keys = Object.keys(flag);
1115
- const setAlias = toCheck.find((key2) => keys.includes(key2));
1116
- return setAlias ? flag[setAlias] : false;
1117
- }
1118
- function hasAnyFlag(key) {
1119
- const flagsKeys = Object.keys(flags);
1120
- const toCheck = [].concat(flagsKeys.map((k) => flags[k]));
1121
- return toCheck.some(function(flag) {
1122
- return Array.isArray(flag) ? flag.includes(key) : flag[key];
1123
- });
1124
- }
1125
- function hasFlagsMatching(arg, ...patterns) {
1126
- const toCheck = [].concat(...patterns);
1127
- return toCheck.some(function(pattern) {
1128
- const match = arg.match(pattern);
1129
- return match && hasAnyFlag(match[1]);
1130
- });
1131
- }
1132
- function hasAllShortFlags(arg) {
1133
- if (arg.match(negative) || !arg.match(/^-[^-]+/)) {
1134
- return false;
1135
- }
1136
- let hasAllFlags = true;
1137
- let next;
1138
- const letters = arg.slice(1).split("");
1139
- for (let j = 0;j < letters.length; j++) {
1140
- next = arg.slice(j + 2);
1141
- if (!hasAnyFlag(letters[j])) {
1142
- hasAllFlags = false;
1143
- break;
1144
- }
1145
- if (letters[j + 1] && letters[j + 1] === "=" || next === "-" || /[A-Za-z]/.test(letters[j]) && /^-?\d+(\.\d*)?(e-?\d+)?$/.test(next) || letters[j + 1] && letters[j + 1].match(/\W/)) {
1146
- break;
1147
- }
1148
- }
1149
- return hasAllFlags;
1150
- }
1151
- function isUnknownOptionAsArg(arg) {
1152
- return configuration["unknown-options-as-args"] && isUnknownOption(arg);
1153
- }
1154
- function isUnknownOption(arg) {
1155
- arg = arg.replace(/^-{3,}/, "--");
1156
- if (arg.match(negative)) {
1157
- return false;
1158
- }
1159
- if (hasAllShortFlags(arg)) {
1160
- return false;
1161
- }
1162
- const flagWithEquals = /^-+([^=]+?)=[\s\S]*$/;
1163
- const normalFlag = /^-+([^=]+?)$/;
1164
- const flagEndingInHyphen = /^-+([^=]+?)-$/;
1165
- const flagEndingInDigits = /^-+([^=]+?\d+)$/;
1166
- const flagEndingInNonWordCharacters = /^-+([^=]+?)\W+.*$/;
1167
- return !hasFlagsMatching(arg, flagWithEquals, negatedBoolean, normalFlag, flagEndingInHyphen, flagEndingInDigits, flagEndingInNonWordCharacters);
1168
- }
1169
- function defaultValue(key) {
1170
- if (!checkAllAliases(key, flags.bools) && !checkAllAliases(key, flags.counts) && `${key}` in defaults) {
1171
- return defaults[key];
1172
- } else {
1173
- return defaultForType(guessType(key));
1174
- }
1175
- }
1176
- function defaultForType(type) {
1177
- const def = {
1178
- [DefaultValuesForTypeKey.BOOLEAN]: true,
1179
- [DefaultValuesForTypeKey.STRING]: "",
1180
- [DefaultValuesForTypeKey.NUMBER]: undefined,
1181
- [DefaultValuesForTypeKey.ARRAY]: []
1182
- };
1183
- return def[type];
1184
- }
1185
- function guessType(key) {
1186
- let type = DefaultValuesForTypeKey.BOOLEAN;
1187
- if (checkAllAliases(key, flags.strings))
1188
- type = DefaultValuesForTypeKey.STRING;
1189
- else if (checkAllAliases(key, flags.numbers))
1190
- type = DefaultValuesForTypeKey.NUMBER;
1191
- else if (checkAllAliases(key, flags.bools))
1192
- type = DefaultValuesForTypeKey.BOOLEAN;
1193
- else if (checkAllAliases(key, flags.arrays))
1194
- type = DefaultValuesForTypeKey.ARRAY;
1195
- return type;
1196
- }
1197
- function isUndefined(num) {
1198
- return num === undefined;
1199
- }
1200
- function checkConfiguration() {
1201
- Object.keys(flags.counts).find((key) => {
1202
- if (checkAllAliases(key, flags.arrays)) {
1203
- error = Error(__("Invalid configuration: %s, opts.count excludes opts.array.", key));
1204
- return true;
1205
- } else if (checkAllAliases(key, flags.nargs)) {
1206
- error = Error(__("Invalid configuration: %s, opts.count excludes opts.narg.", key));
1207
- return true;
1208
- }
1209
- return false;
1210
- });
1211
- }
1212
- return {
1213
- aliases: Object.assign({}, flags.aliases),
1214
- argv: Object.assign(argvReturn, argv),
1215
- configuration,
1216
- defaulted: Object.assign({}, defaulted),
1217
- error,
1218
- newAliases: Object.assign({}, newAliases)
1219
- };
1220
- }
1221
- }
1222
- function combineAliases(aliases) {
1223
- const aliasArrays = [];
1224
- const combined = Object.create(null);
1225
- let change = true;
1226
- Object.keys(aliases).forEach(function(key) {
1227
- aliasArrays.push([].concat(aliases[key], key));
1228
- });
1229
- while (change) {
1230
- change = false;
1231
- for (let i = 0;i < aliasArrays.length; i++) {
1232
- for (let ii = i + 1;ii < aliasArrays.length; ii++) {
1233
- const intersect = aliasArrays[i].filter(function(v) {
1234
- return aliasArrays[ii].indexOf(v) !== -1;
1235
- });
1236
- if (intersect.length) {
1237
- aliasArrays[i] = aliasArrays[i].concat(aliasArrays[ii]);
1238
- aliasArrays.splice(ii, 1);
1239
- change = true;
1240
- break;
1241
- }
1242
- }
1243
- }
1244
- }
1245
- aliasArrays.forEach(function(aliasArray) {
1246
- aliasArray = aliasArray.filter(function(v, i, self) {
1247
- return self.indexOf(v) === i;
1248
- });
1249
- const lastAlias = aliasArray.pop();
1250
- if (lastAlias !== undefined && typeof lastAlias === "string") {
1251
- combined[lastAlias] = aliasArray;
1252
- }
1253
- });
1254
- return combined;
1255
- }
1256
- function increment(orig) {
1257
- return orig !== undefined ? orig + 1 : 1;
1258
- }
1259
- function sanitizeKey(key) {
1260
- if (key === "__proto__")
1261
- return "___proto___";
1262
- return key;
1263
- }
1264
- function stripQuotes(val) {
1265
- return typeof val === "string" && (val[0] === "'" || val[0] === '"') && val[val.length - 1] === val[0] ? val.substring(1, val.length - 1) : val;
1266
- }
1267
-
1268
- // ../../node_modules/yargs-parser/build/lib/index.js
1269
- var _a;
1270
- var _b;
1271
- var _c;
1272
- var minNodeVersion = process && process.env && process.env.YARGS_MIN_NODE_VERSION ? Number(process.env.YARGS_MIN_NODE_VERSION) : 12;
1273
- var nodeVersion = (_b = (_a = process === null || process === undefined ? undefined : process.versions) === null || _a === undefined ? undefined : _a.node) !== null && _b !== undefined ? _b : (_c = process === null || process === undefined ? undefined : process.version) === null || _c === undefined ? undefined : _c.slice(1);
1274
- if (nodeVersion) {
1275
- const major = Number(nodeVersion.match(/^([^.]+)/)[1]);
1276
- if (major < minNodeVersion) {
1277
- throw Error(`yargs parser supports a minimum Node.js version of ${minNodeVersion}. Read our version support policy: https://github.com/yargs/yargs-parser#supported-nodejs-versions`);
1278
- }
1279
- }
1280
- var env = process ? process.env : {};
1281
- var parser = new YargsParser({
1282
- cwd: process.cwd,
1283
- env: () => {
1284
- return env;
1285
- },
1286
- format,
1287
- normalize,
1288
- resolve: resolve2,
1289
- require: (path) => {
1290
- if (true) {
1291
- return __require(path);
1292
- } else
1293
- ;
1294
- }
1295
- });
1296
- var yargsParser = function Parser(args, opts) {
1297
- const result = parser.parse(args.slice(), opts);
1298
- return result.argv;
1299
- };
1300
- yargsParser.detailed = function(args, opts) {
1301
- return parser.parse(args.slice(), opts);
1302
- };
1303
- yargsParser.camelCase = camelCase;
1304
- yargsParser.decamelize = decamelize;
1305
- yargsParser.looksLikeNumber = looksLikeNumber;
1306
- var lib_default = yargsParser;
1307
-
1308
- // ../../node_modules/yargs/lib/platform-shims/esm.mjs
1309
- import { basename, dirname as dirname2, extname, relative, resolve as resolve4 } from "path";
1310
-
1311
- // ../../node_modules/yargs/build/lib/utils/process-argv.js
1312
- function getProcessArgvBinIndex() {
1313
- if (isBundledElectronApp())
1314
- return 0;
1315
- return 1;
1316
- }
1317
- function isBundledElectronApp() {
1318
- return isElectronApp() && !process.defaultApp;
1319
- }
1320
- function isElectronApp() {
1321
- return !!process.versions.electron;
1322
- }
1323
- function hideBin(argv) {
1324
- return argv.slice(getProcessArgvBinIndex() + 1);
1325
- }
1326
- function getProcessArgvBin() {
1327
- return process.argv[getProcessArgvBinIndex()];
1328
- }
1329
-
1330
- // ../../node_modules/yargs/build/lib/yerror.js
1331
- class YError extends Error {
1332
- constructor(msg) {
1333
- super(msg || "yargs error");
1334
- this.name = "YError";
1335
- if (Error.captureStackTrace) {
1336
- Error.captureStackTrace(this, YError);
1337
- }
1338
- }
1339
- }
1340
-
1341
- // ../../node_modules/y18n/build/lib/platform-shims/node.js
1342
- import { readFileSync, statSync as statSync2, writeFile } from "fs";
1343
- import { format as format2 } from "util";
1344
- import { resolve as resolve3 } from "path";
1345
- var node_default = {
1346
- fs: {
1347
- readFileSync,
1348
- writeFile
1349
- },
1350
- format: format2,
1351
- resolve: resolve3,
1352
- exists: (file) => {
1353
- try {
1354
- return statSync2(file).isFile();
1355
- } catch (err) {
1356
- return false;
1357
- }
1358
- }
1359
- };
1360
-
1361
- // ../../node_modules/y18n/build/lib/index.js
1362
- var shim;
1363
-
1364
- class Y18N {
1365
- constructor(opts) {
1366
- opts = opts || {};
1367
- this.directory = opts.directory || "./locales";
1368
- this.updateFiles = typeof opts.updateFiles === "boolean" ? opts.updateFiles : true;
1369
- this.locale = opts.locale || "en";
1370
- this.fallbackToLanguage = typeof opts.fallbackToLanguage === "boolean" ? opts.fallbackToLanguage : true;
1371
- this.cache = Object.create(null);
1372
- this.writeQueue = [];
1373
- }
1374
- __(...args) {
1375
- if (typeof arguments[0] !== "string") {
1376
- return this._taggedLiteral(arguments[0], ...arguments);
1377
- }
1378
- const str = args.shift();
1379
- let cb = function() {
1380
- };
1381
- if (typeof args[args.length - 1] === "function")
1382
- cb = args.pop();
1383
- cb = cb || function() {
1384
- };
1385
- if (!this.cache[this.locale])
1386
- this._readLocaleFile();
1387
- if (!this.cache[this.locale][str] && this.updateFiles) {
1388
- this.cache[this.locale][str] = str;
1389
- this._enqueueWrite({
1390
- directory: this.directory,
1391
- locale: this.locale,
1392
- cb
1393
- });
1394
- } else {
1395
- cb();
1396
- }
1397
- return shim.format.apply(shim.format, [this.cache[this.locale][str] || str].concat(args));
1398
- }
1399
- __n() {
1400
- const args = Array.prototype.slice.call(arguments);
1401
- const singular = args.shift();
1402
- const plural = args.shift();
1403
- const quantity = args.shift();
1404
- let cb = function() {
1405
- };
1406
- if (typeof args[args.length - 1] === "function")
1407
- cb = args.pop();
1408
- if (!this.cache[this.locale])
1409
- this._readLocaleFile();
1410
- let str = quantity === 1 ? singular : plural;
1411
- if (this.cache[this.locale][singular]) {
1412
- const entry = this.cache[this.locale][singular];
1413
- str = entry[quantity === 1 ? "one" : "other"];
1414
- }
1415
- if (!this.cache[this.locale][singular] && this.updateFiles) {
1416
- this.cache[this.locale][singular] = {
1417
- one: singular,
1418
- other: plural
1419
- };
1420
- this._enqueueWrite({
1421
- directory: this.directory,
1422
- locale: this.locale,
1423
- cb
1424
- });
1425
- } else {
1426
- cb();
1427
- }
1428
- const values = [str];
1429
- if (~str.indexOf("%d"))
1430
- values.push(quantity);
1431
- return shim.format.apply(shim.format, values.concat(args));
1432
- }
1433
- setLocale(locale) {
1434
- this.locale = locale;
1435
- }
1436
- getLocale() {
1437
- return this.locale;
1438
- }
1439
- updateLocale(obj) {
1440
- if (!this.cache[this.locale])
1441
- this._readLocaleFile();
1442
- for (const key in obj) {
1443
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
1444
- this.cache[this.locale][key] = obj[key];
1445
- }
1446
- }
1447
- }
1448
- _taggedLiteral(parts, ...args) {
1449
- let str = "";
1450
- parts.forEach(function(part, i) {
1451
- const arg = args[i + 1];
1452
- str += part;
1453
- if (typeof arg !== "undefined") {
1454
- str += "%s";
1455
- }
1456
- });
1457
- return this.__.apply(this, [str].concat([].slice.call(args, 1)));
1458
- }
1459
- _enqueueWrite(work) {
1460
- this.writeQueue.push(work);
1461
- if (this.writeQueue.length === 1)
1462
- this._processWriteQueue();
1463
- }
1464
- _processWriteQueue() {
1465
- const _this = this;
1466
- const work = this.writeQueue[0];
1467
- const directory = work.directory;
1468
- const locale = work.locale;
1469
- const cb = work.cb;
1470
- const languageFile = this._resolveLocaleFile(directory, locale);
1471
- const serializedLocale = JSON.stringify(this.cache[locale], null, 2);
1472
- shim.fs.writeFile(languageFile, serializedLocale, "utf-8", function(err) {
1473
- _this.writeQueue.shift();
1474
- if (_this.writeQueue.length > 0)
1475
- _this._processWriteQueue();
1476
- cb(err);
1477
- });
1478
- }
1479
- _readLocaleFile() {
1480
- let localeLookup = {};
1481
- const languageFile = this._resolveLocaleFile(this.directory, this.locale);
1482
- try {
1483
- if (shim.fs.readFileSync) {
1484
- localeLookup = JSON.parse(shim.fs.readFileSync(languageFile, "utf-8"));
1485
- }
1486
- } catch (err) {
1487
- if (err instanceof SyntaxError) {
1488
- err.message = "syntax error in " + languageFile;
1489
- }
1490
- if (err.code === "ENOENT")
1491
- localeLookup = {};
1492
- else
1493
- throw err;
1494
- }
1495
- this.cache[this.locale] = localeLookup;
1496
- }
1497
- _resolveLocaleFile(directory, locale) {
1498
- let file = shim.resolve(directory, "./", locale + ".json");
1499
- if (this.fallbackToLanguage && !this._fileExistsSync(file) && ~locale.lastIndexOf("_")) {
1500
- const languageFile = shim.resolve(directory, "./", locale.split("_")[0] + ".json");
1501
- if (this._fileExistsSync(languageFile))
1502
- file = languageFile;
1503
- }
1504
- return file;
1505
- }
1506
- _fileExistsSync(file) {
1507
- return shim.exists(file);
1508
- }
1509
- }
1510
- function y18n(opts, _shim) {
1511
- shim = _shim;
1512
- const y18n2 = new Y18N(opts);
1513
- return {
1514
- __: y18n2.__.bind(y18n2),
1515
- __n: y18n2.__n.bind(y18n2),
1516
- setLocale: y18n2.setLocale.bind(y18n2),
1517
- getLocale: y18n2.getLocale.bind(y18n2),
1518
- updateLocale: y18n2.updateLocale.bind(y18n2),
1519
- locale: y18n2.locale
1520
- };
1521
- }
1522
-
1523
- // ../../node_modules/y18n/index.mjs
1524
- var y18n2 = (opts) => {
1525
- return y18n(opts, node_default);
1526
- };
1527
- var y18n_default = y18n2;
1528
-
1529
- // ../../node_modules/yargs/lib/platform-shims/esm.mjs
1530
- var REQUIRE_ERROR = "require is not supported by ESM";
1531
- var REQUIRE_DIRECTORY_ERROR = "loading a directory of commands is not supported yet for ESM";
1532
- var __dirname2;
1533
- try {
1534
- __dirname2 = fileURLToPath(import.meta.url);
1535
- } catch (e) {
1536
- __dirname2 = process.cwd();
1537
- }
1538
- var mainFilename = __dirname2.substring(0, __dirname2.lastIndexOf("node_modules"));
1539
- var esm_default = {
1540
- assert: {
1541
- notStrictEqual,
1542
- strictEqual
1543
- },
1544
- cliui: ui,
1545
- findUp: sync_default,
1546
- getEnv: (key) => {
1547
- return process.env[key];
1548
- },
1549
- inspect,
1550
- getCallerFile: () => {
1551
- throw new YError(REQUIRE_DIRECTORY_ERROR);
1552
- },
1553
- getProcessArgvBin,
1554
- mainFilename: mainFilename || process.cwd(),
1555
- Parser: lib_default,
1556
- path: {
1557
- basename,
1558
- dirname: dirname2,
1559
- extname,
1560
- relative,
1561
- resolve: resolve4
1562
- },
1563
- process: {
1564
- argv: () => process.argv,
1565
- cwd: process.cwd,
1566
- emitWarning: (warning, type) => process.emitWarning(warning, type),
1567
- execPath: () => process.execPath,
1568
- exit: process.exit,
1569
- nextTick: process.nextTick,
1570
- stdColumns: typeof process.stdout.columns !== "undefined" ? process.stdout.columns : null
1571
- },
1572
- readFileSync: readFileSync2,
1573
- require: () => {
1574
- throw new YError(REQUIRE_ERROR);
1575
- },
1576
- requireDirectory: () => {
1577
- throw new YError(REQUIRE_DIRECTORY_ERROR);
1578
- },
1579
- stringWidth: (str) => {
1580
- return [...str].length;
1581
- },
1582
- y18n: y18n_default({
1583
- directory: resolve4(__dirname2, "../../../locales"),
1584
- updateFiles: false
1585
- })
1586
- };
1587
-
1588
- // ../../node_modules/yargs/build/lib/typings/common-types.js
1589
- function assertNotStrictEqual(actual, expected, shim2, message) {
1590
- shim2.assert.notStrictEqual(actual, expected, message);
1591
- }
1592
- function assertSingleKey(actual, shim2) {
1593
- shim2.assert.strictEqual(typeof actual, "string");
1594
- }
1595
- function objectKeys(object) {
1596
- return Object.keys(object);
1597
- }
1598
-
1599
- // ../../node_modules/yargs/build/lib/utils/is-promise.js
1600
- function isPromise(maybePromise) {
1601
- return !!maybePromise && !!maybePromise.then && typeof maybePromise.then === "function";
1602
- }
1603
-
1604
- // ../../node_modules/yargs/build/lib/parse-command.js
1605
- function parseCommand(cmd) {
1606
- const extraSpacesStrippedCommand = cmd.replace(/\s{2,}/g, " ");
1607
- const splitCommand = extraSpacesStrippedCommand.split(/\s+(?![^[]*]|[^<]*>)/);
1608
- const bregex = /\.*[\][<>]/g;
1609
- const firstCommand = splitCommand.shift();
1610
- if (!firstCommand)
1611
- throw new Error(`No command found in: ${cmd}`);
1612
- const parsedCommand = {
1613
- cmd: firstCommand.replace(bregex, ""),
1614
- demanded: [],
1615
- optional: []
1616
- };
1617
- splitCommand.forEach((cmd2, i) => {
1618
- let variadic = false;
1619
- cmd2 = cmd2.replace(/\s/g, "");
1620
- if (/\.+[\]>]/.test(cmd2) && i === splitCommand.length - 1)
1621
- variadic = true;
1622
- if (/^\[/.test(cmd2)) {
1623
- parsedCommand.optional.push({
1624
- cmd: cmd2.replace(bregex, "").split("|"),
1625
- variadic
1626
- });
1627
- } else {
1628
- parsedCommand.demanded.push({
1629
- cmd: cmd2.replace(bregex, "").split("|"),
1630
- variadic
1631
- });
1632
- }
1633
- });
1634
- return parsedCommand;
1635
- }
1636
-
1637
- // ../../node_modules/yargs/build/lib/argsert.js
1638
- var positionName = ["first", "second", "third", "fourth", "fifth", "sixth"];
1639
- function argsert(arg1, arg2, arg3) {
1640
- function parseArgs() {
1641
- return typeof arg1 === "object" ? [{ demanded: [], optional: [] }, arg1, arg2] : [
1642
- parseCommand(`cmd ${arg1}`),
1643
- arg2,
1644
- arg3
1645
- ];
1646
- }
1647
- try {
1648
- let position = 0;
1649
- const [parsed, callerArguments, _length] = parseArgs();
1650
- const args = [].slice.call(callerArguments);
1651
- while (args.length && args[args.length - 1] === undefined)
1652
- args.pop();
1653
- const length = _length || args.length;
1654
- if (length < parsed.demanded.length) {
1655
- throw new YError(`Not enough arguments provided. Expected ${parsed.demanded.length} but received ${args.length}.`);
1656
- }
1657
- const totalCommands = parsed.demanded.length + parsed.optional.length;
1658
- if (length > totalCommands) {
1659
- throw new YError(`Too many arguments provided. Expected max ${totalCommands} but received ${length}.`);
1660
- }
1661
- parsed.demanded.forEach((demanded) => {
1662
- const arg = args.shift();
1663
- const observedType = guessType(arg);
1664
- const matchingTypes = demanded.cmd.filter((type) => type === observedType || type === "*");
1665
- if (matchingTypes.length === 0)
1666
- argumentTypeError(observedType, demanded.cmd, position);
1667
- position += 1;
1668
- });
1669
- parsed.optional.forEach((optional) => {
1670
- if (args.length === 0)
1671
- return;
1672
- const arg = args.shift();
1673
- const observedType = guessType(arg);
1674
- const matchingTypes = optional.cmd.filter((type) => type === observedType || type === "*");
1675
- if (matchingTypes.length === 0)
1676
- argumentTypeError(observedType, optional.cmd, position);
1677
- position += 1;
1678
- });
1679
- } catch (err) {
1680
- console.warn(err.stack);
1681
- }
1682
- }
1683
- function guessType(arg) {
1684
- if (Array.isArray(arg)) {
1685
- return "array";
1686
- } else if (arg === null) {
1687
- return "null";
1688
- }
1689
- return typeof arg;
1690
- }
1691
- function argumentTypeError(observedType, allowedTypes, position) {
1692
- throw new YError(`Invalid ${positionName[position] || "manyith"} argument. Expected ${allowedTypes.join(" or ")} but received ${observedType}.`);
1693
- }
1694
-
1695
- // ../../node_modules/yargs/build/lib/middleware.js
1696
- class GlobalMiddleware {
1697
- constructor(yargs) {
1698
- this.globalMiddleware = [];
1699
- this.frozens = [];
1700
- this.yargs = yargs;
1701
- }
1702
- addMiddleware(callback, applyBeforeValidation, global = true, mutates = false) {
1703
- argsert("<array|function> [boolean] [boolean] [boolean]", [callback, applyBeforeValidation, global], arguments.length);
1704
- if (Array.isArray(callback)) {
1705
- for (let i = 0;i < callback.length; i++) {
1706
- if (typeof callback[i] !== "function") {
1707
- throw Error("middleware must be a function");
1708
- }
1709
- const m = callback[i];
1710
- m.applyBeforeValidation = applyBeforeValidation;
1711
- m.global = global;
1712
- }
1713
- Array.prototype.push.apply(this.globalMiddleware, callback);
1714
- } else if (typeof callback === "function") {
1715
- const m = callback;
1716
- m.applyBeforeValidation = applyBeforeValidation;
1717
- m.global = global;
1718
- m.mutates = mutates;
1719
- this.globalMiddleware.push(callback);
1720
- }
1721
- return this.yargs;
1722
- }
1723
- addCoerceMiddleware(callback, option) {
1724
- const aliases = this.yargs.getAliases();
1725
- this.globalMiddleware = this.globalMiddleware.filter((m) => {
1726
- const toCheck = [...aliases[option] || [], option];
1727
- if (!m.option)
1728
- return true;
1729
- else
1730
- return !toCheck.includes(m.option);
1731
- });
1732
- callback.option = option;
1733
- return this.addMiddleware(callback, true, true, true);
1734
- }
1735
- getMiddleware() {
1736
- return this.globalMiddleware;
1737
- }
1738
- freeze() {
1739
- this.frozens.push([...this.globalMiddleware]);
1740
- }
1741
- unfreeze() {
1742
- const frozen = this.frozens.pop();
1743
- if (frozen !== undefined)
1744
- this.globalMiddleware = frozen;
1745
- }
1746
- reset() {
1747
- this.globalMiddleware = this.globalMiddleware.filter((m) => m.global);
1748
- }
1749
- }
1750
- function commandMiddlewareFactory(commandMiddleware) {
1751
- if (!commandMiddleware)
1752
- return [];
1753
- return commandMiddleware.map((middleware) => {
1754
- middleware.applyBeforeValidation = false;
1755
- return middleware;
1756
- });
1757
- }
1758
- function applyMiddleware(argv, yargs, middlewares, beforeValidation) {
1759
- return middlewares.reduce((acc, middleware) => {
1760
- if (middleware.applyBeforeValidation !== beforeValidation) {
1761
- return acc;
1762
- }
1763
- if (middleware.mutates) {
1764
- if (middleware.applied)
1765
- return acc;
1766
- middleware.applied = true;
1767
- }
1768
- if (isPromise(acc)) {
1769
- return acc.then((initialObj) => Promise.all([initialObj, middleware(initialObj, yargs)])).then(([initialObj, middlewareObj]) => Object.assign(initialObj, middlewareObj));
1770
- } else {
1771
- const result = middleware(acc, yargs);
1772
- return isPromise(result) ? result.then((middlewareObj) => Object.assign(acc, middlewareObj)) : Object.assign(acc, result);
1773
- }
1774
- }, argv);
1775
- }
1776
-
1777
- // ../../node_modules/yargs/build/lib/utils/maybe-async-result.js
1778
- function maybeAsyncResult(getResult, resultHandler, errorHandler = (err) => {
1779
- throw err;
1780
- }) {
1781
- try {
1782
- const result = isFunction(getResult) ? getResult() : getResult;
1783
- return isPromise(result) ? result.then((result2) => resultHandler(result2)) : resultHandler(result);
1784
- } catch (err) {
1785
- return errorHandler(err);
1786
- }
1787
- }
1788
- function isFunction(arg) {
1789
- return typeof arg === "function";
1790
- }
1791
-
1792
- // ../../node_modules/yargs/build/lib/utils/which-module.js
1793
- function whichModule(exported) {
1794
- if (false)
1795
- ;
1796
- for (let i = 0, files = Object.keys(__require.cache), mod;i < files.length; i++) {
1797
- mod = __require.cache[files[i]];
1798
- if (mod.exports === exported)
1799
- return mod;
1800
- }
1801
- return null;
1802
- }
1803
-
1804
- // ../../node_modules/yargs/build/lib/command.js
1805
- var DEFAULT_MARKER = /(^\*)|(^\$0)/;
1806
-
1807
- class CommandInstance {
1808
- constructor(usage, validation, globalMiddleware, shim2) {
1809
- this.requireCache = new Set;
1810
- this.handlers = {};
1811
- this.aliasMap = {};
1812
- this.frozens = [];
1813
- this.shim = shim2;
1814
- this.usage = usage;
1815
- this.globalMiddleware = globalMiddleware;
1816
- this.validation = validation;
1817
- }
1818
- addDirectory(dir, req, callerFile, opts) {
1819
- opts = opts || {};
1820
- if (typeof opts.recurse !== "boolean")
1821
- opts.recurse = false;
1822
- if (!Array.isArray(opts.extensions))
1823
- opts.extensions = ["js"];
1824
- const parentVisit = typeof opts.visit === "function" ? opts.visit : (o) => o;
1825
- opts.visit = (obj, joined, filename) => {
1826
- const visited = parentVisit(obj, joined, filename);
1827
- if (visited) {
1828
- if (this.requireCache.has(joined))
1829
- return visited;
1830
- else
1831
- this.requireCache.add(joined);
1832
- this.addHandler(visited);
1833
- }
1834
- return visited;
1835
- };
1836
- this.shim.requireDirectory({ require: req, filename: callerFile }, dir, opts);
1837
- }
1838
- addHandler(cmd, description, builder, handler, commandMiddleware, deprecated) {
1839
- let aliases = [];
1840
- const middlewares = commandMiddlewareFactory(commandMiddleware);
1841
- handler = handler || (() => {
1842
- });
1843
- if (Array.isArray(cmd)) {
1844
- if (isCommandAndAliases(cmd)) {
1845
- [cmd, ...aliases] = cmd;
1846
- } else {
1847
- for (const command of cmd) {
1848
- this.addHandler(command);
1849
- }
1850
- }
1851
- } else if (isCommandHandlerDefinition(cmd)) {
1852
- let command = Array.isArray(cmd.command) || typeof cmd.command === "string" ? cmd.command : this.moduleName(cmd);
1853
- if (cmd.aliases)
1854
- command = [].concat(command).concat(cmd.aliases);
1855
- this.addHandler(command, this.extractDesc(cmd), cmd.builder, cmd.handler, cmd.middlewares, cmd.deprecated);
1856
- return;
1857
- } else if (isCommandBuilderDefinition(builder)) {
1858
- this.addHandler([cmd].concat(aliases), description, builder.builder, builder.handler, builder.middlewares, builder.deprecated);
1859
- return;
1860
- }
1861
- if (typeof cmd === "string") {
1862
- const parsedCommand = parseCommand(cmd);
1863
- aliases = aliases.map((alias) => parseCommand(alias).cmd);
1864
- let isDefault = false;
1865
- const parsedAliases = [parsedCommand.cmd].concat(aliases).filter((c) => {
1866
- if (DEFAULT_MARKER.test(c)) {
1867
- isDefault = true;
1868
- return false;
1869
- }
1870
- return true;
1871
- });
1872
- if (parsedAliases.length === 0 && isDefault)
1873
- parsedAliases.push("$0");
1874
- if (isDefault) {
1875
- parsedCommand.cmd = parsedAliases[0];
1876
- aliases = parsedAliases.slice(1);
1877
- cmd = cmd.replace(DEFAULT_MARKER, parsedCommand.cmd);
1878
- }
1879
- aliases.forEach((alias) => {
1880
- this.aliasMap[alias] = parsedCommand.cmd;
1881
- });
1882
- if (description !== false) {
1883
- this.usage.command(cmd, description, isDefault, aliases, deprecated);
1884
- }
1885
- this.handlers[parsedCommand.cmd] = {
1886
- original: cmd,
1887
- description,
1888
- handler,
1889
- builder: builder || {},
1890
- middlewares,
1891
- deprecated,
1892
- demanded: parsedCommand.demanded,
1893
- optional: parsedCommand.optional
1894
- };
1895
- if (isDefault)
1896
- this.defaultCommand = this.handlers[parsedCommand.cmd];
1897
- }
1898
- }
1899
- getCommandHandlers() {
1900
- return this.handlers;
1901
- }
1902
- getCommands() {
1903
- return Object.keys(this.handlers).concat(Object.keys(this.aliasMap));
1904
- }
1905
- hasDefaultCommand() {
1906
- return !!this.defaultCommand;
1907
- }
1908
- runCommand(command, yargs, parsed, commandIndex, helpOnly, helpOrVersionSet) {
1909
- const commandHandler = this.handlers[command] || this.handlers[this.aliasMap[command]] || this.defaultCommand;
1910
- const currentContext = yargs.getInternalMethods().getContext();
1911
- const parentCommands = currentContext.commands.slice();
1912
- const isDefaultCommand = !command;
1913
- if (command) {
1914
- currentContext.commands.push(command);
1915
- currentContext.fullCommands.push(commandHandler.original);
1916
- }
1917
- const builderResult = this.applyBuilderUpdateUsageAndParse(isDefaultCommand, commandHandler, yargs, parsed.aliases, parentCommands, commandIndex, helpOnly, helpOrVersionSet);
1918
- return isPromise(builderResult) ? builderResult.then((result) => this.applyMiddlewareAndGetResult(isDefaultCommand, commandHandler, result.innerArgv, currentContext, helpOnly, result.aliases, yargs)) : this.applyMiddlewareAndGetResult(isDefaultCommand, commandHandler, builderResult.innerArgv, currentContext, helpOnly, builderResult.aliases, yargs);
1919
- }
1920
- applyBuilderUpdateUsageAndParse(isDefaultCommand, commandHandler, yargs, aliases, parentCommands, commandIndex, helpOnly, helpOrVersionSet) {
1921
- const builder = commandHandler.builder;
1922
- let innerYargs = yargs;
1923
- if (isCommandBuilderCallback(builder)) {
1924
- yargs.getInternalMethods().getUsageInstance().freeze();
1925
- const builderOutput = builder(yargs.getInternalMethods().reset(aliases), helpOrVersionSet);
1926
- if (isPromise(builderOutput)) {
1927
- return builderOutput.then((output) => {
1928
- innerYargs = isYargsInstance(output) ? output : yargs;
1929
- return this.parseAndUpdateUsage(isDefaultCommand, commandHandler, innerYargs, parentCommands, commandIndex, helpOnly);
1930
- });
1931
- }
1932
- } else if (isCommandBuilderOptionDefinitions(builder)) {
1933
- yargs.getInternalMethods().getUsageInstance().freeze();
1934
- innerYargs = yargs.getInternalMethods().reset(aliases);
1935
- Object.keys(commandHandler.builder).forEach((key) => {
1936
- innerYargs.option(key, builder[key]);
1937
- });
1938
- }
1939
- return this.parseAndUpdateUsage(isDefaultCommand, commandHandler, innerYargs, parentCommands, commandIndex, helpOnly);
1940
- }
1941
- parseAndUpdateUsage(isDefaultCommand, commandHandler, innerYargs, parentCommands, commandIndex, helpOnly) {
1942
- if (isDefaultCommand)
1943
- innerYargs.getInternalMethods().getUsageInstance().unfreeze(true);
1944
- if (this.shouldUpdateUsage(innerYargs)) {
1945
- innerYargs.getInternalMethods().getUsageInstance().usage(this.usageFromParentCommandsCommandHandler(parentCommands, commandHandler), commandHandler.description);
1946
- }
1947
- const innerArgv = innerYargs.getInternalMethods().runYargsParserAndExecuteCommands(null, undefined, true, commandIndex, helpOnly);
1948
- return isPromise(innerArgv) ? innerArgv.then((argv) => ({
1949
- aliases: innerYargs.parsed.aliases,
1950
- innerArgv: argv
1951
- })) : {
1952
- aliases: innerYargs.parsed.aliases,
1953
- innerArgv
1954
- };
1955
- }
1956
- shouldUpdateUsage(yargs) {
1957
- return !yargs.getInternalMethods().getUsageInstance().getUsageDisabled() && yargs.getInternalMethods().getUsageInstance().getUsage().length === 0;
1958
- }
1959
- usageFromParentCommandsCommandHandler(parentCommands, commandHandler) {
1960
- const c = DEFAULT_MARKER.test(commandHandler.original) ? commandHandler.original.replace(DEFAULT_MARKER, "").trim() : commandHandler.original;
1961
- const pc = parentCommands.filter((c2) => {
1962
- return !DEFAULT_MARKER.test(c2);
1963
- });
1964
- pc.push(c);
1965
- return `$0 ${pc.join(" ")}`;
1966
- }
1967
- handleValidationAndGetResult(isDefaultCommand, commandHandler, innerArgv, currentContext, aliases, yargs, middlewares, positionalMap) {
1968
- if (!yargs.getInternalMethods().getHasOutput()) {
1969
- const validation = yargs.getInternalMethods().runValidation(aliases, positionalMap, yargs.parsed.error, isDefaultCommand);
1970
- innerArgv = maybeAsyncResult(innerArgv, (result) => {
1971
- validation(result);
1972
- return result;
1973
- });
1974
- }
1975
- if (commandHandler.handler && !yargs.getInternalMethods().getHasOutput()) {
1976
- yargs.getInternalMethods().setHasOutput();
1977
- const populateDoubleDash = !!yargs.getOptions().configuration["populate--"];
1978
- yargs.getInternalMethods().postProcess(innerArgv, populateDoubleDash, false, false);
1979
- innerArgv = applyMiddleware(innerArgv, yargs, middlewares, false);
1980
- innerArgv = maybeAsyncResult(innerArgv, (result) => {
1981
- const handlerResult = commandHandler.handler(result);
1982
- return isPromise(handlerResult) ? handlerResult.then(() => result) : result;
1983
- });
1984
- if (!isDefaultCommand) {
1985
- yargs.getInternalMethods().getUsageInstance().cacheHelpMessage();
1986
- }
1987
- if (isPromise(innerArgv) && !yargs.getInternalMethods().hasParseCallback()) {
1988
- innerArgv.catch((error) => {
1989
- try {
1990
- yargs.getInternalMethods().getUsageInstance().fail(null, error);
1991
- } catch (_err) {
1992
- }
1993
- });
1994
- }
1995
- }
1996
- if (!isDefaultCommand) {
1997
- currentContext.commands.pop();
1998
- currentContext.fullCommands.pop();
1999
- }
2000
- return innerArgv;
2001
- }
2002
- applyMiddlewareAndGetResult(isDefaultCommand, commandHandler, innerArgv, currentContext, helpOnly, aliases, yargs) {
2003
- let positionalMap = {};
2004
- if (helpOnly)
2005
- return innerArgv;
2006
- if (!yargs.getInternalMethods().getHasOutput()) {
2007
- positionalMap = this.populatePositionals(commandHandler, innerArgv, currentContext, yargs);
2008
- }
2009
- const middlewares = this.globalMiddleware.getMiddleware().slice(0).concat(commandHandler.middlewares);
2010
- const maybePromiseArgv = applyMiddleware(innerArgv, yargs, middlewares, true);
2011
- return isPromise(maybePromiseArgv) ? maybePromiseArgv.then((resolvedInnerArgv) => this.handleValidationAndGetResult(isDefaultCommand, commandHandler, resolvedInnerArgv, currentContext, aliases, yargs, middlewares, positionalMap)) : this.handleValidationAndGetResult(isDefaultCommand, commandHandler, maybePromiseArgv, currentContext, aliases, yargs, middlewares, positionalMap);
2012
- }
2013
- populatePositionals(commandHandler, argv, context, yargs) {
2014
- argv._ = argv._.slice(context.commands.length);
2015
- const demanded = commandHandler.demanded.slice(0);
2016
- const optional = commandHandler.optional.slice(0);
2017
- const positionalMap = {};
2018
- this.validation.positionalCount(demanded.length, argv._.length);
2019
- while (demanded.length) {
2020
- const demand = demanded.shift();
2021
- this.populatePositional(demand, argv, positionalMap);
2022
- }
2023
- while (optional.length) {
2024
- const maybe = optional.shift();
2025
- this.populatePositional(maybe, argv, positionalMap);
2026
- }
2027
- argv._ = context.commands.concat(argv._.map((a) => "" + a));
2028
- this.postProcessPositionals(argv, positionalMap, this.cmdToParseOptions(commandHandler.original), yargs);
2029
- return positionalMap;
2030
- }
2031
- populatePositional(positional, argv, positionalMap) {
2032
- const cmd = positional.cmd[0];
2033
- if (positional.variadic) {
2034
- positionalMap[cmd] = argv._.splice(0).map(String);
2035
- } else {
2036
- if (argv._.length)
2037
- positionalMap[cmd] = [String(argv._.shift())];
2038
- }
2039
- }
2040
- cmdToParseOptions(cmdString) {
2041
- const parseOptions = {
2042
- array: [],
2043
- default: {},
2044
- alias: {},
2045
- demand: {}
2046
- };
2047
- const parsed = parseCommand(cmdString);
2048
- parsed.demanded.forEach((d) => {
2049
- const [cmd, ...aliases] = d.cmd;
2050
- if (d.variadic) {
2051
- parseOptions.array.push(cmd);
2052
- parseOptions.default[cmd] = [];
2053
- }
2054
- parseOptions.alias[cmd] = aliases;
2055
- parseOptions.demand[cmd] = true;
2056
- });
2057
- parsed.optional.forEach((o) => {
2058
- const [cmd, ...aliases] = o.cmd;
2059
- if (o.variadic) {
2060
- parseOptions.array.push(cmd);
2061
- parseOptions.default[cmd] = [];
2062
- }
2063
- parseOptions.alias[cmd] = aliases;
2064
- });
2065
- return parseOptions;
2066
- }
2067
- postProcessPositionals(argv, positionalMap, parseOptions, yargs) {
2068
- const options = Object.assign({}, yargs.getOptions());
2069
- options.default = Object.assign(parseOptions.default, options.default);
2070
- for (const key of Object.keys(parseOptions.alias)) {
2071
- options.alias[key] = (options.alias[key] || []).concat(parseOptions.alias[key]);
2072
- }
2073
- options.array = options.array.concat(parseOptions.array);
2074
- options.config = {};
2075
- const unparsed = [];
2076
- Object.keys(positionalMap).forEach((key) => {
2077
- positionalMap[key].map((value) => {
2078
- if (options.configuration["unknown-options-as-args"])
2079
- options.key[key] = true;
2080
- unparsed.push(`--${key}`);
2081
- unparsed.push(value);
2082
- });
2083
- });
2084
- if (!unparsed.length)
2085
- return;
2086
- const config = Object.assign({}, options.configuration, {
2087
- "populate--": false
2088
- });
2089
- const parsed = this.shim.Parser.detailed(unparsed, Object.assign({}, options, {
2090
- configuration: config
2091
- }));
2092
- if (parsed.error) {
2093
- yargs.getInternalMethods().getUsageInstance().fail(parsed.error.message, parsed.error);
2094
- } else {
2095
- const positionalKeys = Object.keys(positionalMap);
2096
- Object.keys(positionalMap).forEach((key) => {
2097
- positionalKeys.push(...parsed.aliases[key]);
2098
- });
2099
- Object.keys(parsed.argv).forEach((key) => {
2100
- if (positionalKeys.includes(key)) {
2101
- if (!positionalMap[key])
2102
- positionalMap[key] = parsed.argv[key];
2103
- if (!this.isInConfigs(yargs, key) && !this.isDefaulted(yargs, key) && Object.prototype.hasOwnProperty.call(argv, key) && Object.prototype.hasOwnProperty.call(parsed.argv, key) && (Array.isArray(argv[key]) || Array.isArray(parsed.argv[key]))) {
2104
- argv[key] = [].concat(argv[key], parsed.argv[key]);
2105
- } else {
2106
- argv[key] = parsed.argv[key];
2107
- }
2108
- }
2109
- });
2110
- }
2111
- }
2112
- isDefaulted(yargs, key) {
2113
- const { default: defaults } = yargs.getOptions();
2114
- return Object.prototype.hasOwnProperty.call(defaults, key) || Object.prototype.hasOwnProperty.call(defaults, this.shim.Parser.camelCase(key));
2115
- }
2116
- isInConfigs(yargs, key) {
2117
- const { configObjects } = yargs.getOptions();
2118
- return configObjects.some((c) => Object.prototype.hasOwnProperty.call(c, key)) || configObjects.some((c) => Object.prototype.hasOwnProperty.call(c, this.shim.Parser.camelCase(key)));
2119
- }
2120
- runDefaultBuilderOn(yargs) {
2121
- if (!this.defaultCommand)
2122
- return;
2123
- if (this.shouldUpdateUsage(yargs)) {
2124
- const commandString = DEFAULT_MARKER.test(this.defaultCommand.original) ? this.defaultCommand.original : this.defaultCommand.original.replace(/^[^[\]<>]*/, "$0 ");
2125
- yargs.getInternalMethods().getUsageInstance().usage(commandString, this.defaultCommand.description);
2126
- }
2127
- const builder = this.defaultCommand.builder;
2128
- if (isCommandBuilderCallback(builder)) {
2129
- return builder(yargs, true);
2130
- } else if (!isCommandBuilderDefinition(builder)) {
2131
- Object.keys(builder).forEach((key) => {
2132
- yargs.option(key, builder[key]);
2133
- });
2134
- }
2135
- return;
2136
- }
2137
- moduleName(obj) {
2138
- const mod = whichModule(obj);
2139
- if (!mod)
2140
- throw new Error(`No command name given for module: ${this.shim.inspect(obj)}`);
2141
- return this.commandFromFilename(mod.filename);
2142
- }
2143
- commandFromFilename(filename) {
2144
- return this.shim.path.basename(filename, this.shim.path.extname(filename));
2145
- }
2146
- extractDesc({ describe, description, desc }) {
2147
- for (const test of [describe, description, desc]) {
2148
- if (typeof test === "string" || test === false)
2149
- return test;
2150
- assertNotStrictEqual(test, true, this.shim);
2151
- }
2152
- return false;
2153
- }
2154
- freeze() {
2155
- this.frozens.push({
2156
- handlers: this.handlers,
2157
- aliasMap: this.aliasMap,
2158
- defaultCommand: this.defaultCommand
2159
- });
2160
- }
2161
- unfreeze() {
2162
- const frozen = this.frozens.pop();
2163
- assertNotStrictEqual(frozen, undefined, this.shim);
2164
- ({
2165
- handlers: this.handlers,
2166
- aliasMap: this.aliasMap,
2167
- defaultCommand: this.defaultCommand
2168
- } = frozen);
2169
- }
2170
- reset() {
2171
- this.handlers = {};
2172
- this.aliasMap = {};
2173
- this.defaultCommand = undefined;
2174
- this.requireCache = new Set;
2175
- return this;
2176
- }
2177
- }
2178
- function command(usage, validation, globalMiddleware, shim2) {
2179
- return new CommandInstance(usage, validation, globalMiddleware, shim2);
2180
- }
2181
- function isCommandBuilderDefinition(builder) {
2182
- return typeof builder === "object" && !!builder.builder && typeof builder.handler === "function";
2183
- }
2184
- function isCommandAndAliases(cmd) {
2185
- return cmd.every((c) => typeof c === "string");
2186
- }
2187
- function isCommandBuilderCallback(builder) {
2188
- return typeof builder === "function";
2189
- }
2190
- function isCommandBuilderOptionDefinitions(builder) {
2191
- return typeof builder === "object";
2192
- }
2193
- function isCommandHandlerDefinition(cmd) {
2194
- return typeof cmd === "object" && !Array.isArray(cmd);
2195
- }
2196
-
2197
- // ../../node_modules/yargs/build/lib/utils/obj-filter.js
2198
- function objFilter(original = {}, filter = () => true) {
2199
- const obj = {};
2200
- objectKeys(original).forEach((key) => {
2201
- if (filter(key, original[key])) {
2202
- obj[key] = original[key];
2203
- }
2204
- });
2205
- return obj;
2206
- }
2207
-
2208
- // ../../node_modules/yargs/build/lib/utils/set-blocking.js
2209
- function setBlocking(blocking) {
2210
- if (typeof process === "undefined")
2211
- return;
2212
- [process.stdout, process.stderr].forEach((_stream) => {
2213
- const stream = _stream;
2214
- if (stream._handle && stream.isTTY && typeof stream._handle.setBlocking === "function") {
2215
- stream._handle.setBlocking(blocking);
2216
- }
2217
- });
2218
- }
2219
-
2220
- // ../../node_modules/yargs/build/lib/usage.js
2221
- function isBoolean(fail) {
2222
- return typeof fail === "boolean";
2223
- }
2224
- function usage(yargs, shim2) {
2225
- const __ = shim2.y18n.__;
2226
- const self = {};
2227
- const fails = [];
2228
- self.failFn = function failFn(f) {
2229
- fails.push(f);
2230
- };
2231
- let failMessage = null;
2232
- let globalFailMessage = null;
2233
- let showHelpOnFail = true;
2234
- self.showHelpOnFail = function showHelpOnFailFn(arg1 = true, arg2) {
2235
- const [enabled, message] = typeof arg1 === "string" ? [true, arg1] : [arg1, arg2];
2236
- if (yargs.getInternalMethods().isGlobalContext()) {
2237
- globalFailMessage = message;
2238
- }
2239
- failMessage = message;
2240
- showHelpOnFail = enabled;
2241
- return self;
2242
- };
2243
- let failureOutput = false;
2244
- self.fail = function fail(msg, err) {
2245
- const logger = yargs.getInternalMethods().getLoggerInstance();
2246
- if (fails.length) {
2247
- for (let i = fails.length - 1;i >= 0; --i) {
2248
- const fail = fails[i];
2249
- if (isBoolean(fail)) {
2250
- if (err)
2251
- throw err;
2252
- else if (msg)
2253
- throw Error(msg);
2254
- } else {
2255
- fail(msg, err, self);
2256
- }
2257
- }
2258
- } else {
2259
- if (yargs.getExitProcess())
2260
- setBlocking(true);
2261
- if (!failureOutput) {
2262
- failureOutput = true;
2263
- if (showHelpOnFail) {
2264
- yargs.showHelp("error");
2265
- logger.error();
2266
- }
2267
- if (msg || err)
2268
- logger.error(msg || err);
2269
- const globalOrCommandFailMessage = failMessage || globalFailMessage;
2270
- if (globalOrCommandFailMessage) {
2271
- if (msg || err)
2272
- logger.error("");
2273
- logger.error(globalOrCommandFailMessage);
2274
- }
2275
- }
2276
- err = err || new YError(msg);
2277
- if (yargs.getExitProcess()) {
2278
- return yargs.exit(1);
2279
- } else if (yargs.getInternalMethods().hasParseCallback()) {
2280
- return yargs.exit(1, err);
2281
- } else {
2282
- throw err;
2283
- }
2284
- }
2285
- };
2286
- let usages = [];
2287
- let usageDisabled = false;
2288
- self.usage = (msg, description) => {
2289
- if (msg === null) {
2290
- usageDisabled = true;
2291
- usages = [];
2292
- return self;
2293
- }
2294
- usageDisabled = false;
2295
- usages.push([msg, description || ""]);
2296
- return self;
2297
- };
2298
- self.getUsage = () => {
2299
- return usages;
2300
- };
2301
- self.getUsageDisabled = () => {
2302
- return usageDisabled;
2303
- };
2304
- self.getPositionalGroupName = () => {
2305
- return __("Positionals:");
2306
- };
2307
- let examples = [];
2308
- self.example = (cmd, description) => {
2309
- examples.push([cmd, description || ""]);
2310
- };
2311
- let commands = [];
2312
- self.command = function command(cmd, description, isDefault, aliases, deprecated = false) {
2313
- if (isDefault) {
2314
- commands = commands.map((cmdArray) => {
2315
- cmdArray[2] = false;
2316
- return cmdArray;
2317
- });
2318
- }
2319
- commands.push([cmd, description || "", isDefault, aliases, deprecated]);
2320
- };
2321
- self.getCommands = () => commands;
2322
- let descriptions = {};
2323
- self.describe = function describe(keyOrKeys, desc) {
2324
- if (Array.isArray(keyOrKeys)) {
2325
- keyOrKeys.forEach((k) => {
2326
- self.describe(k, desc);
2327
- });
2328
- } else if (typeof keyOrKeys === "object") {
2329
- Object.keys(keyOrKeys).forEach((k) => {
2330
- self.describe(k, keyOrKeys[k]);
2331
- });
2332
- } else {
2333
- descriptions[keyOrKeys] = desc;
2334
- }
2335
- };
2336
- self.getDescriptions = () => descriptions;
2337
- let epilogs = [];
2338
- self.epilog = (msg) => {
2339
- epilogs.push(msg);
2340
- };
2341
- let wrapSet = false;
2342
- let wrap2;
2343
- self.wrap = (cols) => {
2344
- wrapSet = true;
2345
- wrap2 = cols;
2346
- };
2347
- self.getWrap = () => {
2348
- if (shim2.getEnv("YARGS_DISABLE_WRAP")) {
2349
- return null;
2350
- }
2351
- if (!wrapSet) {
2352
- wrap2 = windowWidth();
2353
- wrapSet = true;
2354
- }
2355
- return wrap2;
2356
- };
2357
- const deferY18nLookupPrefix = "__yargsString__:";
2358
- self.deferY18nLookup = (str) => deferY18nLookupPrefix + str;
2359
- self.help = function help() {
2360
- if (cachedHelpMessage)
2361
- return cachedHelpMessage;
2362
- normalizeAliases();
2363
- const base$0 = yargs.customScriptName ? yargs.$0 : shim2.path.basename(yargs.$0);
2364
- const demandedOptions = yargs.getDemandedOptions();
2365
- const demandedCommands = yargs.getDemandedCommands();
2366
- const deprecatedOptions = yargs.getDeprecatedOptions();
2367
- const groups = yargs.getGroups();
2368
- const options = yargs.getOptions();
2369
- let keys = [];
2370
- keys = keys.concat(Object.keys(descriptions));
2371
- keys = keys.concat(Object.keys(demandedOptions));
2372
- keys = keys.concat(Object.keys(demandedCommands));
2373
- keys = keys.concat(Object.keys(options.default));
2374
- keys = keys.filter(filterHiddenOptions);
2375
- keys = Object.keys(keys.reduce((acc, key) => {
2376
- if (key !== "_")
2377
- acc[key] = true;
2378
- return acc;
2379
- }, {}));
2380
- const theWrap = self.getWrap();
2381
- const ui2 = shim2.cliui({
2382
- width: theWrap,
2383
- wrap: !!theWrap
2384
- });
2385
- if (!usageDisabled) {
2386
- if (usages.length) {
2387
- usages.forEach((usage2) => {
2388
- ui2.div({ text: `${usage2[0].replace(/\$0/g, base$0)}` });
2389
- if (usage2[1]) {
2390
- ui2.div({ text: `${usage2[1]}`, padding: [1, 0, 0, 0] });
2391
- }
2392
- });
2393
- ui2.div();
2394
- } else if (commands.length) {
2395
- let u = null;
2396
- if (demandedCommands._) {
2397
- u = `${base$0} <${__("command")}>
2398
- `;
2399
- } else {
2400
- u = `${base$0} [${__("command")}]
2401
- `;
2402
- }
2403
- ui2.div(`${u}`);
2404
- }
2405
- }
2406
- if (commands.length > 1 || commands.length === 1 && !commands[0][2]) {
2407
- ui2.div(__("Commands:"));
2408
- const context = yargs.getInternalMethods().getContext();
2409
- const parentCommands = context.commands.length ? `${context.commands.join(" ")} ` : "";
2410
- if (yargs.getInternalMethods().getParserConfiguration()["sort-commands"] === true) {
2411
- commands = commands.sort((a, b) => a[0].localeCompare(b[0]));
2412
- }
2413
- const prefix = base$0 ? `${base$0} ` : "";
2414
- commands.forEach((command2) => {
2415
- const commandString = `${prefix}${parentCommands}${command2[0].replace(/^\$0 ?/, "")}`;
2416
- ui2.span({
2417
- text: commandString,
2418
- padding: [0, 2, 0, 2],
2419
- width: maxWidth(commands, theWrap, `${base$0}${parentCommands}`) + 4
2420
- }, { text: command2[1] });
2421
- const hints = [];
2422
- if (command2[2])
2423
- hints.push(`[${__("default")}]`);
2424
- if (command2[3] && command2[3].length) {
2425
- hints.push(`[${__("aliases:")} ${command2[3].join(", ")}]`);
2426
- }
2427
- if (command2[4]) {
2428
- if (typeof command2[4] === "string") {
2429
- hints.push(`[${__("deprecated: %s", command2[4])}]`);
2430
- } else {
2431
- hints.push(`[${__("deprecated")}]`);
2432
- }
2433
- }
2434
- if (hints.length) {
2435
- ui2.div({
2436
- text: hints.join(" "),
2437
- padding: [0, 0, 0, 2],
2438
- align: "right"
2439
- });
2440
- } else {
2441
- ui2.div();
2442
- }
2443
- });
2444
- ui2.div();
2445
- }
2446
- const aliasKeys = (Object.keys(options.alias) || []).concat(Object.keys(yargs.parsed.newAliases) || []);
2447
- keys = keys.filter((key) => !yargs.parsed.newAliases[key] && aliasKeys.every((alias) => (options.alias[alias] || []).indexOf(key) === -1));
2448
- const defaultGroup = __("Options:");
2449
- if (!groups[defaultGroup])
2450
- groups[defaultGroup] = [];
2451
- addUngroupedKeys(keys, options.alias, groups, defaultGroup);
2452
- const isLongSwitch = (sw) => /^--/.test(getText(sw));
2453
- const displayedGroups = Object.keys(groups).filter((groupName) => groups[groupName].length > 0).map((groupName) => {
2454
- const normalizedKeys = groups[groupName].filter(filterHiddenOptions).map((key) => {
2455
- if (aliasKeys.includes(key))
2456
- return key;
2457
- for (let i = 0, aliasKey;(aliasKey = aliasKeys[i]) !== undefined; i++) {
2458
- if ((options.alias[aliasKey] || []).includes(key))
2459
- return aliasKey;
2460
- }
2461
- return key;
2462
- });
2463
- return { groupName, normalizedKeys };
2464
- }).filter(({ normalizedKeys }) => normalizedKeys.length > 0).map(({ groupName, normalizedKeys }) => {
2465
- const switches = normalizedKeys.reduce((acc, key) => {
2466
- acc[key] = [key].concat(options.alias[key] || []).map((sw) => {
2467
- if (groupName === self.getPositionalGroupName())
2468
- return sw;
2469
- else {
2470
- return (/^[0-9]$/.test(sw) ? options.boolean.includes(key) ? "-" : "--" : sw.length > 1 ? "--" : "-") + sw;
2471
- }
2472
- }).sort((sw1, sw2) => isLongSwitch(sw1) === isLongSwitch(sw2) ? 0 : isLongSwitch(sw1) ? 1 : -1).join(", ");
2473
- return acc;
2474
- }, {});
2475
- return { groupName, normalizedKeys, switches };
2476
- });
2477
- const shortSwitchesUsed = displayedGroups.filter(({ groupName }) => groupName !== self.getPositionalGroupName()).some(({ normalizedKeys, switches }) => !normalizedKeys.every((key) => isLongSwitch(switches[key])));
2478
- if (shortSwitchesUsed) {
2479
- displayedGroups.filter(({ groupName }) => groupName !== self.getPositionalGroupName()).forEach(({ normalizedKeys, switches }) => {
2480
- normalizedKeys.forEach((key) => {
2481
- if (isLongSwitch(switches[key])) {
2482
- switches[key] = addIndentation(switches[key], "-x, ".length);
2483
- }
2484
- });
2485
- });
2486
- }
2487
- displayedGroups.forEach(({ groupName, normalizedKeys, switches }) => {
2488
- ui2.div(groupName);
2489
- normalizedKeys.forEach((key) => {
2490
- const kswitch = switches[key];
2491
- let desc = descriptions[key] || "";
2492
- let type = null;
2493
- if (desc.includes(deferY18nLookupPrefix))
2494
- desc = __(desc.substring(deferY18nLookupPrefix.length));
2495
- if (options.boolean.includes(key))
2496
- type = `[${__("boolean")}]`;
2497
- if (options.count.includes(key))
2498
- type = `[${__("count")}]`;
2499
- if (options.string.includes(key))
2500
- type = `[${__("string")}]`;
2501
- if (options.normalize.includes(key))
2502
- type = `[${__("string")}]`;
2503
- if (options.array.includes(key))
2504
- type = `[${__("array")}]`;
2505
- if (options.number.includes(key))
2506
- type = `[${__("number")}]`;
2507
- const deprecatedExtra = (deprecated) => typeof deprecated === "string" ? `[${__("deprecated: %s", deprecated)}]` : `[${__("deprecated")}]`;
2508
- const extra = [
2509
- key in deprecatedOptions ? deprecatedExtra(deprecatedOptions[key]) : null,
2510
- type,
2511
- key in demandedOptions ? `[${__("required")}]` : null,
2512
- options.choices && options.choices[key] ? `[${__("choices:")} ${self.stringifiedValues(options.choices[key])}]` : null,
2513
- defaultString(options.default[key], options.defaultDescription[key])
2514
- ].filter(Boolean).join(" ");
2515
- ui2.span({
2516
- text: getText(kswitch),
2517
- padding: [0, 2, 0, 2 + getIndentation(kswitch)],
2518
- width: maxWidth(switches, theWrap) + 4
2519
- }, desc);
2520
- const shouldHideOptionExtras = yargs.getInternalMethods().getUsageConfiguration()["hide-types"] === true;
2521
- if (extra && !shouldHideOptionExtras)
2522
- ui2.div({ text: extra, padding: [0, 0, 0, 2], align: "right" });
2523
- else
2524
- ui2.div();
2525
- });
2526
- ui2.div();
2527
- });
2528
- if (examples.length) {
2529
- ui2.div(__("Examples:"));
2530
- examples.forEach((example) => {
2531
- example[0] = example[0].replace(/\$0/g, base$0);
2532
- });
2533
- examples.forEach((example) => {
2534
- if (example[1] === "") {
2535
- ui2.div({
2536
- text: example[0],
2537
- padding: [0, 2, 0, 2]
2538
- });
2539
- } else {
2540
- ui2.div({
2541
- text: example[0],
2542
- padding: [0, 2, 0, 2],
2543
- width: maxWidth(examples, theWrap) + 4
2544
- }, {
2545
- text: example[1]
2546
- });
2547
- }
2548
- });
2549
- ui2.div();
2550
- }
2551
- if (epilogs.length > 0) {
2552
- const e = epilogs.map((epilog) => epilog.replace(/\$0/g, base$0)).join(`
2553
- `);
2554
- ui2.div(`${e}
2555
- `);
2556
- }
2557
- return ui2.toString().replace(/\s*$/, "");
2558
- };
2559
- function maxWidth(table, theWrap, modifier) {
2560
- let width = 0;
2561
- if (!Array.isArray(table)) {
2562
- table = Object.values(table).map((v) => [v]);
2563
- }
2564
- table.forEach((v) => {
2565
- width = Math.max(shim2.stringWidth(modifier ? `${modifier} ${getText(v[0])}` : getText(v[0])) + getIndentation(v[0]), width);
2566
- });
2567
- if (theWrap)
2568
- width = Math.min(width, parseInt((theWrap * 0.5).toString(), 10));
2569
- return width;
2570
- }
2571
- function normalizeAliases() {
2572
- const demandedOptions = yargs.getDemandedOptions();
2573
- const options = yargs.getOptions();
2574
- (Object.keys(options.alias) || []).forEach((key) => {
2575
- options.alias[key].forEach((alias) => {
2576
- if (descriptions[alias])
2577
- self.describe(key, descriptions[alias]);
2578
- if (alias in demandedOptions)
2579
- yargs.demandOption(key, demandedOptions[alias]);
2580
- if (options.boolean.includes(alias))
2581
- yargs.boolean(key);
2582
- if (options.count.includes(alias))
2583
- yargs.count(key);
2584
- if (options.string.includes(alias))
2585
- yargs.string(key);
2586
- if (options.normalize.includes(alias))
2587
- yargs.normalize(key);
2588
- if (options.array.includes(alias))
2589
- yargs.array(key);
2590
- if (options.number.includes(alias))
2591
- yargs.number(key);
2592
- });
2593
- });
2594
- }
2595
- let cachedHelpMessage;
2596
- self.cacheHelpMessage = function() {
2597
- cachedHelpMessage = this.help();
2598
- };
2599
- self.clearCachedHelpMessage = function() {
2600
- cachedHelpMessage = undefined;
2601
- };
2602
- self.hasCachedHelpMessage = function() {
2603
- return !!cachedHelpMessage;
2604
- };
2605
- function addUngroupedKeys(keys, aliases, groups, defaultGroup) {
2606
- let groupedKeys = [];
2607
- let toCheck = null;
2608
- Object.keys(groups).forEach((group) => {
2609
- groupedKeys = groupedKeys.concat(groups[group]);
2610
- });
2611
- keys.forEach((key) => {
2612
- toCheck = [key].concat(aliases[key]);
2613
- if (!toCheck.some((k) => groupedKeys.indexOf(k) !== -1)) {
2614
- groups[defaultGroup].push(key);
2615
- }
2616
- });
2617
- return groupedKeys;
2618
- }
2619
- function filterHiddenOptions(key) {
2620
- return yargs.getOptions().hiddenOptions.indexOf(key) < 0 || yargs.parsed.argv[yargs.getOptions().showHiddenOpt];
2621
- }
2622
- self.showHelp = (level) => {
2623
- const logger = yargs.getInternalMethods().getLoggerInstance();
2624
- if (!level)
2625
- level = "error";
2626
- const emit = typeof level === "function" ? level : logger[level];
2627
- emit(self.help());
2628
- };
2629
- self.functionDescription = (fn) => {
2630
- const description = fn.name ? shim2.Parser.decamelize(fn.name, "-") : __("generated-value");
2631
- return ["(", description, ")"].join("");
2632
- };
2633
- self.stringifiedValues = function stringifiedValues(values, separator) {
2634
- let string = "";
2635
- const sep = separator || ", ";
2636
- const array = [].concat(values);
2637
- if (!values || !array.length)
2638
- return string;
2639
- array.forEach((value) => {
2640
- if (string.length)
2641
- string += sep;
2642
- string += JSON.stringify(value);
2643
- });
2644
- return string;
2645
- };
2646
- function defaultString(value, defaultDescription) {
2647
- let string = `[${__("default:")} `;
2648
- if (value === undefined && !defaultDescription)
2649
- return null;
2650
- if (defaultDescription) {
2651
- string += defaultDescription;
2652
- } else {
2653
- switch (typeof value) {
2654
- case "string":
2655
- string += `"${value}"`;
2656
- break;
2657
- case "object":
2658
- string += JSON.stringify(value);
2659
- break;
2660
- default:
2661
- string += value;
2662
- }
2663
- }
2664
- return `${string}]`;
2665
- }
2666
- function windowWidth() {
2667
- const maxWidth2 = 80;
2668
- if (shim2.process.stdColumns) {
2669
- return Math.min(maxWidth2, shim2.process.stdColumns);
2670
- } else {
2671
- return maxWidth2;
2672
- }
2673
- }
2674
- let version = null;
2675
- self.version = (ver) => {
2676
- version = ver;
2677
- };
2678
- self.showVersion = (level) => {
2679
- const logger = yargs.getInternalMethods().getLoggerInstance();
2680
- if (!level)
2681
- level = "error";
2682
- const emit = typeof level === "function" ? level : logger[level];
2683
- emit(version);
2684
- };
2685
- self.reset = function reset(localLookup) {
2686
- failMessage = null;
2687
- failureOutput = false;
2688
- usages = [];
2689
- usageDisabled = false;
2690
- epilogs = [];
2691
- examples = [];
2692
- commands = [];
2693
- descriptions = objFilter(descriptions, (k) => !localLookup[k]);
2694
- return self;
2695
- };
2696
- const frozens = [];
2697
- self.freeze = function freeze() {
2698
- frozens.push({
2699
- failMessage,
2700
- failureOutput,
2701
- usages,
2702
- usageDisabled,
2703
- epilogs,
2704
- examples,
2705
- commands,
2706
- descriptions
2707
- });
2708
- };
2709
- self.unfreeze = function unfreeze(defaultCommand = false) {
2710
- const frozen = frozens.pop();
2711
- if (!frozen)
2712
- return;
2713
- if (defaultCommand) {
2714
- descriptions = { ...frozen.descriptions, ...descriptions };
2715
- commands = [...frozen.commands, ...commands];
2716
- usages = [...frozen.usages, ...usages];
2717
- examples = [...frozen.examples, ...examples];
2718
- epilogs = [...frozen.epilogs, ...epilogs];
2719
- } else {
2720
- ({
2721
- failMessage,
2722
- failureOutput,
2723
- usages,
2724
- usageDisabled,
2725
- epilogs,
2726
- examples,
2727
- commands,
2728
- descriptions
2729
- } = frozen);
2730
- }
2731
- };
2732
- return self;
2733
- }
2734
- function isIndentedText(text) {
2735
- return typeof text === "object";
2736
- }
2737
- function addIndentation(text, indent) {
2738
- return isIndentedText(text) ? { text: text.text, indentation: text.indentation + indent } : { text, indentation: indent };
2739
- }
2740
- function getIndentation(text) {
2741
- return isIndentedText(text) ? text.indentation : 0;
2742
- }
2743
- function getText(text) {
2744
- return isIndentedText(text) ? text.text : text;
2745
- }
2746
-
2747
- // ../../node_modules/yargs/build/lib/completion-templates.js
2748
- var completionShTemplate = `###-begin-{{app_name}}-completions-###
2749
- #
2750
- # yargs command completion script
2751
- #
2752
- # Installation: {{app_path}} {{completion_command}} >> ~/.bashrc
2753
- # or {{app_path}} {{completion_command}} >> ~/.bash_profile on OSX.
2754
- #
2755
- _{{app_name}}_yargs_completions()
2756
- {
2757
- local cur_word args type_list
2758
-
2759
- cur_word="\${COMP_WORDS[COMP_CWORD]}"
2760
- args=("\${COMP_WORDS[@]}")
2761
-
2762
- # ask yargs to generate completions.
2763
- type_list=$({{app_path}} --get-yargs-completions "\${args[@]}")
2764
-
2765
- COMPREPLY=( $(compgen -W "\${type_list}" -- \${cur_word}) )
2766
-
2767
- # if no match was found, fall back to filename completion
2768
- if [ \${#COMPREPLY[@]} -eq 0 ]; then
2769
- COMPREPLY=()
2770
- fi
2771
-
2772
- return 0
2773
- }
2774
- complete -o bashdefault -o default -F _{{app_name}}_yargs_completions {{app_name}}
2775
- ###-end-{{app_name}}-completions-###
2776
- `;
2777
- var completionZshTemplate = `#compdef {{app_name}}
2778
- ###-begin-{{app_name}}-completions-###
2779
- #
2780
- # yargs command completion script
2781
- #
2782
- # Installation: {{app_path}} {{completion_command}} >> ~/.zshrc
2783
- # or {{app_path}} {{completion_command}} >> ~/.zprofile on OSX.
2784
- #
2785
- _{{app_name}}_yargs_completions()
2786
- {
2787
- local reply
2788
- local si=$IFS
2789
- IFS=$'
2790
- ' reply=($(COMP_CWORD="$((CURRENT-1))" COMP_LINE="$BUFFER" COMP_POINT="$CURSOR" {{app_path}} --get-yargs-completions "\${words[@]}"))
2791
- IFS=$si
2792
- _describe 'values' reply
2793
- }
2794
- compdef _{{app_name}}_yargs_completions {{app_name}}
2795
- ###-end-{{app_name}}-completions-###
2796
- `;
2797
-
2798
- // ../../node_modules/yargs/build/lib/completion.js
2799
- class Completion {
2800
- constructor(yargs, usage2, command2, shim2) {
2801
- var _a2, _b2, _c2;
2802
- this.yargs = yargs;
2803
- this.usage = usage2;
2804
- this.command = command2;
2805
- this.shim = shim2;
2806
- this.completionKey = "get-yargs-completions";
2807
- this.aliases = null;
2808
- this.customCompletionFunction = null;
2809
- this.indexAfterLastReset = 0;
2810
- this.zshShell = (_c2 = ((_a2 = this.shim.getEnv("SHELL")) === null || _a2 === undefined ? undefined : _a2.includes("zsh")) || ((_b2 = this.shim.getEnv("ZSH_NAME")) === null || _b2 === undefined ? undefined : _b2.includes("zsh"))) !== null && _c2 !== undefined ? _c2 : false;
2811
- }
2812
- defaultCompletion(args, argv, current, done) {
2813
- const handlers = this.command.getCommandHandlers();
2814
- for (let i = 0, ii = args.length;i < ii; ++i) {
2815
- if (handlers[args[i]] && handlers[args[i]].builder) {
2816
- const builder = handlers[args[i]].builder;
2817
- if (isCommandBuilderCallback(builder)) {
2818
- this.indexAfterLastReset = i + 1;
2819
- const y = this.yargs.getInternalMethods().reset();
2820
- builder(y, true);
2821
- return y.argv;
2822
- }
2823
- }
2824
- }
2825
- const completions = [];
2826
- this.commandCompletions(completions, args, current);
2827
- this.optionCompletions(completions, args, argv, current);
2828
- this.choicesFromOptionsCompletions(completions, args, argv, current);
2829
- this.choicesFromPositionalsCompletions(completions, args, argv, current);
2830
- done(null, completions);
2831
- }
2832
- commandCompletions(completions, args, current) {
2833
- const parentCommands = this.yargs.getInternalMethods().getContext().commands;
2834
- if (!current.match(/^-/) && parentCommands[parentCommands.length - 1] !== current && !this.previousArgHasChoices(args)) {
2835
- this.usage.getCommands().forEach((usageCommand) => {
2836
- const commandName = parseCommand(usageCommand[0]).cmd;
2837
- if (args.indexOf(commandName) === -1) {
2838
- if (!this.zshShell) {
2839
- completions.push(commandName);
2840
- } else {
2841
- const desc = usageCommand[1] || "";
2842
- completions.push(commandName.replace(/:/g, "\\:") + ":" + desc);
2843
- }
2844
- }
2845
- });
2846
- }
2847
- }
2848
- optionCompletions(completions, args, argv, current) {
2849
- if ((current.match(/^-/) || current === "" && completions.length === 0) && !this.previousArgHasChoices(args)) {
2850
- const options = this.yargs.getOptions();
2851
- const positionalKeys = this.yargs.getGroups()[this.usage.getPositionalGroupName()] || [];
2852
- Object.keys(options.key).forEach((key) => {
2853
- const negable = !!options.configuration["boolean-negation"] && options.boolean.includes(key);
2854
- const isPositionalKey = positionalKeys.includes(key);
2855
- if (!isPositionalKey && !options.hiddenOptions.includes(key) && !this.argsContainKey(args, key, negable)) {
2856
- this.completeOptionKey(key, completions, current, negable && !!options.default[key]);
2857
- }
2858
- });
2859
- }
2860
- }
2861
- choicesFromOptionsCompletions(completions, args, argv, current) {
2862
- if (this.previousArgHasChoices(args)) {
2863
- const choices = this.getPreviousArgChoices(args);
2864
- if (choices && choices.length > 0) {
2865
- completions.push(...choices.map((c) => c.replace(/:/g, "\\:")));
2866
- }
2867
- }
2868
- }
2869
- choicesFromPositionalsCompletions(completions, args, argv, current) {
2870
- if (current === "" && completions.length > 0 && this.previousArgHasChoices(args)) {
2871
- return;
2872
- }
2873
- const positionalKeys = this.yargs.getGroups()[this.usage.getPositionalGroupName()] || [];
2874
- const offset = Math.max(this.indexAfterLastReset, this.yargs.getInternalMethods().getContext().commands.length + 1);
2875
- const positionalKey = positionalKeys[argv._.length - offset - 1];
2876
- if (!positionalKey) {
2877
- return;
2878
- }
2879
- const choices = this.yargs.getOptions().choices[positionalKey] || [];
2880
- for (const choice of choices) {
2881
- if (choice.startsWith(current)) {
2882
- completions.push(choice.replace(/:/g, "\\:"));
2883
- }
2884
- }
2885
- }
2886
- getPreviousArgChoices(args) {
2887
- if (args.length < 1)
2888
- return;
2889
- let previousArg = args[args.length - 1];
2890
- let filter = "";
2891
- if (!previousArg.startsWith("-") && args.length > 1) {
2892
- filter = previousArg;
2893
- previousArg = args[args.length - 2];
2894
- }
2895
- if (!previousArg.startsWith("-"))
2896
- return;
2897
- const previousArgKey = previousArg.replace(/^-+/, "");
2898
- const options = this.yargs.getOptions();
2899
- const possibleAliases = [
2900
- previousArgKey,
2901
- ...this.yargs.getAliases()[previousArgKey] || []
2902
- ];
2903
- let choices;
2904
- for (const possibleAlias of possibleAliases) {
2905
- if (Object.prototype.hasOwnProperty.call(options.key, possibleAlias) && Array.isArray(options.choices[possibleAlias])) {
2906
- choices = options.choices[possibleAlias];
2907
- break;
2908
- }
2909
- }
2910
- if (choices) {
2911
- return choices.filter((choice) => !filter || choice.startsWith(filter));
2912
- }
2913
- }
2914
- previousArgHasChoices(args) {
2915
- const choices = this.getPreviousArgChoices(args);
2916
- return choices !== undefined && choices.length > 0;
2917
- }
2918
- argsContainKey(args, key, negable) {
2919
- const argsContains = (s) => args.indexOf((/^[^0-9]$/.test(s) ? "-" : "--") + s) !== -1;
2920
- if (argsContains(key))
2921
- return true;
2922
- if (negable && argsContains(`no-${key}`))
2923
- return true;
2924
- if (this.aliases) {
2925
- for (const alias of this.aliases[key]) {
2926
- if (argsContains(alias))
2927
- return true;
2928
- }
2929
- }
2930
- return false;
2931
- }
2932
- completeOptionKey(key, completions, current, negable) {
2933
- var _a2, _b2, _c2, _d;
2934
- let keyWithDesc = key;
2935
- if (this.zshShell) {
2936
- const descs = this.usage.getDescriptions();
2937
- const aliasKey = (_b2 = (_a2 = this === null || this === undefined ? undefined : this.aliases) === null || _a2 === undefined ? undefined : _a2[key]) === null || _b2 === undefined ? undefined : _b2.find((alias) => {
2938
- const desc2 = descs[alias];
2939
- return typeof desc2 === "string" && desc2.length > 0;
2940
- });
2941
- const descFromAlias = aliasKey ? descs[aliasKey] : undefined;
2942
- const desc = (_d = (_c2 = descs[key]) !== null && _c2 !== undefined ? _c2 : descFromAlias) !== null && _d !== undefined ? _d : "";
2943
- keyWithDesc = `${key.replace(/:/g, "\\:")}:${desc.replace("__yargsString__:", "").replace(/(\r\n|\n|\r)/gm, " ")}`;
2944
- }
2945
- const startsByTwoDashes = (s) => /^--/.test(s);
2946
- const isShortOption = (s) => /^[^0-9]$/.test(s);
2947
- const dashes = !startsByTwoDashes(current) && isShortOption(key) ? "-" : "--";
2948
- completions.push(dashes + keyWithDesc);
2949
- if (negable) {
2950
- completions.push(dashes + "no-" + keyWithDesc);
2951
- }
2952
- }
2953
- customCompletion(args, argv, current, done) {
2954
- assertNotStrictEqual(this.customCompletionFunction, null, this.shim);
2955
- if (isSyncCompletionFunction(this.customCompletionFunction)) {
2956
- const result = this.customCompletionFunction(current, argv);
2957
- if (isPromise(result)) {
2958
- return result.then((list) => {
2959
- this.shim.process.nextTick(() => {
2960
- done(null, list);
2961
- });
2962
- }).catch((err) => {
2963
- this.shim.process.nextTick(() => {
2964
- done(err, undefined);
2965
- });
2966
- });
2967
- }
2968
- return done(null, result);
2969
- } else if (isFallbackCompletionFunction(this.customCompletionFunction)) {
2970
- return this.customCompletionFunction(current, argv, (onCompleted = done) => this.defaultCompletion(args, argv, current, onCompleted), (completions) => {
2971
- done(null, completions);
2972
- });
2973
- } else {
2974
- return this.customCompletionFunction(current, argv, (completions) => {
2975
- done(null, completions);
2976
- });
2977
- }
2978
- }
2979
- getCompletion(args, done) {
2980
- const current = args.length ? args[args.length - 1] : "";
2981
- const argv = this.yargs.parse(args, true);
2982
- const completionFunction = this.customCompletionFunction ? (argv2) => this.customCompletion(args, argv2, current, done) : (argv2) => this.defaultCompletion(args, argv2, current, done);
2983
- return isPromise(argv) ? argv.then(completionFunction) : completionFunction(argv);
2984
- }
2985
- generateCompletionScript($0, cmd) {
2986
- let script = this.zshShell ? completionZshTemplate : completionShTemplate;
2987
- const name = this.shim.path.basename($0);
2988
- if ($0.match(/\.js$/))
2989
- $0 = `./${$0}`;
2990
- script = script.replace(/{{app_name}}/g, name);
2991
- script = script.replace(/{{completion_command}}/g, cmd);
2992
- return script.replace(/{{app_path}}/g, $0);
2993
- }
2994
- registerFunction(fn) {
2995
- this.customCompletionFunction = fn;
2996
- }
2997
- setParsed(parsed) {
2998
- this.aliases = parsed.aliases;
2999
- }
3000
- }
3001
- function completion(yargs, usage2, command2, shim2) {
3002
- return new Completion(yargs, usage2, command2, shim2);
3003
- }
3004
- function isSyncCompletionFunction(completionFunction) {
3005
- return completionFunction.length < 3;
3006
- }
3007
- function isFallbackCompletionFunction(completionFunction) {
3008
- return completionFunction.length > 3;
3009
- }
3010
-
3011
- // ../../node_modules/yargs/build/lib/utils/levenshtein.js
3012
- function levenshtein(a, b) {
3013
- if (a.length === 0)
3014
- return b.length;
3015
- if (b.length === 0)
3016
- return a.length;
3017
- const matrix = [];
3018
- let i;
3019
- for (i = 0;i <= b.length; i++) {
3020
- matrix[i] = [i];
3021
- }
3022
- let j;
3023
- for (j = 0;j <= a.length; j++) {
3024
- matrix[0][j] = j;
3025
- }
3026
- for (i = 1;i <= b.length; i++) {
3027
- for (j = 1;j <= a.length; j++) {
3028
- if (b.charAt(i - 1) === a.charAt(j - 1)) {
3029
- matrix[i][j] = matrix[i - 1][j - 1];
3030
- } else {
3031
- if (i > 1 && j > 1 && b.charAt(i - 2) === a.charAt(j - 1) && b.charAt(i - 1) === a.charAt(j - 2)) {
3032
- matrix[i][j] = matrix[i - 2][j - 2] + 1;
3033
- } else {
3034
- matrix[i][j] = Math.min(matrix[i - 1][j - 1] + 1, Math.min(matrix[i][j - 1] + 1, matrix[i - 1][j] + 1));
3035
- }
3036
- }
3037
- }
3038
- }
3039
- return matrix[b.length][a.length];
3040
- }
3041
-
3042
- // ../../node_modules/yargs/build/lib/validation.js
3043
- var specialKeys = ["$0", "--", "_"];
3044
- function validation(yargs, usage2, shim2) {
3045
- const __ = shim2.y18n.__;
3046
- const __n = shim2.y18n.__n;
3047
- const self = {};
3048
- self.nonOptionCount = function nonOptionCount(argv) {
3049
- const demandedCommands = yargs.getDemandedCommands();
3050
- const positionalCount = argv._.length + (argv["--"] ? argv["--"].length : 0);
3051
- const _s = positionalCount - yargs.getInternalMethods().getContext().commands.length;
3052
- if (demandedCommands._ && (_s < demandedCommands._.min || _s > demandedCommands._.max)) {
3053
- if (_s < demandedCommands._.min) {
3054
- if (demandedCommands._.minMsg !== undefined) {
3055
- usage2.fail(demandedCommands._.minMsg ? demandedCommands._.minMsg.replace(/\$0/g, _s.toString()).replace(/\$1/, demandedCommands._.min.toString()) : null);
3056
- } else {
3057
- usage2.fail(__n("Not enough non-option arguments: got %s, need at least %s", "Not enough non-option arguments: got %s, need at least %s", _s, _s.toString(), demandedCommands._.min.toString()));
3058
- }
3059
- } else if (_s > demandedCommands._.max) {
3060
- if (demandedCommands._.maxMsg !== undefined) {
3061
- usage2.fail(demandedCommands._.maxMsg ? demandedCommands._.maxMsg.replace(/\$0/g, _s.toString()).replace(/\$1/, demandedCommands._.max.toString()) : null);
3062
- } else {
3063
- usage2.fail(__n("Too many non-option arguments: got %s, maximum of %s", "Too many non-option arguments: got %s, maximum of %s", _s, _s.toString(), demandedCommands._.max.toString()));
3064
- }
3065
- }
3066
- }
3067
- };
3068
- self.positionalCount = function positionalCount(required, observed) {
3069
- if (observed < required) {
3070
- usage2.fail(__n("Not enough non-option arguments: got %s, need at least %s", "Not enough non-option arguments: got %s, need at least %s", observed, observed + "", required + ""));
3071
- }
3072
- };
3073
- self.requiredArguments = function requiredArguments(argv, demandedOptions) {
3074
- let missing = null;
3075
- for (const key of Object.keys(demandedOptions)) {
3076
- if (!Object.prototype.hasOwnProperty.call(argv, key) || typeof argv[key] === "undefined") {
3077
- missing = missing || {};
3078
- missing[key] = demandedOptions[key];
3079
- }
3080
- }
3081
- if (missing) {
3082
- const customMsgs = [];
3083
- for (const key of Object.keys(missing)) {
3084
- const msg = missing[key];
3085
- if (msg && customMsgs.indexOf(msg) < 0) {
3086
- customMsgs.push(msg);
3087
- }
3088
- }
3089
- const customMsg = customMsgs.length ? `
3090
- ${customMsgs.join(`
3091
- `)}` : "";
3092
- usage2.fail(__n("Missing required argument: %s", "Missing required arguments: %s", Object.keys(missing).length, Object.keys(missing).join(", ") + customMsg));
3093
- }
3094
- };
3095
- self.unknownArguments = function unknownArguments(argv, aliases, positionalMap, isDefaultCommand, checkPositionals = true) {
3096
- var _a2;
3097
- const commandKeys = yargs.getInternalMethods().getCommandInstance().getCommands();
3098
- const unknown = [];
3099
- const currentContext = yargs.getInternalMethods().getContext();
3100
- Object.keys(argv).forEach((key) => {
3101
- if (!specialKeys.includes(key) && !Object.prototype.hasOwnProperty.call(positionalMap, key) && !Object.prototype.hasOwnProperty.call(yargs.getInternalMethods().getParseContext(), key) && !self.isValidAndSomeAliasIsNotNew(key, aliases)) {
3102
- unknown.push(key);
3103
- }
3104
- });
3105
- if (checkPositionals && (currentContext.commands.length > 0 || commandKeys.length > 0 || isDefaultCommand)) {
3106
- argv._.slice(currentContext.commands.length).forEach((key) => {
3107
- if (!commandKeys.includes("" + key)) {
3108
- unknown.push("" + key);
3109
- }
3110
- });
3111
- }
3112
- if (checkPositionals) {
3113
- const demandedCommands = yargs.getDemandedCommands();
3114
- const maxNonOptDemanded = ((_a2 = demandedCommands._) === null || _a2 === undefined ? undefined : _a2.max) || 0;
3115
- const expected = currentContext.commands.length + maxNonOptDemanded;
3116
- if (expected < argv._.length) {
3117
- argv._.slice(expected).forEach((key) => {
3118
- key = String(key);
3119
- if (!currentContext.commands.includes(key) && !unknown.includes(key)) {
3120
- unknown.push(key);
3121
- }
3122
- });
3123
- }
3124
- }
3125
- if (unknown.length) {
3126
- usage2.fail(__n("Unknown argument: %s", "Unknown arguments: %s", unknown.length, unknown.map((s) => s.trim() ? s : `"${s}"`).join(", ")));
3127
- }
3128
- };
3129
- self.unknownCommands = function unknownCommands(argv) {
3130
- const commandKeys = yargs.getInternalMethods().getCommandInstance().getCommands();
3131
- const unknown = [];
3132
- const currentContext = yargs.getInternalMethods().getContext();
3133
- if (currentContext.commands.length > 0 || commandKeys.length > 0) {
3134
- argv._.slice(currentContext.commands.length).forEach((key) => {
3135
- if (!commandKeys.includes("" + key)) {
3136
- unknown.push("" + key);
3137
- }
3138
- });
3139
- }
3140
- if (unknown.length > 0) {
3141
- usage2.fail(__n("Unknown command: %s", "Unknown commands: %s", unknown.length, unknown.join(", ")));
3142
- return true;
3143
- } else {
3144
- return false;
3145
- }
3146
- };
3147
- self.isValidAndSomeAliasIsNotNew = function isValidAndSomeAliasIsNotNew(key, aliases) {
3148
- if (!Object.prototype.hasOwnProperty.call(aliases, key)) {
3149
- return false;
3150
- }
3151
- const newAliases = yargs.parsed.newAliases;
3152
- return [key, ...aliases[key]].some((a) => !Object.prototype.hasOwnProperty.call(newAliases, a) || !newAliases[key]);
3153
- };
3154
- self.limitedChoices = function limitedChoices(argv) {
3155
- const options = yargs.getOptions();
3156
- const invalid = {};
3157
- if (!Object.keys(options.choices).length)
3158
- return;
3159
- Object.keys(argv).forEach((key) => {
3160
- if (specialKeys.indexOf(key) === -1 && Object.prototype.hasOwnProperty.call(options.choices, key)) {
3161
- [].concat(argv[key]).forEach((value) => {
3162
- if (options.choices[key].indexOf(value) === -1 && value !== undefined) {
3163
- invalid[key] = (invalid[key] || []).concat(value);
3164
- }
3165
- });
3166
- }
3167
- });
3168
- const invalidKeys = Object.keys(invalid);
3169
- if (!invalidKeys.length)
3170
- return;
3171
- let msg = __("Invalid values:");
3172
- invalidKeys.forEach((key) => {
3173
- msg += `
3174
- ${__("Argument: %s, Given: %s, Choices: %s", key, usage2.stringifiedValues(invalid[key]), usage2.stringifiedValues(options.choices[key]))}`;
3175
- });
3176
- usage2.fail(msg);
3177
- };
3178
- let implied = {};
3179
- self.implies = function implies(key, value) {
3180
- argsert("<string|object> [array|number|string]", [key, value], arguments.length);
3181
- if (typeof key === "object") {
3182
- Object.keys(key).forEach((k) => {
3183
- self.implies(k, key[k]);
3184
- });
3185
- } else {
3186
- yargs.global(key);
3187
- if (!implied[key]) {
3188
- implied[key] = [];
3189
- }
3190
- if (Array.isArray(value)) {
3191
- value.forEach((i) => self.implies(key, i));
3192
- } else {
3193
- assertNotStrictEqual(value, undefined, shim2);
3194
- implied[key].push(value);
3195
- }
3196
- }
3197
- };
3198
- self.getImplied = function getImplied() {
3199
- return implied;
3200
- };
3201
- function keyExists(argv, val) {
3202
- const num = Number(val);
3203
- val = isNaN(num) ? val : num;
3204
- if (typeof val === "number") {
3205
- val = argv._.length >= val;
3206
- } else if (val.match(/^--no-.+/)) {
3207
- val = val.match(/^--no-(.+)/)[1];
3208
- val = !Object.prototype.hasOwnProperty.call(argv, val);
3209
- } else {
3210
- val = Object.prototype.hasOwnProperty.call(argv, val);
3211
- }
3212
- return val;
3213
- }
3214
- self.implications = function implications(argv) {
3215
- const implyFail = [];
3216
- Object.keys(implied).forEach((key) => {
3217
- const origKey = key;
3218
- (implied[key] || []).forEach((value) => {
3219
- let key2 = origKey;
3220
- const origValue = value;
3221
- key2 = keyExists(argv, key2);
3222
- value = keyExists(argv, value);
3223
- if (key2 && !value) {
3224
- implyFail.push(` ${origKey} -> ${origValue}`);
3225
- }
3226
- });
3227
- });
3228
- if (implyFail.length) {
3229
- let msg = `${__("Implications failed:")}
3230
- `;
3231
- implyFail.forEach((value) => {
3232
- msg += value;
3233
- });
3234
- usage2.fail(msg);
3235
- }
3236
- };
3237
- let conflicting = {};
3238
- self.conflicts = function conflicts(key, value) {
3239
- argsert("<string|object> [array|string]", [key, value], arguments.length);
3240
- if (typeof key === "object") {
3241
- Object.keys(key).forEach((k) => {
3242
- self.conflicts(k, key[k]);
3243
- });
3244
- } else {
3245
- yargs.global(key);
3246
- if (!conflicting[key]) {
3247
- conflicting[key] = [];
3248
- }
3249
- if (Array.isArray(value)) {
3250
- value.forEach((i) => self.conflicts(key, i));
3251
- } else {
3252
- conflicting[key].push(value);
3253
- }
3254
- }
3255
- };
3256
- self.getConflicting = () => conflicting;
3257
- self.conflicting = function conflictingFn(argv) {
3258
- Object.keys(argv).forEach((key) => {
3259
- if (conflicting[key]) {
3260
- conflicting[key].forEach((value) => {
3261
- if (value && argv[key] !== undefined && argv[value] !== undefined) {
3262
- usage2.fail(__("Arguments %s and %s are mutually exclusive", key, value));
3263
- }
3264
- });
3265
- }
3266
- });
3267
- if (yargs.getInternalMethods().getParserConfiguration()["strip-dashed"]) {
3268
- Object.keys(conflicting).forEach((key) => {
3269
- conflicting[key].forEach((value) => {
3270
- if (value && argv[shim2.Parser.camelCase(key)] !== undefined && argv[shim2.Parser.camelCase(value)] !== undefined) {
3271
- usage2.fail(__("Arguments %s and %s are mutually exclusive", key, value));
3272
- }
3273
- });
3274
- });
3275
- }
3276
- };
3277
- self.recommendCommands = function recommendCommands(cmd, potentialCommands) {
3278
- const threshold = 3;
3279
- potentialCommands = potentialCommands.sort((a, b) => b.length - a.length);
3280
- let recommended = null;
3281
- let bestDistance = Infinity;
3282
- for (let i = 0, candidate;(candidate = potentialCommands[i]) !== undefined; i++) {
3283
- const d = levenshtein(cmd, candidate);
3284
- if (d <= threshold && d < bestDistance) {
3285
- bestDistance = d;
3286
- recommended = candidate;
3287
- }
3288
- }
3289
- if (recommended)
3290
- usage2.fail(__("Did you mean %s?", recommended));
3291
- };
3292
- self.reset = function reset(localLookup) {
3293
- implied = objFilter(implied, (k) => !localLookup[k]);
3294
- conflicting = objFilter(conflicting, (k) => !localLookup[k]);
3295
- return self;
3296
- };
3297
- const frozens = [];
3298
- self.freeze = function freeze() {
3299
- frozens.push({
3300
- implied,
3301
- conflicting
3302
- });
3303
- };
3304
- self.unfreeze = function unfreeze() {
3305
- const frozen = frozens.pop();
3306
- assertNotStrictEqual(frozen, undefined, shim2);
3307
- ({ implied, conflicting } = frozen);
3308
- };
3309
- return self;
3310
- }
3311
-
3312
- // ../../node_modules/yargs/build/lib/utils/apply-extends.js
3313
- var previouslyVisitedConfigs = [];
3314
- var shim2;
3315
- function applyExtends(config, cwd, mergeExtends, _shim) {
3316
- shim2 = _shim;
3317
- let defaultConfig = {};
3318
- if (Object.prototype.hasOwnProperty.call(config, "extends")) {
3319
- if (typeof config.extends !== "string")
3320
- return defaultConfig;
3321
- const isPath = /\.json|\..*rc$/.test(config.extends);
3322
- let pathToDefault = null;
3323
- if (!isPath) {
3324
- try {
3325
- pathToDefault = __require.resolve(config.extends);
3326
- } catch (_err) {
3327
- return config;
3328
- }
3329
- } else {
3330
- pathToDefault = getPathToDefaultConfig(cwd, config.extends);
3331
- }
3332
- checkForCircularExtends(pathToDefault);
3333
- previouslyVisitedConfigs.push(pathToDefault);
3334
- defaultConfig = isPath ? JSON.parse(shim2.readFileSync(pathToDefault, "utf8")) : __require(config.extends);
3335
- delete config.extends;
3336
- defaultConfig = applyExtends(defaultConfig, shim2.path.dirname(pathToDefault), mergeExtends, shim2);
3337
- }
3338
- previouslyVisitedConfigs = [];
3339
- return mergeExtends ? mergeDeep(defaultConfig, config) : Object.assign({}, defaultConfig, config);
3340
- }
3341
- function checkForCircularExtends(cfgPath) {
3342
- if (previouslyVisitedConfigs.indexOf(cfgPath) > -1) {
3343
- throw new YError(`Circular extended configurations: '${cfgPath}'.`);
3344
- }
3345
- }
3346
- function getPathToDefaultConfig(cwd, pathToExtend) {
3347
- return shim2.path.resolve(cwd, pathToExtend);
3348
- }
3349
- function mergeDeep(config1, config2) {
3350
- const target = {};
3351
- function isObject(obj) {
3352
- return obj && typeof obj === "object" && !Array.isArray(obj);
3353
- }
3354
- Object.assign(target, config1);
3355
- for (const key of Object.keys(config2)) {
3356
- if (isObject(config2[key]) && isObject(target[key])) {
3357
- target[key] = mergeDeep(config1[key], config2[key]);
3358
- } else {
3359
- target[key] = config2[key];
3360
- }
3361
- }
3362
- return target;
3363
- }
3364
-
3365
- // ../../node_modules/yargs/build/lib/yargs-factory.js
3366
- var __classPrivateFieldSet = function(receiver, state, value, kind, f) {
3367
- if (kind === "m")
3368
- throw new TypeError("Private method is not writable");
3369
- if (kind === "a" && !f)
3370
- throw new TypeError("Private accessor was defined without a setter");
3371
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
3372
- throw new TypeError("Cannot write private member to an object whose class did not declare it");
3373
- return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
3374
- };
3375
- var __classPrivateFieldGet = function(receiver, state, kind, f) {
3376
- if (kind === "a" && !f)
3377
- throw new TypeError("Private accessor was defined without a getter");
3378
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
3379
- throw new TypeError("Cannot read private member from an object whose class did not declare it");
3380
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
3381
- };
3382
- var _YargsInstance_command;
3383
- var _YargsInstance_cwd;
3384
- var _YargsInstance_context;
3385
- var _YargsInstance_completion;
3386
- var _YargsInstance_completionCommand;
3387
- var _YargsInstance_defaultShowHiddenOpt;
3388
- var _YargsInstance_exitError;
3389
- var _YargsInstance_detectLocale;
3390
- var _YargsInstance_emittedWarnings;
3391
- var _YargsInstance_exitProcess;
3392
- var _YargsInstance_frozens;
3393
- var _YargsInstance_globalMiddleware;
3394
- var _YargsInstance_groups;
3395
- var _YargsInstance_hasOutput;
3396
- var _YargsInstance_helpOpt;
3397
- var _YargsInstance_isGlobalContext;
3398
- var _YargsInstance_logger;
3399
- var _YargsInstance_output;
3400
- var _YargsInstance_options;
3401
- var _YargsInstance_parentRequire;
3402
- var _YargsInstance_parserConfig;
3403
- var _YargsInstance_parseFn;
3404
- var _YargsInstance_parseContext;
3405
- var _YargsInstance_pkgs;
3406
- var _YargsInstance_preservedGroups;
3407
- var _YargsInstance_processArgs;
3408
- var _YargsInstance_recommendCommands;
3409
- var _YargsInstance_shim;
3410
- var _YargsInstance_strict;
3411
- var _YargsInstance_strictCommands;
3412
- var _YargsInstance_strictOptions;
3413
- var _YargsInstance_usage;
3414
- var _YargsInstance_usageConfig;
3415
- var _YargsInstance_versionOpt;
3416
- var _YargsInstance_validation;
3417
- function YargsFactory(_shim) {
3418
- return (processArgs = [], cwd = _shim.process.cwd(), parentRequire) => {
3419
- const yargs = new YargsInstance(processArgs, cwd, parentRequire, _shim);
3420
- Object.defineProperty(yargs, "argv", {
3421
- get: () => {
3422
- return yargs.parse();
3423
- },
3424
- enumerable: true
3425
- });
3426
- yargs.help();
3427
- yargs.version();
3428
- return yargs;
3429
- };
3430
- }
3431
- var kCopyDoubleDash = Symbol("copyDoubleDash");
3432
- var kCreateLogger = Symbol("copyDoubleDash");
3433
- var kDeleteFromParserHintObject = Symbol("deleteFromParserHintObject");
3434
- var kEmitWarning = Symbol("emitWarning");
3435
- var kFreeze = Symbol("freeze");
3436
- var kGetDollarZero = Symbol("getDollarZero");
3437
- var kGetParserConfiguration = Symbol("getParserConfiguration");
3438
- var kGetUsageConfiguration = Symbol("getUsageConfiguration");
3439
- var kGuessLocale = Symbol("guessLocale");
3440
- var kGuessVersion = Symbol("guessVersion");
3441
- var kParsePositionalNumbers = Symbol("parsePositionalNumbers");
3442
- var kPkgUp = Symbol("pkgUp");
3443
- var kPopulateParserHintArray = Symbol("populateParserHintArray");
3444
- var kPopulateParserHintSingleValueDictionary = Symbol("populateParserHintSingleValueDictionary");
3445
- var kPopulateParserHintArrayDictionary = Symbol("populateParserHintArrayDictionary");
3446
- var kPopulateParserHintDictionary = Symbol("populateParserHintDictionary");
3447
- var kSanitizeKey = Symbol("sanitizeKey");
3448
- var kSetKey = Symbol("setKey");
3449
- var kUnfreeze = Symbol("unfreeze");
3450
- var kValidateAsync = Symbol("validateAsync");
3451
- var kGetCommandInstance = Symbol("getCommandInstance");
3452
- var kGetContext = Symbol("getContext");
3453
- var kGetHasOutput = Symbol("getHasOutput");
3454
- var kGetLoggerInstance = Symbol("getLoggerInstance");
3455
- var kGetParseContext = Symbol("getParseContext");
3456
- var kGetUsageInstance = Symbol("getUsageInstance");
3457
- var kGetValidationInstance = Symbol("getValidationInstance");
3458
- var kHasParseCallback = Symbol("hasParseCallback");
3459
- var kIsGlobalContext = Symbol("isGlobalContext");
3460
- var kPostProcess = Symbol("postProcess");
3461
- var kRebase = Symbol("rebase");
3462
- var kReset = Symbol("reset");
3463
- var kRunYargsParserAndExecuteCommands = Symbol("runYargsParserAndExecuteCommands");
3464
- var kRunValidation = Symbol("runValidation");
3465
- var kSetHasOutput = Symbol("setHasOutput");
3466
- var kTrackManuallySetKeys = Symbol("kTrackManuallySetKeys");
3467
-
3468
- class YargsInstance {
3469
- constructor(processArgs = [], cwd, parentRequire, shim3) {
3470
- this.customScriptName = false;
3471
- this.parsed = false;
3472
- _YargsInstance_command.set(this, undefined);
3473
- _YargsInstance_cwd.set(this, undefined);
3474
- _YargsInstance_context.set(this, { commands: [], fullCommands: [] });
3475
- _YargsInstance_completion.set(this, null);
3476
- _YargsInstance_completionCommand.set(this, null);
3477
- _YargsInstance_defaultShowHiddenOpt.set(this, "show-hidden");
3478
- _YargsInstance_exitError.set(this, null);
3479
- _YargsInstance_detectLocale.set(this, true);
3480
- _YargsInstance_emittedWarnings.set(this, {});
3481
- _YargsInstance_exitProcess.set(this, true);
3482
- _YargsInstance_frozens.set(this, []);
3483
- _YargsInstance_globalMiddleware.set(this, undefined);
3484
- _YargsInstance_groups.set(this, {});
3485
- _YargsInstance_hasOutput.set(this, false);
3486
- _YargsInstance_helpOpt.set(this, null);
3487
- _YargsInstance_isGlobalContext.set(this, true);
3488
- _YargsInstance_logger.set(this, undefined);
3489
- _YargsInstance_output.set(this, "");
3490
- _YargsInstance_options.set(this, undefined);
3491
- _YargsInstance_parentRequire.set(this, undefined);
3492
- _YargsInstance_parserConfig.set(this, {});
3493
- _YargsInstance_parseFn.set(this, null);
3494
- _YargsInstance_parseContext.set(this, null);
3495
- _YargsInstance_pkgs.set(this, {});
3496
- _YargsInstance_preservedGroups.set(this, {});
3497
- _YargsInstance_processArgs.set(this, undefined);
3498
- _YargsInstance_recommendCommands.set(this, false);
3499
- _YargsInstance_shim.set(this, undefined);
3500
- _YargsInstance_strict.set(this, false);
3501
- _YargsInstance_strictCommands.set(this, false);
3502
- _YargsInstance_strictOptions.set(this, false);
3503
- _YargsInstance_usage.set(this, undefined);
3504
- _YargsInstance_usageConfig.set(this, {});
3505
- _YargsInstance_versionOpt.set(this, null);
3506
- _YargsInstance_validation.set(this, undefined);
3507
- __classPrivateFieldSet(this, _YargsInstance_shim, shim3, "f");
3508
- __classPrivateFieldSet(this, _YargsInstance_processArgs, processArgs, "f");
3509
- __classPrivateFieldSet(this, _YargsInstance_cwd, cwd, "f");
3510
- __classPrivateFieldSet(this, _YargsInstance_parentRequire, parentRequire, "f");
3511
- __classPrivateFieldSet(this, _YargsInstance_globalMiddleware, new GlobalMiddleware(this), "f");
3512
- this.$0 = this[kGetDollarZero]();
3513
- this[kReset]();
3514
- __classPrivateFieldSet(this, _YargsInstance_command, __classPrivateFieldGet(this, _YargsInstance_command, "f"), "f");
3515
- __classPrivateFieldSet(this, _YargsInstance_usage, __classPrivateFieldGet(this, _YargsInstance_usage, "f"), "f");
3516
- __classPrivateFieldSet(this, _YargsInstance_validation, __classPrivateFieldGet(this, _YargsInstance_validation, "f"), "f");
3517
- __classPrivateFieldSet(this, _YargsInstance_options, __classPrivateFieldGet(this, _YargsInstance_options, "f"), "f");
3518
- __classPrivateFieldGet(this, _YargsInstance_options, "f").showHiddenOpt = __classPrivateFieldGet(this, _YargsInstance_defaultShowHiddenOpt, "f");
3519
- __classPrivateFieldSet(this, _YargsInstance_logger, this[kCreateLogger](), "f");
3520
- }
3521
- addHelpOpt(opt, msg) {
3522
- const defaultHelpOpt = "help";
3523
- argsert("[string|boolean] [string]", [opt, msg], arguments.length);
3524
- if (__classPrivateFieldGet(this, _YargsInstance_helpOpt, "f")) {
3525
- this[kDeleteFromParserHintObject](__classPrivateFieldGet(this, _YargsInstance_helpOpt, "f"));
3526
- __classPrivateFieldSet(this, _YargsInstance_helpOpt, null, "f");
3527
- }
3528
- if (opt === false && msg === undefined)
3529
- return this;
3530
- __classPrivateFieldSet(this, _YargsInstance_helpOpt, typeof opt === "string" ? opt : defaultHelpOpt, "f");
3531
- this.boolean(__classPrivateFieldGet(this, _YargsInstance_helpOpt, "f"));
3532
- this.describe(__classPrivateFieldGet(this, _YargsInstance_helpOpt, "f"), msg || __classPrivateFieldGet(this, _YargsInstance_usage, "f").deferY18nLookup("Show help"));
3533
- return this;
3534
- }
3535
- help(opt, msg) {
3536
- return this.addHelpOpt(opt, msg);
3537
- }
3538
- addShowHiddenOpt(opt, msg) {
3539
- argsert("[string|boolean] [string]", [opt, msg], arguments.length);
3540
- if (opt === false && msg === undefined)
3541
- return this;
3542
- const showHiddenOpt = typeof opt === "string" ? opt : __classPrivateFieldGet(this, _YargsInstance_defaultShowHiddenOpt, "f");
3543
- this.boolean(showHiddenOpt);
3544
- this.describe(showHiddenOpt, msg || __classPrivateFieldGet(this, _YargsInstance_usage, "f").deferY18nLookup("Show hidden options"));
3545
- __classPrivateFieldGet(this, _YargsInstance_options, "f").showHiddenOpt = showHiddenOpt;
3546
- return this;
3547
- }
3548
- showHidden(opt, msg) {
3549
- return this.addShowHiddenOpt(opt, msg);
3550
- }
3551
- alias(key, value) {
3552
- argsert("<object|string|array> [string|array]", [key, value], arguments.length);
3553
- this[kPopulateParserHintArrayDictionary](this.alias.bind(this), "alias", key, value);
3554
- return this;
3555
- }
3556
- array(keys) {
3557
- argsert("<array|string>", [keys], arguments.length);
3558
- this[kPopulateParserHintArray]("array", keys);
3559
- this[kTrackManuallySetKeys](keys);
3560
- return this;
3561
- }
3562
- boolean(keys) {
3563
- argsert("<array|string>", [keys], arguments.length);
3564
- this[kPopulateParserHintArray]("boolean", keys);
3565
- this[kTrackManuallySetKeys](keys);
3566
- return this;
3567
- }
3568
- check(f, global) {
3569
- argsert("<function> [boolean]", [f, global], arguments.length);
3570
- this.middleware((argv, _yargs) => {
3571
- return maybeAsyncResult(() => {
3572
- return f(argv, _yargs.getOptions());
3573
- }, (result) => {
3574
- if (!result) {
3575
- __classPrivateFieldGet(this, _YargsInstance_usage, "f").fail(__classPrivateFieldGet(this, _YargsInstance_shim, "f").y18n.__("Argument check failed: %s", f.toString()));
3576
- } else if (typeof result === "string" || result instanceof Error) {
3577
- __classPrivateFieldGet(this, _YargsInstance_usage, "f").fail(result.toString(), result);
3578
- }
3579
- return argv;
3580
- }, (err) => {
3581
- __classPrivateFieldGet(this, _YargsInstance_usage, "f").fail(err.message ? err.message : err.toString(), err);
3582
- return argv;
3583
- });
3584
- }, false, global);
3585
- return this;
3586
- }
3587
- choices(key, value) {
3588
- argsert("<object|string|array> [string|array]", [key, value], arguments.length);
3589
- this[kPopulateParserHintArrayDictionary](this.choices.bind(this), "choices", key, value);
3590
- return this;
3591
- }
3592
- coerce(keys, value) {
3593
- argsert("<object|string|array> [function]", [keys, value], arguments.length);
3594
- if (Array.isArray(keys)) {
3595
- if (!value) {
3596
- throw new YError("coerce callback must be provided");
3597
- }
3598
- for (const key of keys) {
3599
- this.coerce(key, value);
3600
- }
3601
- return this;
3602
- } else if (typeof keys === "object") {
3603
- for (const key of Object.keys(keys)) {
3604
- this.coerce(key, keys[key]);
3605
- }
3606
- return this;
3607
- }
3608
- if (!value) {
3609
- throw new YError("coerce callback must be provided");
3610
- }
3611
- __classPrivateFieldGet(this, _YargsInstance_options, "f").key[keys] = true;
3612
- __classPrivateFieldGet(this, _YargsInstance_globalMiddleware, "f").addCoerceMiddleware((argv, yargs) => {
3613
- let aliases;
3614
- const shouldCoerce = Object.prototype.hasOwnProperty.call(argv, keys);
3615
- if (!shouldCoerce) {
3616
- return argv;
3617
- }
3618
- return maybeAsyncResult(() => {
3619
- aliases = yargs.getAliases();
3620
- return value(argv[keys]);
3621
- }, (result) => {
3622
- argv[keys] = result;
3623
- const stripAliased = yargs.getInternalMethods().getParserConfiguration()["strip-aliased"];
3624
- if (aliases[keys] && stripAliased !== true) {
3625
- for (const alias of aliases[keys]) {
3626
- argv[alias] = result;
3627
- }
3628
- }
3629
- return argv;
3630
- }, (err) => {
3631
- throw new YError(err.message);
3632
- });
3633
- }, keys);
3634
- return this;
3635
- }
3636
- conflicts(key1, key2) {
3637
- argsert("<string|object> [string|array]", [key1, key2], arguments.length);
3638
- __classPrivateFieldGet(this, _YargsInstance_validation, "f").conflicts(key1, key2);
3639
- return this;
3640
- }
3641
- config(key = "config", msg, parseFn) {
3642
- argsert("[object|string] [string|function] [function]", [key, msg, parseFn], arguments.length);
3643
- if (typeof key === "object" && !Array.isArray(key)) {
3644
- key = applyExtends(key, __classPrivateFieldGet(this, _YargsInstance_cwd, "f"), this[kGetParserConfiguration]()["deep-merge-config"] || false, __classPrivateFieldGet(this, _YargsInstance_shim, "f"));
3645
- __classPrivateFieldGet(this, _YargsInstance_options, "f").configObjects = (__classPrivateFieldGet(this, _YargsInstance_options, "f").configObjects || []).concat(key);
3646
- return this;
3647
- }
3648
- if (typeof msg === "function") {
3649
- parseFn = msg;
3650
- msg = undefined;
3651
- }
3652
- this.describe(key, msg || __classPrivateFieldGet(this, _YargsInstance_usage, "f").deferY18nLookup("Path to JSON config file"));
3653
- (Array.isArray(key) ? key : [key]).forEach((k) => {
3654
- __classPrivateFieldGet(this, _YargsInstance_options, "f").config[k] = parseFn || true;
3655
- });
3656
- return this;
3657
- }
3658
- completion(cmd, desc, fn) {
3659
- argsert("[string] [string|boolean|function] [function]", [cmd, desc, fn], arguments.length);
3660
- if (typeof desc === "function") {
3661
- fn = desc;
3662
- desc = undefined;
3663
- }
3664
- __classPrivateFieldSet(this, _YargsInstance_completionCommand, cmd || __classPrivateFieldGet(this, _YargsInstance_completionCommand, "f") || "completion", "f");
3665
- if (!desc && desc !== false) {
3666
- desc = "generate completion script";
3667
- }
3668
- this.command(__classPrivateFieldGet(this, _YargsInstance_completionCommand, "f"), desc);
3669
- if (fn)
3670
- __classPrivateFieldGet(this, _YargsInstance_completion, "f").registerFunction(fn);
3671
- return this;
3672
- }
3673
- command(cmd, description, builder, handler, middlewares, deprecated) {
3674
- argsert("<string|array|object> [string|boolean] [function|object] [function] [array] [boolean|string]", [cmd, description, builder, handler, middlewares, deprecated], arguments.length);
3675
- __classPrivateFieldGet(this, _YargsInstance_command, "f").addHandler(cmd, description, builder, handler, middlewares, deprecated);
3676
- return this;
3677
- }
3678
- commands(cmd, description, builder, handler, middlewares, deprecated) {
3679
- return this.command(cmd, description, builder, handler, middlewares, deprecated);
3680
- }
3681
- commandDir(dir, opts) {
3682
- argsert("<string> [object]", [dir, opts], arguments.length);
3683
- const req = __classPrivateFieldGet(this, _YargsInstance_parentRequire, "f") || __classPrivateFieldGet(this, _YargsInstance_shim, "f").require;
3684
- __classPrivateFieldGet(this, _YargsInstance_command, "f").addDirectory(dir, req, __classPrivateFieldGet(this, _YargsInstance_shim, "f").getCallerFile(), opts);
3685
- return this;
3686
- }
3687
- count(keys) {
3688
- argsert("<array|string>", [keys], arguments.length);
3689
- this[kPopulateParserHintArray]("count", keys);
3690
- this[kTrackManuallySetKeys](keys);
3691
- return this;
3692
- }
3693
- default(key, value, defaultDescription) {
3694
- argsert("<object|string|array> [*] [string]", [key, value, defaultDescription], arguments.length);
3695
- if (defaultDescription) {
3696
- assertSingleKey(key, __classPrivateFieldGet(this, _YargsInstance_shim, "f"));
3697
- __classPrivateFieldGet(this, _YargsInstance_options, "f").defaultDescription[key] = defaultDescription;
3698
- }
3699
- if (typeof value === "function") {
3700
- assertSingleKey(key, __classPrivateFieldGet(this, _YargsInstance_shim, "f"));
3701
- if (!__classPrivateFieldGet(this, _YargsInstance_options, "f").defaultDescription[key])
3702
- __classPrivateFieldGet(this, _YargsInstance_options, "f").defaultDescription[key] = __classPrivateFieldGet(this, _YargsInstance_usage, "f").functionDescription(value);
3703
- value = value.call();
3704
- }
3705
- this[kPopulateParserHintSingleValueDictionary](this.default.bind(this), "default", key, value);
3706
- return this;
3707
- }
3708
- defaults(key, value, defaultDescription) {
3709
- return this.default(key, value, defaultDescription);
3710
- }
3711
- demandCommand(min = 1, max, minMsg, maxMsg) {
3712
- argsert("[number] [number|string] [string|null|undefined] [string|null|undefined]", [min, max, minMsg, maxMsg], arguments.length);
3713
- if (typeof max !== "number") {
3714
- minMsg = max;
3715
- max = Infinity;
3716
- }
3717
- this.global("_", false);
3718
- __classPrivateFieldGet(this, _YargsInstance_options, "f").demandedCommands._ = {
3719
- min,
3720
- max,
3721
- minMsg,
3722
- maxMsg
3723
- };
3724
- return this;
3725
- }
3726
- demand(keys, max, msg) {
3727
- if (Array.isArray(max)) {
3728
- max.forEach((key) => {
3729
- assertNotStrictEqual(msg, true, __classPrivateFieldGet(this, _YargsInstance_shim, "f"));
3730
- this.demandOption(key, msg);
3731
- });
3732
- max = Infinity;
3733
- } else if (typeof max !== "number") {
3734
- msg = max;
3735
- max = Infinity;
3736
- }
3737
- if (typeof keys === "number") {
3738
- assertNotStrictEqual(msg, true, __classPrivateFieldGet(this, _YargsInstance_shim, "f"));
3739
- this.demandCommand(keys, max, msg, msg);
3740
- } else if (Array.isArray(keys)) {
3741
- keys.forEach((key) => {
3742
- assertNotStrictEqual(msg, true, __classPrivateFieldGet(this, _YargsInstance_shim, "f"));
3743
- this.demandOption(key, msg);
3744
- });
3745
- } else {
3746
- if (typeof msg === "string") {
3747
- this.demandOption(keys, msg);
3748
- } else if (msg === true || typeof msg === "undefined") {
3749
- this.demandOption(keys);
3750
- }
3751
- }
3752
- return this;
3753
- }
3754
- demandOption(keys, msg) {
3755
- argsert("<object|string|array> [string]", [keys, msg], arguments.length);
3756
- this[kPopulateParserHintSingleValueDictionary](this.demandOption.bind(this), "demandedOptions", keys, msg);
3757
- return this;
3758
- }
3759
- deprecateOption(option, message) {
3760
- argsert("<string> [string|boolean]", [option, message], arguments.length);
3761
- __classPrivateFieldGet(this, _YargsInstance_options, "f").deprecatedOptions[option] = message;
3762
- return this;
3763
- }
3764
- describe(keys, description) {
3765
- argsert("<object|string|array> [string]", [keys, description], arguments.length);
3766
- this[kSetKey](keys, true);
3767
- __classPrivateFieldGet(this, _YargsInstance_usage, "f").describe(keys, description);
3768
- return this;
3769
- }
3770
- detectLocale(detect) {
3771
- argsert("<boolean>", [detect], arguments.length);
3772
- __classPrivateFieldSet(this, _YargsInstance_detectLocale, detect, "f");
3773
- return this;
3774
- }
3775
- env(prefix) {
3776
- argsert("[string|boolean]", [prefix], arguments.length);
3777
- if (prefix === false)
3778
- delete __classPrivateFieldGet(this, _YargsInstance_options, "f").envPrefix;
3779
- else
3780
- __classPrivateFieldGet(this, _YargsInstance_options, "f").envPrefix = prefix || "";
3781
- return this;
3782
- }
3783
- epilogue(msg) {
3784
- argsert("<string>", [msg], arguments.length);
3785
- __classPrivateFieldGet(this, _YargsInstance_usage, "f").epilog(msg);
3786
- return this;
3787
- }
3788
- epilog(msg) {
3789
- return this.epilogue(msg);
3790
- }
3791
- example(cmd, description) {
3792
- argsert("<string|array> [string]", [cmd, description], arguments.length);
3793
- if (Array.isArray(cmd)) {
3794
- cmd.forEach((exampleParams) => this.example(...exampleParams));
3795
- } else {
3796
- __classPrivateFieldGet(this, _YargsInstance_usage, "f").example(cmd, description);
3797
- }
3798
- return this;
3799
- }
3800
- exit(code, err) {
3801
- __classPrivateFieldSet(this, _YargsInstance_hasOutput, true, "f");
3802
- __classPrivateFieldSet(this, _YargsInstance_exitError, err, "f");
3803
- if (__classPrivateFieldGet(this, _YargsInstance_exitProcess, "f"))
3804
- __classPrivateFieldGet(this, _YargsInstance_shim, "f").process.exit(code);
3805
- }
3806
- exitProcess(enabled = true) {
3807
- argsert("[boolean]", [enabled], arguments.length);
3808
- __classPrivateFieldSet(this, _YargsInstance_exitProcess, enabled, "f");
3809
- return this;
3810
- }
3811
- fail(f) {
3812
- argsert("<function|boolean>", [f], arguments.length);
3813
- if (typeof f === "boolean" && f !== false) {
3814
- throw new YError("Invalid first argument. Expected function or boolean 'false'");
3815
- }
3816
- __classPrivateFieldGet(this, _YargsInstance_usage, "f").failFn(f);
3817
- return this;
3818
- }
3819
- getAliases() {
3820
- return this.parsed ? this.parsed.aliases : {};
3821
- }
3822
- async getCompletion(args, done) {
3823
- argsert("<array> [function]", [args, done], arguments.length);
3824
- if (!done) {
3825
- return new Promise((resolve5, reject) => {
3826
- __classPrivateFieldGet(this, _YargsInstance_completion, "f").getCompletion(args, (err, completions) => {
3827
- if (err)
3828
- reject(err);
3829
- else
3830
- resolve5(completions);
3831
- });
3832
- });
3833
- } else {
3834
- return __classPrivateFieldGet(this, _YargsInstance_completion, "f").getCompletion(args, done);
3835
- }
3836
- }
3837
- getDemandedOptions() {
3838
- argsert([], 0);
3839
- return __classPrivateFieldGet(this, _YargsInstance_options, "f").demandedOptions;
3840
- }
3841
- getDemandedCommands() {
3842
- argsert([], 0);
3843
- return __classPrivateFieldGet(this, _YargsInstance_options, "f").demandedCommands;
3844
- }
3845
- getDeprecatedOptions() {
3846
- argsert([], 0);
3847
- return __classPrivateFieldGet(this, _YargsInstance_options, "f").deprecatedOptions;
3848
- }
3849
- getDetectLocale() {
3850
- return __classPrivateFieldGet(this, _YargsInstance_detectLocale, "f");
3851
- }
3852
- getExitProcess() {
3853
- return __classPrivateFieldGet(this, _YargsInstance_exitProcess, "f");
3854
- }
3855
- getGroups() {
3856
- return Object.assign({}, __classPrivateFieldGet(this, _YargsInstance_groups, "f"), __classPrivateFieldGet(this, _YargsInstance_preservedGroups, "f"));
3857
- }
3858
- getHelp() {
3859
- __classPrivateFieldSet(this, _YargsInstance_hasOutput, true, "f");
3860
- if (!__classPrivateFieldGet(this, _YargsInstance_usage, "f").hasCachedHelpMessage()) {
3861
- if (!this.parsed) {
3862
- const parse = this[kRunYargsParserAndExecuteCommands](__classPrivateFieldGet(this, _YargsInstance_processArgs, "f"), undefined, undefined, 0, true);
3863
- if (isPromise(parse)) {
3864
- return parse.then(() => {
3865
- return __classPrivateFieldGet(this, _YargsInstance_usage, "f").help();
3866
- });
3867
- }
3868
- }
3869
- const builderResponse = __classPrivateFieldGet(this, _YargsInstance_command, "f").runDefaultBuilderOn(this);
3870
- if (isPromise(builderResponse)) {
3871
- return builderResponse.then(() => {
3872
- return __classPrivateFieldGet(this, _YargsInstance_usage, "f").help();
3873
- });
3874
- }
3875
- }
3876
- return Promise.resolve(__classPrivateFieldGet(this, _YargsInstance_usage, "f").help());
3877
- }
3878
- getOptions() {
3879
- return __classPrivateFieldGet(this, _YargsInstance_options, "f");
3880
- }
3881
- getStrict() {
3882
- return __classPrivateFieldGet(this, _YargsInstance_strict, "f");
3883
- }
3884
- getStrictCommands() {
3885
- return __classPrivateFieldGet(this, _YargsInstance_strictCommands, "f");
3886
- }
3887
- getStrictOptions() {
3888
- return __classPrivateFieldGet(this, _YargsInstance_strictOptions, "f");
3889
- }
3890
- global(globals, global) {
3891
- argsert("<string|array> [boolean]", [globals, global], arguments.length);
3892
- globals = [].concat(globals);
3893
- if (global !== false) {
3894
- __classPrivateFieldGet(this, _YargsInstance_options, "f").local = __classPrivateFieldGet(this, _YargsInstance_options, "f").local.filter((l) => globals.indexOf(l) === -1);
3895
- } else {
3896
- globals.forEach((g) => {
3897
- if (!__classPrivateFieldGet(this, _YargsInstance_options, "f").local.includes(g))
3898
- __classPrivateFieldGet(this, _YargsInstance_options, "f").local.push(g);
3899
- });
3900
- }
3901
- return this;
3902
- }
3903
- group(opts, groupName) {
3904
- argsert("<string|array> <string>", [opts, groupName], arguments.length);
3905
- const existing = __classPrivateFieldGet(this, _YargsInstance_preservedGroups, "f")[groupName] || __classPrivateFieldGet(this, _YargsInstance_groups, "f")[groupName];
3906
- if (__classPrivateFieldGet(this, _YargsInstance_preservedGroups, "f")[groupName]) {
3907
- delete __classPrivateFieldGet(this, _YargsInstance_preservedGroups, "f")[groupName];
3908
- }
3909
- const seen = {};
3910
- __classPrivateFieldGet(this, _YargsInstance_groups, "f")[groupName] = (existing || []).concat(opts).filter((key) => {
3911
- if (seen[key])
3912
- return false;
3913
- return seen[key] = true;
3914
- });
3915
- return this;
3916
- }
3917
- hide(key) {
3918
- argsert("<string>", [key], arguments.length);
3919
- __classPrivateFieldGet(this, _YargsInstance_options, "f").hiddenOptions.push(key);
3920
- return this;
3921
- }
3922
- implies(key, value) {
3923
- argsert("<string|object> [number|string|array]", [key, value], arguments.length);
3924
- __classPrivateFieldGet(this, _YargsInstance_validation, "f").implies(key, value);
3925
- return this;
3926
- }
3927
- locale(locale) {
3928
- argsert("[string]", [locale], arguments.length);
3929
- if (locale === undefined) {
3930
- this[kGuessLocale]();
3931
- return __classPrivateFieldGet(this, _YargsInstance_shim, "f").y18n.getLocale();
3932
- }
3933
- __classPrivateFieldSet(this, _YargsInstance_detectLocale, false, "f");
3934
- __classPrivateFieldGet(this, _YargsInstance_shim, "f").y18n.setLocale(locale);
3935
- return this;
3936
- }
3937
- middleware(callback, applyBeforeValidation, global) {
3938
- return __classPrivateFieldGet(this, _YargsInstance_globalMiddleware, "f").addMiddleware(callback, !!applyBeforeValidation, global);
3939
- }
3940
- nargs(key, value) {
3941
- argsert("<string|object|array> [number]", [key, value], arguments.length);
3942
- this[kPopulateParserHintSingleValueDictionary](this.nargs.bind(this), "narg", key, value);
3943
- return this;
3944
- }
3945
- normalize(keys) {
3946
- argsert("<array|string>", [keys], arguments.length);
3947
- this[kPopulateParserHintArray]("normalize", keys);
3948
- return this;
3949
- }
3950
- number(keys) {
3951
- argsert("<array|string>", [keys], arguments.length);
3952
- this[kPopulateParserHintArray]("number", keys);
3953
- this[kTrackManuallySetKeys](keys);
3954
- return this;
3955
- }
3956
- option(key, opt) {
3957
- argsert("<string|object> [object]", [key, opt], arguments.length);
3958
- if (typeof key === "object") {
3959
- Object.keys(key).forEach((k) => {
3960
- this.options(k, key[k]);
3961
- });
3962
- } else {
3963
- if (typeof opt !== "object") {
3964
- opt = {};
3965
- }
3966
- this[kTrackManuallySetKeys](key);
3967
- if (__classPrivateFieldGet(this, _YargsInstance_versionOpt, "f") && (key === "version" || (opt === null || opt === undefined ? undefined : opt.alias) === "version")) {
3968
- this[kEmitWarning]([
3969
- '"version" is a reserved word.',
3970
- "Please do one of the following:",
3971
- '- Disable version with `yargs.version(false)` if using "version" as an option',
3972
- "- Use the built-in `yargs.version` method instead (if applicable)",
3973
- "- Use a different option key",
3974
- "https://yargs.js.org/docs/#api-reference-version"
3975
- ].join(`
3976
- `), undefined, "versionWarning");
3977
- }
3978
- __classPrivateFieldGet(this, _YargsInstance_options, "f").key[key] = true;
3979
- if (opt.alias)
3980
- this.alias(key, opt.alias);
3981
- const deprecate = opt.deprecate || opt.deprecated;
3982
- if (deprecate) {
3983
- this.deprecateOption(key, deprecate);
3984
- }
3985
- const demand = opt.demand || opt.required || opt.require;
3986
- if (demand) {
3987
- this.demand(key, demand);
3988
- }
3989
- if (opt.demandOption) {
3990
- this.demandOption(key, typeof opt.demandOption === "string" ? opt.demandOption : undefined);
3991
- }
3992
- if (opt.conflicts) {
3993
- this.conflicts(key, opt.conflicts);
3994
- }
3995
- if ("default" in opt) {
3996
- this.default(key, opt.default);
3997
- }
3998
- if (opt.implies !== undefined) {
3999
- this.implies(key, opt.implies);
4000
- }
4001
- if (opt.nargs !== undefined) {
4002
- this.nargs(key, opt.nargs);
4003
- }
4004
- if (opt.config) {
4005
- this.config(key, opt.configParser);
4006
- }
4007
- if (opt.normalize) {
4008
- this.normalize(key);
4009
- }
4010
- if (opt.choices) {
4011
- this.choices(key, opt.choices);
4012
- }
4013
- if (opt.coerce) {
4014
- this.coerce(key, opt.coerce);
4015
- }
4016
- if (opt.group) {
4017
- this.group(key, opt.group);
4018
- }
4019
- if (opt.boolean || opt.type === "boolean") {
4020
- this.boolean(key);
4021
- if (opt.alias)
4022
- this.boolean(opt.alias);
4023
- }
4024
- if (opt.array || opt.type === "array") {
4025
- this.array(key);
4026
- if (opt.alias)
4027
- this.array(opt.alias);
4028
- }
4029
- if (opt.number || opt.type === "number") {
4030
- this.number(key);
4031
- if (opt.alias)
4032
- this.number(opt.alias);
4033
- }
4034
- if (opt.string || opt.type === "string") {
4035
- this.string(key);
4036
- if (opt.alias)
4037
- this.string(opt.alias);
4038
- }
4039
- if (opt.count || opt.type === "count") {
4040
- this.count(key);
4041
- }
4042
- if (typeof opt.global === "boolean") {
4043
- this.global(key, opt.global);
4044
- }
4045
- if (opt.defaultDescription) {
4046
- __classPrivateFieldGet(this, _YargsInstance_options, "f").defaultDescription[key] = opt.defaultDescription;
4047
- }
4048
- if (opt.skipValidation) {
4049
- this.skipValidation(key);
4050
- }
4051
- const desc = opt.describe || opt.description || opt.desc;
4052
- const descriptions = __classPrivateFieldGet(this, _YargsInstance_usage, "f").getDescriptions();
4053
- if (!Object.prototype.hasOwnProperty.call(descriptions, key) || typeof desc === "string") {
4054
- this.describe(key, desc);
4055
- }
4056
- if (opt.hidden) {
4057
- this.hide(key);
4058
- }
4059
- if (opt.requiresArg) {
4060
- this.requiresArg(key);
4061
- }
4062
- }
4063
- return this;
4064
- }
4065
- options(key, opt) {
4066
- return this.option(key, opt);
4067
- }
4068
- parse(args, shortCircuit, _parseFn) {
4069
- argsert("[string|array] [function|boolean|object] [function]", [args, shortCircuit, _parseFn], arguments.length);
4070
- this[kFreeze]();
4071
- if (typeof args === "undefined") {
4072
- args = __classPrivateFieldGet(this, _YargsInstance_processArgs, "f");
4073
- }
4074
- if (typeof shortCircuit === "object") {
4075
- __classPrivateFieldSet(this, _YargsInstance_parseContext, shortCircuit, "f");
4076
- shortCircuit = _parseFn;
4077
- }
4078
- if (typeof shortCircuit === "function") {
4079
- __classPrivateFieldSet(this, _YargsInstance_parseFn, shortCircuit, "f");
4080
- shortCircuit = false;
4081
- }
4082
- if (!shortCircuit)
4083
- __classPrivateFieldSet(this, _YargsInstance_processArgs, args, "f");
4084
- if (__classPrivateFieldGet(this, _YargsInstance_parseFn, "f"))
4085
- __classPrivateFieldSet(this, _YargsInstance_exitProcess, false, "f");
4086
- const parsed = this[kRunYargsParserAndExecuteCommands](args, !!shortCircuit);
4087
- const tmpParsed = this.parsed;
4088
- __classPrivateFieldGet(this, _YargsInstance_completion, "f").setParsed(this.parsed);
4089
- if (isPromise(parsed)) {
4090
- return parsed.then((argv) => {
4091
- if (__classPrivateFieldGet(this, _YargsInstance_parseFn, "f"))
4092
- __classPrivateFieldGet(this, _YargsInstance_parseFn, "f").call(this, __classPrivateFieldGet(this, _YargsInstance_exitError, "f"), argv, __classPrivateFieldGet(this, _YargsInstance_output, "f"));
4093
- return argv;
4094
- }).catch((err) => {
4095
- if (__classPrivateFieldGet(this, _YargsInstance_parseFn, "f")) {
4096
- __classPrivateFieldGet(this, _YargsInstance_parseFn, "f")(err, this.parsed.argv, __classPrivateFieldGet(this, _YargsInstance_output, "f"));
4097
- }
4098
- throw err;
4099
- }).finally(() => {
4100
- this[kUnfreeze]();
4101
- this.parsed = tmpParsed;
4102
- });
4103
- } else {
4104
- if (__classPrivateFieldGet(this, _YargsInstance_parseFn, "f"))
4105
- __classPrivateFieldGet(this, _YargsInstance_parseFn, "f").call(this, __classPrivateFieldGet(this, _YargsInstance_exitError, "f"), parsed, __classPrivateFieldGet(this, _YargsInstance_output, "f"));
4106
- this[kUnfreeze]();
4107
- this.parsed = tmpParsed;
4108
- }
4109
- return parsed;
4110
- }
4111
- parseAsync(args, shortCircuit, _parseFn) {
4112
- const maybePromise = this.parse(args, shortCircuit, _parseFn);
4113
- return !isPromise(maybePromise) ? Promise.resolve(maybePromise) : maybePromise;
4114
- }
4115
- parseSync(args, shortCircuit, _parseFn) {
4116
- const maybePromise = this.parse(args, shortCircuit, _parseFn);
4117
- if (isPromise(maybePromise)) {
4118
- throw new YError(".parseSync() must not be used with asynchronous builders, handlers, or middleware");
4119
- }
4120
- return maybePromise;
4121
- }
4122
- parserConfiguration(config) {
4123
- argsert("<object>", [config], arguments.length);
4124
- __classPrivateFieldSet(this, _YargsInstance_parserConfig, config, "f");
4125
- return this;
4126
- }
4127
- pkgConf(key, rootPath) {
4128
- argsert("<string> [string]", [key, rootPath], arguments.length);
4129
- let conf = null;
4130
- const obj = this[kPkgUp](rootPath || __classPrivateFieldGet(this, _YargsInstance_cwd, "f"));
4131
- if (obj[key] && typeof obj[key] === "object") {
4132
- conf = applyExtends(obj[key], rootPath || __classPrivateFieldGet(this, _YargsInstance_cwd, "f"), this[kGetParserConfiguration]()["deep-merge-config"] || false, __classPrivateFieldGet(this, _YargsInstance_shim, "f"));
4133
- __classPrivateFieldGet(this, _YargsInstance_options, "f").configObjects = (__classPrivateFieldGet(this, _YargsInstance_options, "f").configObjects || []).concat(conf);
4134
- }
4135
- return this;
4136
- }
4137
- positional(key, opts) {
4138
- argsert("<string> <object>", [key, opts], arguments.length);
4139
- const supportedOpts = [
4140
- "default",
4141
- "defaultDescription",
4142
- "implies",
4143
- "normalize",
4144
- "choices",
4145
- "conflicts",
4146
- "coerce",
4147
- "type",
4148
- "describe",
4149
- "desc",
4150
- "description",
4151
- "alias"
4152
- ];
4153
- opts = objFilter(opts, (k, v) => {
4154
- if (k === "type" && !["string", "number", "boolean"].includes(v))
4155
- return false;
4156
- return supportedOpts.includes(k);
4157
- });
4158
- const fullCommand = __classPrivateFieldGet(this, _YargsInstance_context, "f").fullCommands[__classPrivateFieldGet(this, _YargsInstance_context, "f").fullCommands.length - 1];
4159
- const parseOptions = fullCommand ? __classPrivateFieldGet(this, _YargsInstance_command, "f").cmdToParseOptions(fullCommand) : {
4160
- array: [],
4161
- alias: {},
4162
- default: {},
4163
- demand: {}
4164
- };
4165
- objectKeys(parseOptions).forEach((pk) => {
4166
- const parseOption = parseOptions[pk];
4167
- if (Array.isArray(parseOption)) {
4168
- if (parseOption.indexOf(key) !== -1)
4169
- opts[pk] = true;
4170
- } else {
4171
- if (parseOption[key] && !(pk in opts))
4172
- opts[pk] = parseOption[key];
4173
- }
4174
- });
4175
- this.group(key, __classPrivateFieldGet(this, _YargsInstance_usage, "f").getPositionalGroupName());
4176
- return this.option(key, opts);
4177
- }
4178
- recommendCommands(recommend = true) {
4179
- argsert("[boolean]", [recommend], arguments.length);
4180
- __classPrivateFieldSet(this, _YargsInstance_recommendCommands, recommend, "f");
4181
- return this;
4182
- }
4183
- required(keys, max, msg) {
4184
- return this.demand(keys, max, msg);
4185
- }
4186
- require(keys, max, msg) {
4187
- return this.demand(keys, max, msg);
4188
- }
4189
- requiresArg(keys) {
4190
- argsert("<array|string|object> [number]", [keys], arguments.length);
4191
- if (typeof keys === "string" && __classPrivateFieldGet(this, _YargsInstance_options, "f").narg[keys]) {
4192
- return this;
4193
- } else {
4194
- this[kPopulateParserHintSingleValueDictionary](this.requiresArg.bind(this), "narg", keys, NaN);
4195
- }
4196
- return this;
4197
- }
4198
- showCompletionScript($0, cmd) {
4199
- argsert("[string] [string]", [$0, cmd], arguments.length);
4200
- $0 = $0 || this.$0;
4201
- __classPrivateFieldGet(this, _YargsInstance_logger, "f").log(__classPrivateFieldGet(this, _YargsInstance_completion, "f").generateCompletionScript($0, cmd || __classPrivateFieldGet(this, _YargsInstance_completionCommand, "f") || "completion"));
4202
- return this;
4203
- }
4204
- showHelp(level) {
4205
- argsert("[string|function]", [level], arguments.length);
4206
- __classPrivateFieldSet(this, _YargsInstance_hasOutput, true, "f");
4207
- if (!__classPrivateFieldGet(this, _YargsInstance_usage, "f").hasCachedHelpMessage()) {
4208
- if (!this.parsed) {
4209
- const parse = this[kRunYargsParserAndExecuteCommands](__classPrivateFieldGet(this, _YargsInstance_processArgs, "f"), undefined, undefined, 0, true);
4210
- if (isPromise(parse)) {
4211
- parse.then(() => {
4212
- __classPrivateFieldGet(this, _YargsInstance_usage, "f").showHelp(level);
4213
- });
4214
- return this;
4215
- }
4216
- }
4217
- const builderResponse = __classPrivateFieldGet(this, _YargsInstance_command, "f").runDefaultBuilderOn(this);
4218
- if (isPromise(builderResponse)) {
4219
- builderResponse.then(() => {
4220
- __classPrivateFieldGet(this, _YargsInstance_usage, "f").showHelp(level);
4221
- });
4222
- return this;
4223
- }
4224
- }
4225
- __classPrivateFieldGet(this, _YargsInstance_usage, "f").showHelp(level);
4226
- return this;
4227
- }
4228
- scriptName(scriptName) {
4229
- this.customScriptName = true;
4230
- this.$0 = scriptName;
4231
- return this;
4232
- }
4233
- showHelpOnFail(enabled, message) {
4234
- argsert("[boolean|string] [string]", [enabled, message], arguments.length);
4235
- __classPrivateFieldGet(this, _YargsInstance_usage, "f").showHelpOnFail(enabled, message);
4236
- return this;
4237
- }
4238
- showVersion(level) {
4239
- argsert("[string|function]", [level], arguments.length);
4240
- __classPrivateFieldGet(this, _YargsInstance_usage, "f").showVersion(level);
4241
- return this;
4242
- }
4243
- skipValidation(keys) {
4244
- argsert("<array|string>", [keys], arguments.length);
4245
- this[kPopulateParserHintArray]("skipValidation", keys);
4246
- return this;
4247
- }
4248
- strict(enabled) {
4249
- argsert("[boolean]", [enabled], arguments.length);
4250
- __classPrivateFieldSet(this, _YargsInstance_strict, enabled !== false, "f");
4251
- return this;
4252
- }
4253
- strictCommands(enabled) {
4254
- argsert("[boolean]", [enabled], arguments.length);
4255
- __classPrivateFieldSet(this, _YargsInstance_strictCommands, enabled !== false, "f");
4256
- return this;
4257
- }
4258
- strictOptions(enabled) {
4259
- argsert("[boolean]", [enabled], arguments.length);
4260
- __classPrivateFieldSet(this, _YargsInstance_strictOptions, enabled !== false, "f");
4261
- return this;
4262
- }
4263
- string(keys) {
4264
- argsert("<array|string>", [keys], arguments.length);
4265
- this[kPopulateParserHintArray]("string", keys);
4266
- this[kTrackManuallySetKeys](keys);
4267
- return this;
4268
- }
4269
- terminalWidth() {
4270
- argsert([], 0);
4271
- return __classPrivateFieldGet(this, _YargsInstance_shim, "f").process.stdColumns;
4272
- }
4273
- updateLocale(obj) {
4274
- return this.updateStrings(obj);
4275
- }
4276
- updateStrings(obj) {
4277
- argsert("<object>", [obj], arguments.length);
4278
- __classPrivateFieldSet(this, _YargsInstance_detectLocale, false, "f");
4279
- __classPrivateFieldGet(this, _YargsInstance_shim, "f").y18n.updateLocale(obj);
4280
- return this;
4281
- }
4282
- usage(msg, description, builder, handler) {
4283
- argsert("<string|null|undefined> [string|boolean] [function|object] [function]", [msg, description, builder, handler], arguments.length);
4284
- if (description !== undefined) {
4285
- assertNotStrictEqual(msg, null, __classPrivateFieldGet(this, _YargsInstance_shim, "f"));
4286
- if ((msg || "").match(/^\$0( |$)/)) {
4287
- return this.command(msg, description, builder, handler);
4288
- } else {
4289
- throw new YError(".usage() description must start with $0 if being used as alias for .command()");
4290
- }
4291
- } else {
4292
- __classPrivateFieldGet(this, _YargsInstance_usage, "f").usage(msg);
4293
- return this;
4294
- }
4295
- }
4296
- usageConfiguration(config) {
4297
- argsert("<object>", [config], arguments.length);
4298
- __classPrivateFieldSet(this, _YargsInstance_usageConfig, config, "f");
4299
- return this;
4300
- }
4301
- version(opt, msg, ver) {
4302
- const defaultVersionOpt = "version";
4303
- argsert("[boolean|string] [string] [string]", [opt, msg, ver], arguments.length);
4304
- if (__classPrivateFieldGet(this, _YargsInstance_versionOpt, "f")) {
4305
- this[kDeleteFromParserHintObject](__classPrivateFieldGet(this, _YargsInstance_versionOpt, "f"));
4306
- __classPrivateFieldGet(this, _YargsInstance_usage, "f").version(undefined);
4307
- __classPrivateFieldSet(this, _YargsInstance_versionOpt, null, "f");
4308
- }
4309
- if (arguments.length === 0) {
4310
- ver = this[kGuessVersion]();
4311
- opt = defaultVersionOpt;
4312
- } else if (arguments.length === 1) {
4313
- if (opt === false) {
4314
- return this;
4315
- }
4316
- ver = opt;
4317
- opt = defaultVersionOpt;
4318
- } else if (arguments.length === 2) {
4319
- ver = msg;
4320
- msg = undefined;
4321
- }
4322
- __classPrivateFieldSet(this, _YargsInstance_versionOpt, typeof opt === "string" ? opt : defaultVersionOpt, "f");
4323
- msg = msg || __classPrivateFieldGet(this, _YargsInstance_usage, "f").deferY18nLookup("Show version number");
4324
- __classPrivateFieldGet(this, _YargsInstance_usage, "f").version(ver || undefined);
4325
- this.boolean(__classPrivateFieldGet(this, _YargsInstance_versionOpt, "f"));
4326
- this.describe(__classPrivateFieldGet(this, _YargsInstance_versionOpt, "f"), msg);
4327
- return this;
4328
- }
4329
- wrap(cols) {
4330
- argsert("<number|null|undefined>", [cols], arguments.length);
4331
- __classPrivateFieldGet(this, _YargsInstance_usage, "f").wrap(cols);
4332
- return this;
4333
- }
4334
- [(_YargsInstance_command = new WeakMap, _YargsInstance_cwd = new WeakMap, _YargsInstance_context = new WeakMap, _YargsInstance_completion = new WeakMap, _YargsInstance_completionCommand = new WeakMap, _YargsInstance_defaultShowHiddenOpt = new WeakMap, _YargsInstance_exitError = new WeakMap, _YargsInstance_detectLocale = new WeakMap, _YargsInstance_emittedWarnings = new WeakMap, _YargsInstance_exitProcess = new WeakMap, _YargsInstance_frozens = new WeakMap, _YargsInstance_globalMiddleware = new WeakMap, _YargsInstance_groups = new WeakMap, _YargsInstance_hasOutput = new WeakMap, _YargsInstance_helpOpt = new WeakMap, _YargsInstance_isGlobalContext = new WeakMap, _YargsInstance_logger = new WeakMap, _YargsInstance_output = new WeakMap, _YargsInstance_options = new WeakMap, _YargsInstance_parentRequire = new WeakMap, _YargsInstance_parserConfig = new WeakMap, _YargsInstance_parseFn = new WeakMap, _YargsInstance_parseContext = new WeakMap, _YargsInstance_pkgs = new WeakMap, _YargsInstance_preservedGroups = new WeakMap, _YargsInstance_processArgs = new WeakMap, _YargsInstance_recommendCommands = new WeakMap, _YargsInstance_shim = new WeakMap, _YargsInstance_strict = new WeakMap, _YargsInstance_strictCommands = new WeakMap, _YargsInstance_strictOptions = new WeakMap, _YargsInstance_usage = new WeakMap, _YargsInstance_usageConfig = new WeakMap, _YargsInstance_versionOpt = new WeakMap, _YargsInstance_validation = new WeakMap, kCopyDoubleDash)](argv) {
4335
- if (!argv._ || !argv["--"])
4336
- return argv;
4337
- argv._.push.apply(argv._, argv["--"]);
4338
- try {
4339
- delete argv["--"];
4340
- } catch (_err) {
4341
- }
4342
- return argv;
4343
- }
4344
- [kCreateLogger]() {
4345
- return {
4346
- log: (...args) => {
4347
- if (!this[kHasParseCallback]())
4348
- console.log(...args);
4349
- __classPrivateFieldSet(this, _YargsInstance_hasOutput, true, "f");
4350
- if (__classPrivateFieldGet(this, _YargsInstance_output, "f").length)
4351
- __classPrivateFieldSet(this, _YargsInstance_output, __classPrivateFieldGet(this, _YargsInstance_output, "f") + `
4352
- `, "f");
4353
- __classPrivateFieldSet(this, _YargsInstance_output, __classPrivateFieldGet(this, _YargsInstance_output, "f") + args.join(" "), "f");
4354
- },
4355
- error: (...args) => {
4356
- if (!this[kHasParseCallback]())
4357
- console.error(...args);
4358
- __classPrivateFieldSet(this, _YargsInstance_hasOutput, true, "f");
4359
- if (__classPrivateFieldGet(this, _YargsInstance_output, "f").length)
4360
- __classPrivateFieldSet(this, _YargsInstance_output, __classPrivateFieldGet(this, _YargsInstance_output, "f") + `
4361
- `, "f");
4362
- __classPrivateFieldSet(this, _YargsInstance_output, __classPrivateFieldGet(this, _YargsInstance_output, "f") + args.join(" "), "f");
4363
- }
4364
- };
4365
- }
4366
- [kDeleteFromParserHintObject](optionKey) {
4367
- objectKeys(__classPrivateFieldGet(this, _YargsInstance_options, "f")).forEach((hintKey) => {
4368
- if (((key) => key === "configObjects")(hintKey))
4369
- return;
4370
- const hint = __classPrivateFieldGet(this, _YargsInstance_options, "f")[hintKey];
4371
- if (Array.isArray(hint)) {
4372
- if (hint.includes(optionKey))
4373
- hint.splice(hint.indexOf(optionKey), 1);
4374
- } else if (typeof hint === "object") {
4375
- delete hint[optionKey];
4376
- }
4377
- });
4378
- delete __classPrivateFieldGet(this, _YargsInstance_usage, "f").getDescriptions()[optionKey];
4379
- }
4380
- [kEmitWarning](warning, type, deduplicationId) {
4381
- if (!__classPrivateFieldGet(this, _YargsInstance_emittedWarnings, "f")[deduplicationId]) {
4382
- __classPrivateFieldGet(this, _YargsInstance_shim, "f").process.emitWarning(warning, type);
4383
- __classPrivateFieldGet(this, _YargsInstance_emittedWarnings, "f")[deduplicationId] = true;
4384
- }
4385
- }
4386
- [kFreeze]() {
4387
- __classPrivateFieldGet(this, _YargsInstance_frozens, "f").push({
4388
- options: __classPrivateFieldGet(this, _YargsInstance_options, "f"),
4389
- configObjects: __classPrivateFieldGet(this, _YargsInstance_options, "f").configObjects.slice(0),
4390
- exitProcess: __classPrivateFieldGet(this, _YargsInstance_exitProcess, "f"),
4391
- groups: __classPrivateFieldGet(this, _YargsInstance_groups, "f"),
4392
- strict: __classPrivateFieldGet(this, _YargsInstance_strict, "f"),
4393
- strictCommands: __classPrivateFieldGet(this, _YargsInstance_strictCommands, "f"),
4394
- strictOptions: __classPrivateFieldGet(this, _YargsInstance_strictOptions, "f"),
4395
- completionCommand: __classPrivateFieldGet(this, _YargsInstance_completionCommand, "f"),
4396
- output: __classPrivateFieldGet(this, _YargsInstance_output, "f"),
4397
- exitError: __classPrivateFieldGet(this, _YargsInstance_exitError, "f"),
4398
- hasOutput: __classPrivateFieldGet(this, _YargsInstance_hasOutput, "f"),
4399
- parsed: this.parsed,
4400
- parseFn: __classPrivateFieldGet(this, _YargsInstance_parseFn, "f"),
4401
- parseContext: __classPrivateFieldGet(this, _YargsInstance_parseContext, "f")
4402
- });
4403
- __classPrivateFieldGet(this, _YargsInstance_usage, "f").freeze();
4404
- __classPrivateFieldGet(this, _YargsInstance_validation, "f").freeze();
4405
- __classPrivateFieldGet(this, _YargsInstance_command, "f").freeze();
4406
- __classPrivateFieldGet(this, _YargsInstance_globalMiddleware, "f").freeze();
4407
- }
4408
- [kGetDollarZero]() {
4409
- let $0 = "";
4410
- let default$0;
4411
- if (/\b(node|iojs|electron)(\.exe)?$/.test(__classPrivateFieldGet(this, _YargsInstance_shim, "f").process.argv()[0])) {
4412
- default$0 = __classPrivateFieldGet(this, _YargsInstance_shim, "f").process.argv().slice(1, 2);
4413
- } else {
4414
- default$0 = __classPrivateFieldGet(this, _YargsInstance_shim, "f").process.argv().slice(0, 1);
4415
- }
4416
- $0 = default$0.map((x) => {
4417
- const b = this[kRebase](__classPrivateFieldGet(this, _YargsInstance_cwd, "f"), x);
4418
- return x.match(/^(\/|([a-zA-Z]:)?\\)/) && b.length < x.length ? b : x;
4419
- }).join(" ").trim();
4420
- if (__classPrivateFieldGet(this, _YargsInstance_shim, "f").getEnv("_") && __classPrivateFieldGet(this, _YargsInstance_shim, "f").getProcessArgvBin() === __classPrivateFieldGet(this, _YargsInstance_shim, "f").getEnv("_")) {
4421
- $0 = __classPrivateFieldGet(this, _YargsInstance_shim, "f").getEnv("_").replace(`${__classPrivateFieldGet(this, _YargsInstance_shim, "f").path.dirname(__classPrivateFieldGet(this, _YargsInstance_shim, "f").process.execPath())}/`, "");
4422
- }
4423
- return $0;
4424
- }
4425
- [kGetParserConfiguration]() {
4426
- return __classPrivateFieldGet(this, _YargsInstance_parserConfig, "f");
4427
- }
4428
- [kGetUsageConfiguration]() {
4429
- return __classPrivateFieldGet(this, _YargsInstance_usageConfig, "f");
4430
- }
4431
- [kGuessLocale]() {
4432
- if (!__classPrivateFieldGet(this, _YargsInstance_detectLocale, "f"))
4433
- return;
4434
- const locale = __classPrivateFieldGet(this, _YargsInstance_shim, "f").getEnv("LC_ALL") || __classPrivateFieldGet(this, _YargsInstance_shim, "f").getEnv("LC_MESSAGES") || __classPrivateFieldGet(this, _YargsInstance_shim, "f").getEnv("LANG") || __classPrivateFieldGet(this, _YargsInstance_shim, "f").getEnv("LANGUAGE") || "en_US";
4435
- this.locale(locale.replace(/[.:].*/, ""));
4436
- }
4437
- [kGuessVersion]() {
4438
- const obj = this[kPkgUp]();
4439
- return obj.version || "unknown";
4440
- }
4441
- [kParsePositionalNumbers](argv) {
4442
- const args = argv["--"] ? argv["--"] : argv._;
4443
- for (let i = 0, arg;(arg = args[i]) !== undefined; i++) {
4444
- if (__classPrivateFieldGet(this, _YargsInstance_shim, "f").Parser.looksLikeNumber(arg) && Number.isSafeInteger(Math.floor(parseFloat(`${arg}`)))) {
4445
- args[i] = Number(arg);
4446
- }
4447
- }
4448
- return argv;
4449
- }
4450
- [kPkgUp](rootPath) {
4451
- const npath = rootPath || "*";
4452
- if (__classPrivateFieldGet(this, _YargsInstance_pkgs, "f")[npath])
4453
- return __classPrivateFieldGet(this, _YargsInstance_pkgs, "f")[npath];
4454
- let obj = {};
4455
- try {
4456
- let startDir = rootPath || __classPrivateFieldGet(this, _YargsInstance_shim, "f").mainFilename;
4457
- if (!rootPath && __classPrivateFieldGet(this, _YargsInstance_shim, "f").path.extname(startDir)) {
4458
- startDir = __classPrivateFieldGet(this, _YargsInstance_shim, "f").path.dirname(startDir);
4459
- }
4460
- const pkgJsonPath = __classPrivateFieldGet(this, _YargsInstance_shim, "f").findUp(startDir, (dir, names) => {
4461
- if (names.includes("package.json")) {
4462
- return "package.json";
4463
- } else {
4464
- return;
4465
- }
4466
- });
4467
- assertNotStrictEqual(pkgJsonPath, undefined, __classPrivateFieldGet(this, _YargsInstance_shim, "f"));
4468
- obj = JSON.parse(__classPrivateFieldGet(this, _YargsInstance_shim, "f").readFileSync(pkgJsonPath, "utf8"));
4469
- } catch (_noop) {
4470
- }
4471
- __classPrivateFieldGet(this, _YargsInstance_pkgs, "f")[npath] = obj || {};
4472
- return __classPrivateFieldGet(this, _YargsInstance_pkgs, "f")[npath];
4473
- }
4474
- [kPopulateParserHintArray](type, keys) {
4475
- keys = [].concat(keys);
4476
- keys.forEach((key) => {
4477
- key = this[kSanitizeKey](key);
4478
- __classPrivateFieldGet(this, _YargsInstance_options, "f")[type].push(key);
4479
- });
4480
- }
4481
- [kPopulateParserHintSingleValueDictionary](builder, type, key, value) {
4482
- this[kPopulateParserHintDictionary](builder, type, key, value, (type2, key2, value2) => {
4483
- __classPrivateFieldGet(this, _YargsInstance_options, "f")[type2][key2] = value2;
4484
- });
4485
- }
4486
- [kPopulateParserHintArrayDictionary](builder, type, key, value) {
4487
- this[kPopulateParserHintDictionary](builder, type, key, value, (type2, key2, value2) => {
4488
- __classPrivateFieldGet(this, _YargsInstance_options, "f")[type2][key2] = (__classPrivateFieldGet(this, _YargsInstance_options, "f")[type2][key2] || []).concat(value2);
4489
- });
4490
- }
4491
- [kPopulateParserHintDictionary](builder, type, key, value, singleKeyHandler) {
4492
- if (Array.isArray(key)) {
4493
- key.forEach((k) => {
4494
- builder(k, value);
4495
- });
4496
- } else if (((key2) => typeof key2 === "object")(key)) {
4497
- for (const k of objectKeys(key)) {
4498
- builder(k, key[k]);
4499
- }
4500
- } else {
4501
- singleKeyHandler(type, this[kSanitizeKey](key), value);
4502
- }
4503
- }
4504
- [kSanitizeKey](key) {
4505
- if (key === "__proto__")
4506
- return "___proto___";
4507
- return key;
4508
- }
4509
- [kSetKey](key, set) {
4510
- this[kPopulateParserHintSingleValueDictionary](this[kSetKey].bind(this), "key", key, set);
4511
- return this;
4512
- }
4513
- [kUnfreeze]() {
4514
- var _a2, _b2, _c2, _d, _e, _f, _g, _h, _j, _k, _l, _m;
4515
- const frozen = __classPrivateFieldGet(this, _YargsInstance_frozens, "f").pop();
4516
- assertNotStrictEqual(frozen, undefined, __classPrivateFieldGet(this, _YargsInstance_shim, "f"));
4517
- let configObjects;
4518
- _a2 = this, _b2 = this, _c2 = this, _d = this, _e = this, _f = this, _g = this, _h = this, _j = this, _k = this, _l = this, _m = this, {
4519
- options: { set value(_o) {
4520
- __classPrivateFieldSet(_a2, _YargsInstance_options, _o, "f");
4521
- } }.value,
4522
- configObjects,
4523
- exitProcess: { set value(_o) {
4524
- __classPrivateFieldSet(_b2, _YargsInstance_exitProcess, _o, "f");
4525
- } }.value,
4526
- groups: { set value(_o) {
4527
- __classPrivateFieldSet(_c2, _YargsInstance_groups, _o, "f");
4528
- } }.value,
4529
- output: { set value(_o) {
4530
- __classPrivateFieldSet(_d, _YargsInstance_output, _o, "f");
4531
- } }.value,
4532
- exitError: { set value(_o) {
4533
- __classPrivateFieldSet(_e, _YargsInstance_exitError, _o, "f");
4534
- } }.value,
4535
- hasOutput: { set value(_o) {
4536
- __classPrivateFieldSet(_f, _YargsInstance_hasOutput, _o, "f");
4537
- } }.value,
4538
- parsed: this.parsed,
4539
- strict: { set value(_o) {
4540
- __classPrivateFieldSet(_g, _YargsInstance_strict, _o, "f");
4541
- } }.value,
4542
- strictCommands: { set value(_o) {
4543
- __classPrivateFieldSet(_h, _YargsInstance_strictCommands, _o, "f");
4544
- } }.value,
4545
- strictOptions: { set value(_o) {
4546
- __classPrivateFieldSet(_j, _YargsInstance_strictOptions, _o, "f");
4547
- } }.value,
4548
- completionCommand: { set value(_o) {
4549
- __classPrivateFieldSet(_k, _YargsInstance_completionCommand, _o, "f");
4550
- } }.value,
4551
- parseFn: { set value(_o) {
4552
- __classPrivateFieldSet(_l, _YargsInstance_parseFn, _o, "f");
4553
- } }.value,
4554
- parseContext: { set value(_o) {
4555
- __classPrivateFieldSet(_m, _YargsInstance_parseContext, _o, "f");
4556
- } }.value
4557
- } = frozen;
4558
- __classPrivateFieldGet(this, _YargsInstance_options, "f").configObjects = configObjects;
4559
- __classPrivateFieldGet(this, _YargsInstance_usage, "f").unfreeze();
4560
- __classPrivateFieldGet(this, _YargsInstance_validation, "f").unfreeze();
4561
- __classPrivateFieldGet(this, _YargsInstance_command, "f").unfreeze();
4562
- __classPrivateFieldGet(this, _YargsInstance_globalMiddleware, "f").unfreeze();
4563
- }
4564
- [kValidateAsync](validation2, argv) {
4565
- return maybeAsyncResult(argv, (result) => {
4566
- validation2(result);
4567
- return result;
4568
- });
4569
- }
4570
- getInternalMethods() {
4571
- return {
4572
- getCommandInstance: this[kGetCommandInstance].bind(this),
4573
- getContext: this[kGetContext].bind(this),
4574
- getHasOutput: this[kGetHasOutput].bind(this),
4575
- getLoggerInstance: this[kGetLoggerInstance].bind(this),
4576
- getParseContext: this[kGetParseContext].bind(this),
4577
- getParserConfiguration: this[kGetParserConfiguration].bind(this),
4578
- getUsageConfiguration: this[kGetUsageConfiguration].bind(this),
4579
- getUsageInstance: this[kGetUsageInstance].bind(this),
4580
- getValidationInstance: this[kGetValidationInstance].bind(this),
4581
- hasParseCallback: this[kHasParseCallback].bind(this),
4582
- isGlobalContext: this[kIsGlobalContext].bind(this),
4583
- postProcess: this[kPostProcess].bind(this),
4584
- reset: this[kReset].bind(this),
4585
- runValidation: this[kRunValidation].bind(this),
4586
- runYargsParserAndExecuteCommands: this[kRunYargsParserAndExecuteCommands].bind(this),
4587
- setHasOutput: this[kSetHasOutput].bind(this)
4588
- };
4589
- }
4590
- [kGetCommandInstance]() {
4591
- return __classPrivateFieldGet(this, _YargsInstance_command, "f");
4592
- }
4593
- [kGetContext]() {
4594
- return __classPrivateFieldGet(this, _YargsInstance_context, "f");
4595
- }
4596
- [kGetHasOutput]() {
4597
- return __classPrivateFieldGet(this, _YargsInstance_hasOutput, "f");
4598
- }
4599
- [kGetLoggerInstance]() {
4600
- return __classPrivateFieldGet(this, _YargsInstance_logger, "f");
4601
- }
4602
- [kGetParseContext]() {
4603
- return __classPrivateFieldGet(this, _YargsInstance_parseContext, "f") || {};
4604
- }
4605
- [kGetUsageInstance]() {
4606
- return __classPrivateFieldGet(this, _YargsInstance_usage, "f");
4607
- }
4608
- [kGetValidationInstance]() {
4609
- return __classPrivateFieldGet(this, _YargsInstance_validation, "f");
4610
- }
4611
- [kHasParseCallback]() {
4612
- return !!__classPrivateFieldGet(this, _YargsInstance_parseFn, "f");
4613
- }
4614
- [kIsGlobalContext]() {
4615
- return __classPrivateFieldGet(this, _YargsInstance_isGlobalContext, "f");
4616
- }
4617
- [kPostProcess](argv, populateDoubleDash, calledFromCommand, runGlobalMiddleware) {
4618
- if (calledFromCommand)
4619
- return argv;
4620
- if (isPromise(argv))
4621
- return argv;
4622
- if (!populateDoubleDash) {
4623
- argv = this[kCopyDoubleDash](argv);
4624
- }
4625
- const parsePositionalNumbers = this[kGetParserConfiguration]()["parse-positional-numbers"] || this[kGetParserConfiguration]()["parse-positional-numbers"] === undefined;
4626
- if (parsePositionalNumbers) {
4627
- argv = this[kParsePositionalNumbers](argv);
4628
- }
4629
- if (runGlobalMiddleware) {
4630
- argv = applyMiddleware(argv, this, __classPrivateFieldGet(this, _YargsInstance_globalMiddleware, "f").getMiddleware(), false);
4631
- }
4632
- return argv;
4633
- }
4634
- [kReset](aliases = {}) {
4635
- __classPrivateFieldSet(this, _YargsInstance_options, __classPrivateFieldGet(this, _YargsInstance_options, "f") || {}, "f");
4636
- const tmpOptions = {};
4637
- tmpOptions.local = __classPrivateFieldGet(this, _YargsInstance_options, "f").local || [];
4638
- tmpOptions.configObjects = __classPrivateFieldGet(this, _YargsInstance_options, "f").configObjects || [];
4639
- const localLookup = {};
4640
- tmpOptions.local.forEach((l) => {
4641
- localLookup[l] = true;
4642
- (aliases[l] || []).forEach((a) => {
4643
- localLookup[a] = true;
4644
- });
4645
- });
4646
- Object.assign(__classPrivateFieldGet(this, _YargsInstance_preservedGroups, "f"), Object.keys(__classPrivateFieldGet(this, _YargsInstance_groups, "f")).reduce((acc, groupName) => {
4647
- const keys = __classPrivateFieldGet(this, _YargsInstance_groups, "f")[groupName].filter((key) => !(key in localLookup));
4648
- if (keys.length > 0) {
4649
- acc[groupName] = keys;
4650
- }
4651
- return acc;
4652
- }, {}));
4653
- __classPrivateFieldSet(this, _YargsInstance_groups, {}, "f");
4654
- const arrayOptions = [
4655
- "array",
4656
- "boolean",
4657
- "string",
4658
- "skipValidation",
4659
- "count",
4660
- "normalize",
4661
- "number",
4662
- "hiddenOptions"
4663
- ];
4664
- const objectOptions = [
4665
- "narg",
4666
- "key",
4667
- "alias",
4668
- "default",
4669
- "defaultDescription",
4670
- "config",
4671
- "choices",
4672
- "demandedOptions",
4673
- "demandedCommands",
4674
- "deprecatedOptions"
4675
- ];
4676
- arrayOptions.forEach((k) => {
4677
- tmpOptions[k] = (__classPrivateFieldGet(this, _YargsInstance_options, "f")[k] || []).filter((k2) => !localLookup[k2]);
4678
- });
4679
- objectOptions.forEach((k) => {
4680
- tmpOptions[k] = objFilter(__classPrivateFieldGet(this, _YargsInstance_options, "f")[k], (k2) => !localLookup[k2]);
4681
- });
4682
- tmpOptions.envPrefix = __classPrivateFieldGet(this, _YargsInstance_options, "f").envPrefix;
4683
- __classPrivateFieldSet(this, _YargsInstance_options, tmpOptions, "f");
4684
- __classPrivateFieldSet(this, _YargsInstance_usage, __classPrivateFieldGet(this, _YargsInstance_usage, "f") ? __classPrivateFieldGet(this, _YargsInstance_usage, "f").reset(localLookup) : usage(this, __classPrivateFieldGet(this, _YargsInstance_shim, "f")), "f");
4685
- __classPrivateFieldSet(this, _YargsInstance_validation, __classPrivateFieldGet(this, _YargsInstance_validation, "f") ? __classPrivateFieldGet(this, _YargsInstance_validation, "f").reset(localLookup) : validation(this, __classPrivateFieldGet(this, _YargsInstance_usage, "f"), __classPrivateFieldGet(this, _YargsInstance_shim, "f")), "f");
4686
- __classPrivateFieldSet(this, _YargsInstance_command, __classPrivateFieldGet(this, _YargsInstance_command, "f") ? __classPrivateFieldGet(this, _YargsInstance_command, "f").reset() : command(__classPrivateFieldGet(this, _YargsInstance_usage, "f"), __classPrivateFieldGet(this, _YargsInstance_validation, "f"), __classPrivateFieldGet(this, _YargsInstance_globalMiddleware, "f"), __classPrivateFieldGet(this, _YargsInstance_shim, "f")), "f");
4687
- if (!__classPrivateFieldGet(this, _YargsInstance_completion, "f"))
4688
- __classPrivateFieldSet(this, _YargsInstance_completion, completion(this, __classPrivateFieldGet(this, _YargsInstance_usage, "f"), __classPrivateFieldGet(this, _YargsInstance_command, "f"), __classPrivateFieldGet(this, _YargsInstance_shim, "f")), "f");
4689
- __classPrivateFieldGet(this, _YargsInstance_globalMiddleware, "f").reset();
4690
- __classPrivateFieldSet(this, _YargsInstance_completionCommand, null, "f");
4691
- __classPrivateFieldSet(this, _YargsInstance_output, "", "f");
4692
- __classPrivateFieldSet(this, _YargsInstance_exitError, null, "f");
4693
- __classPrivateFieldSet(this, _YargsInstance_hasOutput, false, "f");
4694
- this.parsed = false;
4695
- return this;
4696
- }
4697
- [kRebase](base, dir) {
4698
- return __classPrivateFieldGet(this, _YargsInstance_shim, "f").path.relative(base, dir);
4699
- }
4700
- [kRunYargsParserAndExecuteCommands](args, shortCircuit, calledFromCommand, commandIndex = 0, helpOnly = false) {
4701
- let skipValidation = !!calledFromCommand || helpOnly;
4702
- args = args || __classPrivateFieldGet(this, _YargsInstance_processArgs, "f");
4703
- __classPrivateFieldGet(this, _YargsInstance_options, "f").__ = __classPrivateFieldGet(this, _YargsInstance_shim, "f").y18n.__;
4704
- __classPrivateFieldGet(this, _YargsInstance_options, "f").configuration = this[kGetParserConfiguration]();
4705
- const populateDoubleDash = !!__classPrivateFieldGet(this, _YargsInstance_options, "f").configuration["populate--"];
4706
- const config = Object.assign({}, __classPrivateFieldGet(this, _YargsInstance_options, "f").configuration, {
4707
- "populate--": true
4708
- });
4709
- const parsed = __classPrivateFieldGet(this, _YargsInstance_shim, "f").Parser.detailed(args, Object.assign({}, __classPrivateFieldGet(this, _YargsInstance_options, "f"), {
4710
- configuration: { "parse-positional-numbers": false, ...config }
4711
- }));
4712
- const argv = Object.assign(parsed.argv, __classPrivateFieldGet(this, _YargsInstance_parseContext, "f"));
4713
- let argvPromise = undefined;
4714
- const aliases = parsed.aliases;
4715
- let helpOptSet = false;
4716
- let versionOptSet = false;
4717
- Object.keys(argv).forEach((key) => {
4718
- if (key === __classPrivateFieldGet(this, _YargsInstance_helpOpt, "f") && argv[key]) {
4719
- helpOptSet = true;
4720
- } else if (key === __classPrivateFieldGet(this, _YargsInstance_versionOpt, "f") && argv[key]) {
4721
- versionOptSet = true;
4722
- }
4723
- });
4724
- argv.$0 = this.$0;
4725
- this.parsed = parsed;
4726
- if (commandIndex === 0) {
4727
- __classPrivateFieldGet(this, _YargsInstance_usage, "f").clearCachedHelpMessage();
4728
- }
4729
- try {
4730
- this[kGuessLocale]();
4731
- if (shortCircuit) {
4732
- return this[kPostProcess](argv, populateDoubleDash, !!calledFromCommand, false);
4733
- }
4734
- if (__classPrivateFieldGet(this, _YargsInstance_helpOpt, "f")) {
4735
- const helpCmds = [__classPrivateFieldGet(this, _YargsInstance_helpOpt, "f")].concat(aliases[__classPrivateFieldGet(this, _YargsInstance_helpOpt, "f")] || []).filter((k) => k.length > 1);
4736
- if (helpCmds.includes("" + argv._[argv._.length - 1])) {
4737
- argv._.pop();
4738
- helpOptSet = true;
4739
- }
4740
- }
4741
- __classPrivateFieldSet(this, _YargsInstance_isGlobalContext, false, "f");
4742
- const handlerKeys = __classPrivateFieldGet(this, _YargsInstance_command, "f").getCommands();
4743
- const requestCompletions = __classPrivateFieldGet(this, _YargsInstance_completion, "f").completionKey in argv;
4744
- const skipRecommendation = helpOptSet || requestCompletions || helpOnly;
4745
- if (argv._.length) {
4746
- if (handlerKeys.length) {
4747
- let firstUnknownCommand;
4748
- for (let i = commandIndex || 0, cmd;argv._[i] !== undefined; i++) {
4749
- cmd = String(argv._[i]);
4750
- if (handlerKeys.includes(cmd) && cmd !== __classPrivateFieldGet(this, _YargsInstance_completionCommand, "f")) {
4751
- const innerArgv = __classPrivateFieldGet(this, _YargsInstance_command, "f").runCommand(cmd, this, parsed, i + 1, helpOnly, helpOptSet || versionOptSet || helpOnly);
4752
- return this[kPostProcess](innerArgv, populateDoubleDash, !!calledFromCommand, false);
4753
- } else if (!firstUnknownCommand && cmd !== __classPrivateFieldGet(this, _YargsInstance_completionCommand, "f")) {
4754
- firstUnknownCommand = cmd;
4755
- break;
4756
- }
4757
- }
4758
- if (!__classPrivateFieldGet(this, _YargsInstance_command, "f").hasDefaultCommand() && __classPrivateFieldGet(this, _YargsInstance_recommendCommands, "f") && firstUnknownCommand && !skipRecommendation) {
4759
- __classPrivateFieldGet(this, _YargsInstance_validation, "f").recommendCommands(firstUnknownCommand, handlerKeys);
4760
- }
4761
- }
4762
- if (__classPrivateFieldGet(this, _YargsInstance_completionCommand, "f") && argv._.includes(__classPrivateFieldGet(this, _YargsInstance_completionCommand, "f")) && !requestCompletions) {
4763
- if (__classPrivateFieldGet(this, _YargsInstance_exitProcess, "f"))
4764
- setBlocking(true);
4765
- this.showCompletionScript();
4766
- this.exit(0);
4767
- }
4768
- }
4769
- if (__classPrivateFieldGet(this, _YargsInstance_command, "f").hasDefaultCommand() && !skipRecommendation) {
4770
- const innerArgv = __classPrivateFieldGet(this, _YargsInstance_command, "f").runCommand(null, this, parsed, 0, helpOnly, helpOptSet || versionOptSet || helpOnly);
4771
- return this[kPostProcess](innerArgv, populateDoubleDash, !!calledFromCommand, false);
4772
- }
4773
- if (requestCompletions) {
4774
- if (__classPrivateFieldGet(this, _YargsInstance_exitProcess, "f"))
4775
- setBlocking(true);
4776
- args = [].concat(args);
4777
- const completionArgs = args.slice(args.indexOf(`--${__classPrivateFieldGet(this, _YargsInstance_completion, "f").completionKey}`) + 1);
4778
- __classPrivateFieldGet(this, _YargsInstance_completion, "f").getCompletion(completionArgs, (err, completions) => {
4779
- if (err)
4780
- throw new YError(err.message);
4781
- (completions || []).forEach((completion2) => {
4782
- __classPrivateFieldGet(this, _YargsInstance_logger, "f").log(completion2);
4783
- });
4784
- this.exit(0);
4785
- });
4786
- return this[kPostProcess](argv, !populateDoubleDash, !!calledFromCommand, false);
4787
- }
4788
- if (!__classPrivateFieldGet(this, _YargsInstance_hasOutput, "f")) {
4789
- if (helpOptSet) {
4790
- if (__classPrivateFieldGet(this, _YargsInstance_exitProcess, "f"))
4791
- setBlocking(true);
4792
- skipValidation = true;
4793
- this.showHelp("log");
4794
- this.exit(0);
4795
- } else if (versionOptSet) {
4796
- if (__classPrivateFieldGet(this, _YargsInstance_exitProcess, "f"))
4797
- setBlocking(true);
4798
- skipValidation = true;
4799
- __classPrivateFieldGet(this, _YargsInstance_usage, "f").showVersion("log");
4800
- this.exit(0);
4801
- }
4802
- }
4803
- if (!skipValidation && __classPrivateFieldGet(this, _YargsInstance_options, "f").skipValidation.length > 0) {
4804
- skipValidation = Object.keys(argv).some((key) => __classPrivateFieldGet(this, _YargsInstance_options, "f").skipValidation.indexOf(key) >= 0 && argv[key] === true);
4805
- }
4806
- if (!skipValidation) {
4807
- if (parsed.error)
4808
- throw new YError(parsed.error.message);
4809
- if (!requestCompletions) {
4810
- const validation2 = this[kRunValidation](aliases, {}, parsed.error);
4811
- if (!calledFromCommand) {
4812
- argvPromise = applyMiddleware(argv, this, __classPrivateFieldGet(this, _YargsInstance_globalMiddleware, "f").getMiddleware(), true);
4813
- }
4814
- argvPromise = this[kValidateAsync](validation2, argvPromise !== null && argvPromise !== undefined ? argvPromise : argv);
4815
- if (isPromise(argvPromise) && !calledFromCommand) {
4816
- argvPromise = argvPromise.then(() => {
4817
- return applyMiddleware(argv, this, __classPrivateFieldGet(this, _YargsInstance_globalMiddleware, "f").getMiddleware(), false);
4818
- });
4819
- }
4820
- }
4821
- }
4822
- } catch (err) {
4823
- if (err instanceof YError)
4824
- __classPrivateFieldGet(this, _YargsInstance_usage, "f").fail(err.message, err);
4825
- else
4826
- throw err;
4827
- }
4828
- return this[kPostProcess](argvPromise !== null && argvPromise !== undefined ? argvPromise : argv, populateDoubleDash, !!calledFromCommand, true);
4829
- }
4830
- [kRunValidation](aliases, positionalMap, parseErrors, isDefaultCommand) {
4831
- const demandedOptions = { ...this.getDemandedOptions() };
4832
- return (argv) => {
4833
- if (parseErrors)
4834
- throw new YError(parseErrors.message);
4835
- __classPrivateFieldGet(this, _YargsInstance_validation, "f").nonOptionCount(argv);
4836
- __classPrivateFieldGet(this, _YargsInstance_validation, "f").requiredArguments(argv, demandedOptions);
4837
- let failedStrictCommands = false;
4838
- if (__classPrivateFieldGet(this, _YargsInstance_strictCommands, "f")) {
4839
- failedStrictCommands = __classPrivateFieldGet(this, _YargsInstance_validation, "f").unknownCommands(argv);
4840
- }
4841
- if (__classPrivateFieldGet(this, _YargsInstance_strict, "f") && !failedStrictCommands) {
4842
- __classPrivateFieldGet(this, _YargsInstance_validation, "f").unknownArguments(argv, aliases, positionalMap, !!isDefaultCommand);
4843
- } else if (__classPrivateFieldGet(this, _YargsInstance_strictOptions, "f")) {
4844
- __classPrivateFieldGet(this, _YargsInstance_validation, "f").unknownArguments(argv, aliases, {}, false, false);
4845
- }
4846
- __classPrivateFieldGet(this, _YargsInstance_validation, "f").limitedChoices(argv);
4847
- __classPrivateFieldGet(this, _YargsInstance_validation, "f").implications(argv);
4848
- __classPrivateFieldGet(this, _YargsInstance_validation, "f").conflicting(argv);
4849
- };
4850
- }
4851
- [kSetHasOutput]() {
4852
- __classPrivateFieldSet(this, _YargsInstance_hasOutput, true, "f");
4853
- }
4854
- [kTrackManuallySetKeys](keys) {
4855
- if (typeof keys === "string") {
4856
- __classPrivateFieldGet(this, _YargsInstance_options, "f").key[keys] = true;
4857
- } else {
4858
- for (const k of keys) {
4859
- __classPrivateFieldGet(this, _YargsInstance_options, "f").key[k] = true;
4860
- }
4861
- }
4862
- }
4863
- }
4864
- function isYargsInstance(y) {
4865
- return !!y && typeof y.getInternalMethods === "function";
4866
- }
4867
-
4868
- // ../../node_modules/yargs/index.mjs
4869
- var Yargs = YargsFactory(esm_default);
4870
- var yargs_default = Yargs;
4871
-
4872
- // src/cli.ts
4873
- var y = yargs_default(hideBin(process.argv));
10
+ import yargs from "yargs";
11
+ import { hideBin } from "yargs/helpers";
12
+ var y = yargs(hideBin(process.argv));
4874
13
  function errorExit(title, text) {
4875
14
  console.error(chalk.red.bold(title + `
4876
15
  `));
@@ -4880,14 +19,19 @@ function errorExit(title, text) {
4880
19
  }
4881
20
  process.exit(1);
4882
21
  }
4883
- y.command("generate-types", "generates typescript types", (yargs) => yargs.option("access-token", {
4884
- describe: "access token"
22
+ y.command("generate-types", "generates typescript types", (yargs2) => yargs2.option("access-token", {
23
+ describe: "access token",
24
+ type: "string"
4885
25
  }).option("outfile", {
4886
26
  default: "requence-env.d.ts"
4887
27
  }).option("outdir", {
4888
28
  default: ""
4889
29
  }), async (argv) => {
4890
- const token = argv.accessToken ?? process.env.REQUENCE_ACCESS_TOKEN ?? JSON.parse(fs.readFileSync("package.json", "utf-8")).requence?.accessToken;
30
+ let token = argv.accessToken ?? process.env.REQUENCE_TASK_ACCESS_TOKEN ?? process.env.REQUENCE_ACCESS_TOKEN;
31
+ if (!token) {
32
+ const pkgJson = JSON.parse(fs.readFileSync("package.json", "utf-8"));
33
+ token = pkgJson.requence?.task?.accessToken ?? pkgJson.requence?.accessToken;
34
+ }
4891
35
  console.info();
4892
36
  if (!token) {
4893
37
  errorExit("No access token found", `You can provide the access token as argument to ${chalk.bold("createTask")},
@@ -4899,7 +43,7 @@ in your ${chalk.bold("package.json")} in ${chalk.bold("requence.accessToken")}`)
4899
43
  errorExit("Invalid access token");
4900
44
  }
4901
45
  const [, accessToken, serverUrl] = parts;
4902
- console.info(chalk.gray(`generating typescript definitions…`));
46
+ console.info(chalk.gray("generating typescript definitions…"));
4903
47
  const response = await fetch(serverUrl + "/task/types/typescript", {
4904
48
  method: "GET",
4905
49
  headers: {
@@ -4911,14 +55,17 @@ in your ${chalk.bold("package.json")} in ${chalk.bold("requence.accessToken")}`)
4911
55
  errorExit(error);
4912
56
  }
4913
57
  const text = await response.text();
4914
- const data = `/* eslint-disable */
4915
- /* prettier-ignore */
4916
-
4917
- ${text}`;
58
+ const data = [
59
+ "/* eslint-disable */",
60
+ "/* oxlint-disable */",
61
+ "/* prettier-ignore */",
62
+ text
63
+ ].join(`
64
+ `);
4918
65
  const file = path.join(argv.outdir || process.cwd(), argv.outfile);
4919
66
  fs.writeFileSync(file, data);
4920
67
  console.info(chalk.green("types saved to", chalk.bold(path.relative(process.cwd(), file))));
4921
68
  }).scriptName("requence-task").help("h").demandCommand(1, 1).strict().parse();
4922
69
 
4923
- //# debugId=B7E3681F48E5677864756E2164756E21
70
+ //# debugId=F960044E10AD164964756E2164756E21
4924
71
  //# sourceMappingURL=cli.js.map