@slicemachine/init 1.1.19-dev-release-feb.2 → 1.1.19

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 (42) hide show
  1. package/build/index.js +1 -1
  2. package/dist/__node_modules/lines-and-columns/build/index.cjs +64 -0
  3. package/dist/__node_modules/lines-and-columns/build/index.cjs.map +1 -0
  4. package/dist/__node_modules/lines-and-columns/build/index.js +63 -0
  5. package/dist/__node_modules/lines-and-columns/build/index.js.map +1 -0
  6. package/dist/__node_modules/meow/__node_modules/yargs-parser/build/lib/index.cjs +56 -0
  7. package/dist/__node_modules/meow/__node_modules/yargs-parser/build/lib/index.cjs.map +1 -0
  8. package/dist/__node_modules/meow/__node_modules/yargs-parser/build/lib/index.js +57 -0
  9. package/dist/__node_modules/meow/__node_modules/yargs-parser/build/lib/index.js.map +1 -0
  10. package/dist/__node_modules/meow/__node_modules/yargs-parser/build/lib/string-utils.cjs +63 -0
  11. package/dist/__node_modules/meow/__node_modules/yargs-parser/build/lib/string-utils.cjs.map +1 -0
  12. package/dist/__node_modules/meow/__node_modules/yargs-parser/build/lib/string-utils.js +63 -0
  13. package/dist/__node_modules/meow/__node_modules/yargs-parser/build/lib/string-utils.js.map +1 -0
  14. package/dist/__node_modules/meow/__node_modules/yargs-parser/build/lib/tokenize-arg-string.cjs +39 -0
  15. package/dist/__node_modules/meow/__node_modules/yargs-parser/build/lib/tokenize-arg-string.cjs.map +1 -0
  16. package/dist/__node_modules/meow/__node_modules/yargs-parser/build/lib/tokenize-arg-string.js +39 -0
  17. package/dist/__node_modules/meow/__node_modules/yargs-parser/build/lib/tokenize-arg-string.js.map +1 -0
  18. package/dist/__node_modules/meow/__node_modules/yargs-parser/build/lib/yargs-parser-types.cjs +15 -0
  19. package/dist/__node_modules/meow/__node_modules/yargs-parser/build/lib/yargs-parser-types.cjs.map +1 -0
  20. package/dist/__node_modules/meow/__node_modules/yargs-parser/build/lib/yargs-parser-types.js +16 -0
  21. package/dist/__node_modules/meow/__node_modules/yargs-parser/build/lib/yargs-parser-types.js.map +1 -0
  22. package/dist/__node_modules/meow/__node_modules/yargs-parser/build/lib/yargs-parser.cjs +847 -0
  23. package/dist/__node_modules/meow/__node_modules/yargs-parser/build/lib/yargs-parser.cjs.map +1 -0
  24. package/dist/__node_modules/meow/__node_modules/yargs-parser/build/lib/yargs-parser.js +847 -0
  25. package/dist/__node_modules/meow/__node_modules/yargs-parser/build/lib/yargs-parser.js.map +1 -0
  26. package/dist/packages/init/__node_modules/human-signals/build/src/core.cjs +275 -0
  27. package/dist/packages/init/__node_modules/human-signals/build/src/core.cjs.map +1 -0
  28. package/dist/packages/init/__node_modules/human-signals/build/src/core.js +275 -0
  29. package/dist/packages/init/__node_modules/human-signals/build/src/core.js.map +1 -0
  30. package/dist/packages/init/__node_modules/human-signals/build/src/main.cjs +50 -0
  31. package/dist/packages/init/__node_modules/human-signals/build/src/main.cjs.map +1 -0
  32. package/dist/packages/init/__node_modules/human-signals/build/src/main.js +50 -0
  33. package/dist/packages/init/__node_modules/human-signals/build/src/main.js.map +1 -0
  34. package/dist/packages/init/__node_modules/human-signals/build/src/realtime.cjs +20 -0
  35. package/dist/packages/init/__node_modules/human-signals/build/src/realtime.cjs.map +1 -0
  36. package/dist/packages/init/__node_modules/human-signals/build/src/realtime.js +20 -0
  37. package/dist/packages/init/__node_modules/human-signals/build/src/realtime.js.map +1 -0
  38. package/dist/packages/init/__node_modules/human-signals/build/src/signals.cjs +27 -0
  39. package/dist/packages/init/__node_modules/human-signals/build/src/signals.cjs.map +1 -0
  40. package/dist/packages/init/__node_modules/human-signals/build/src/signals.js +27 -0
  41. package/dist/packages/init/__node_modules/human-signals/build/src/signals.js.map +1 -0
  42. package/package.json +4 -4
@@ -0,0 +1,847 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const tokenizeArgString = require("./tokenize-arg-string.cjs");
4
+ const yargsParserTypes = require("./yargs-parser-types.cjs");
5
+ const stringUtils = require("./string-utils.cjs");
6
+ /**
7
+ * @license
8
+ * Copyright (c) 2016, Contributors
9
+ * SPDX-License-Identifier: ISC
10
+ */
11
+ let mixin;
12
+ class YargsParser {
13
+ constructor(_mixin) {
14
+ mixin = _mixin;
15
+ }
16
+ parse(argsInput, options) {
17
+ const opts = Object.assign({
18
+ alias: void 0,
19
+ array: void 0,
20
+ boolean: void 0,
21
+ config: void 0,
22
+ configObjects: void 0,
23
+ configuration: void 0,
24
+ coerce: void 0,
25
+ count: void 0,
26
+ default: void 0,
27
+ envPrefix: void 0,
28
+ narg: void 0,
29
+ normalize: void 0,
30
+ string: void 0,
31
+ number: void 0,
32
+ __: void 0,
33
+ key: void 0
34
+ }, options);
35
+ const args = tokenizeArgString.tokenizeArgString(argsInput);
36
+ const inputIsString = typeof argsInput === "string";
37
+ const aliases = combineAliases(Object.assign(/* @__PURE__ */ Object.create(null), opts.alias));
38
+ const configuration = Object.assign({
39
+ "boolean-negation": true,
40
+ "camel-case-expansion": true,
41
+ "combine-arrays": false,
42
+ "dot-notation": true,
43
+ "duplicate-arguments-array": true,
44
+ "flatten-duplicate-arrays": true,
45
+ "greedy-arrays": true,
46
+ "halt-at-non-option": false,
47
+ "nargs-eats-options": false,
48
+ "negation-prefix": "no-",
49
+ "parse-numbers": true,
50
+ "parse-positional-numbers": true,
51
+ "populate--": false,
52
+ "set-placeholder-key": false,
53
+ "short-option-groups": true,
54
+ "strip-aliased": false,
55
+ "strip-dashed": false,
56
+ "unknown-options-as-args": false
57
+ }, opts.configuration);
58
+ const defaults = Object.assign(/* @__PURE__ */ Object.create(null), opts.default);
59
+ const configObjects = opts.configObjects || [];
60
+ const envPrefix = opts.envPrefix;
61
+ const notFlagsOption = configuration["populate--"];
62
+ const notFlagsArgv = notFlagsOption ? "--" : "_";
63
+ const newAliases = /* @__PURE__ */ Object.create(null);
64
+ const defaulted = /* @__PURE__ */ Object.create(null);
65
+ const __ = opts.__ || mixin.format;
66
+ const flags = {
67
+ aliases: /* @__PURE__ */ Object.create(null),
68
+ arrays: /* @__PURE__ */ Object.create(null),
69
+ bools: /* @__PURE__ */ Object.create(null),
70
+ strings: /* @__PURE__ */ Object.create(null),
71
+ numbers: /* @__PURE__ */ Object.create(null),
72
+ counts: /* @__PURE__ */ Object.create(null),
73
+ normalize: /* @__PURE__ */ Object.create(null),
74
+ configs: /* @__PURE__ */ Object.create(null),
75
+ nargs: /* @__PURE__ */ Object.create(null),
76
+ coercions: /* @__PURE__ */ Object.create(null),
77
+ keys: []
78
+ };
79
+ const negative = /^-([0-9]+(\.[0-9]+)?|\.[0-9]+)$/;
80
+ const negatedBoolean = new RegExp("^--" + configuration["negation-prefix"] + "(.+)");
81
+ [].concat(opts.array || []).filter(Boolean).forEach(function(opt) {
82
+ const key = typeof opt === "object" ? opt.key : opt;
83
+ const assignment = Object.keys(opt).map(function(key2) {
84
+ const arrayFlagKeys = {
85
+ boolean: "bools",
86
+ string: "strings",
87
+ number: "numbers"
88
+ };
89
+ return arrayFlagKeys[key2];
90
+ }).filter(Boolean).pop();
91
+ if (assignment) {
92
+ flags[assignment][key] = true;
93
+ }
94
+ flags.arrays[key] = true;
95
+ flags.keys.push(key);
96
+ });
97
+ [].concat(opts.boolean || []).filter(Boolean).forEach(function(key) {
98
+ flags.bools[key] = true;
99
+ flags.keys.push(key);
100
+ });
101
+ [].concat(opts.string || []).filter(Boolean).forEach(function(key) {
102
+ flags.strings[key] = true;
103
+ flags.keys.push(key);
104
+ });
105
+ [].concat(opts.number || []).filter(Boolean).forEach(function(key) {
106
+ flags.numbers[key] = true;
107
+ flags.keys.push(key);
108
+ });
109
+ [].concat(opts.count || []).filter(Boolean).forEach(function(key) {
110
+ flags.counts[key] = true;
111
+ flags.keys.push(key);
112
+ });
113
+ [].concat(opts.normalize || []).filter(Boolean).forEach(function(key) {
114
+ flags.normalize[key] = true;
115
+ flags.keys.push(key);
116
+ });
117
+ if (typeof opts.narg === "object") {
118
+ Object.entries(opts.narg).forEach(([key, value]) => {
119
+ if (typeof value === "number") {
120
+ flags.nargs[key] = value;
121
+ flags.keys.push(key);
122
+ }
123
+ });
124
+ }
125
+ if (typeof opts.coerce === "object") {
126
+ Object.entries(opts.coerce).forEach(([key, value]) => {
127
+ if (typeof value === "function") {
128
+ flags.coercions[key] = value;
129
+ flags.keys.push(key);
130
+ }
131
+ });
132
+ }
133
+ if (typeof opts.config !== "undefined") {
134
+ if (Array.isArray(opts.config) || typeof opts.config === "string") {
135
+ [].concat(opts.config).filter(Boolean).forEach(function(key) {
136
+ flags.configs[key] = true;
137
+ });
138
+ } else if (typeof opts.config === "object") {
139
+ Object.entries(opts.config).forEach(([key, value]) => {
140
+ if (typeof value === "boolean" || typeof value === "function") {
141
+ flags.configs[key] = value;
142
+ }
143
+ });
144
+ }
145
+ }
146
+ extendAliases(opts.key, aliases, opts.default, flags.arrays);
147
+ Object.keys(defaults).forEach(function(key) {
148
+ (flags.aliases[key] || []).forEach(function(alias) {
149
+ defaults[alias] = defaults[key];
150
+ });
151
+ });
152
+ let error = null;
153
+ checkConfiguration();
154
+ let notFlags = [];
155
+ const argv = Object.assign(/* @__PURE__ */ Object.create(null), { _: [] });
156
+ const argvReturn = {};
157
+ for (let i = 0; i < args.length; i++) {
158
+ const arg = args[i];
159
+ const truncatedArg = arg.replace(/^-{3,}/, "---");
160
+ let broken;
161
+ let key;
162
+ let letters;
163
+ let m;
164
+ let next;
165
+ let value;
166
+ if (arg !== "--" && /^-/.test(arg) && isUnknownOptionAsArg(arg)) {
167
+ pushPositional(arg);
168
+ } else if (truncatedArg.match(/^---+(=|$)/)) {
169
+ pushPositional(arg);
170
+ continue;
171
+ } else if (arg.match(/^--.+=/) || !configuration["short-option-groups"] && arg.match(/^-.+=/)) {
172
+ m = arg.match(/^--?([^=]+)=([\s\S]*)$/);
173
+ if (m !== null && Array.isArray(m) && m.length >= 3) {
174
+ if (checkAllAliases(m[1], flags.arrays)) {
175
+ i = eatArray(i, m[1], args, m[2]);
176
+ } else if (checkAllAliases(m[1], flags.nargs) !== false) {
177
+ i = eatNargs(i, m[1], args, m[2]);
178
+ } else {
179
+ setArg(m[1], m[2], true);
180
+ }
181
+ }
182
+ } else if (arg.match(negatedBoolean) && configuration["boolean-negation"]) {
183
+ m = arg.match(negatedBoolean);
184
+ if (m !== null && Array.isArray(m) && m.length >= 2) {
185
+ key = m[1];
186
+ setArg(key, checkAllAliases(key, flags.arrays) ? [false] : false);
187
+ }
188
+ } else if (arg.match(/^--.+/) || !configuration["short-option-groups"] && arg.match(/^-[^-]+/)) {
189
+ m = arg.match(/^--?(.+)/);
190
+ if (m !== null && Array.isArray(m) && m.length >= 2) {
191
+ key = m[1];
192
+ if (checkAllAliases(key, flags.arrays)) {
193
+ i = eatArray(i, key, args);
194
+ } else if (checkAllAliases(key, flags.nargs) !== false) {
195
+ i = eatNargs(i, key, args);
196
+ } else {
197
+ next = args[i + 1];
198
+ if (next !== void 0 && (!next.match(/^-/) || next.match(negative)) && !checkAllAliases(key, flags.bools) && !checkAllAliases(key, flags.counts)) {
199
+ setArg(key, next);
200
+ i++;
201
+ } else if (/^(true|false)$/.test(next)) {
202
+ setArg(key, next);
203
+ i++;
204
+ } else {
205
+ setArg(key, defaultValue(key));
206
+ }
207
+ }
208
+ }
209
+ } else if (arg.match(/^-.\..+=/)) {
210
+ m = arg.match(/^-([^=]+)=([\s\S]*)$/);
211
+ if (m !== null && Array.isArray(m) && m.length >= 3) {
212
+ setArg(m[1], m[2]);
213
+ }
214
+ } else if (arg.match(/^-.\..+/) && !arg.match(negative)) {
215
+ next = args[i + 1];
216
+ m = arg.match(/^-(.\..+)/);
217
+ if (m !== null && Array.isArray(m) && m.length >= 2) {
218
+ key = m[1];
219
+ if (next !== void 0 && !next.match(/^-/) && !checkAllAliases(key, flags.bools) && !checkAllAliases(key, flags.counts)) {
220
+ setArg(key, next);
221
+ i++;
222
+ } else {
223
+ setArg(key, defaultValue(key));
224
+ }
225
+ }
226
+ } else if (arg.match(/^-[^-]+/) && !arg.match(negative)) {
227
+ letters = arg.slice(1, -1).split("");
228
+ broken = false;
229
+ for (let j = 0; j < letters.length; j++) {
230
+ next = arg.slice(j + 2);
231
+ if (letters[j + 1] && letters[j + 1] === "=") {
232
+ value = arg.slice(j + 3);
233
+ key = letters[j];
234
+ if (checkAllAliases(key, flags.arrays)) {
235
+ i = eatArray(i, key, args, value);
236
+ } else if (checkAllAliases(key, flags.nargs) !== false) {
237
+ i = eatNargs(i, key, args, value);
238
+ } else {
239
+ setArg(key, value);
240
+ }
241
+ broken = true;
242
+ break;
243
+ }
244
+ if (next === "-") {
245
+ setArg(letters[j], next);
246
+ continue;
247
+ }
248
+ if (/[A-Za-z]/.test(letters[j]) && /^-?\d+(\.\d*)?(e-?\d+)?$/.test(next) && checkAllAliases(next, flags.bools) === false) {
249
+ setArg(letters[j], next);
250
+ broken = true;
251
+ break;
252
+ }
253
+ if (letters[j + 1] && letters[j + 1].match(/\W/)) {
254
+ setArg(letters[j], next);
255
+ broken = true;
256
+ break;
257
+ } else {
258
+ setArg(letters[j], defaultValue(letters[j]));
259
+ }
260
+ }
261
+ key = arg.slice(-1)[0];
262
+ if (!broken && key !== "-") {
263
+ if (checkAllAliases(key, flags.arrays)) {
264
+ i = eatArray(i, key, args);
265
+ } else if (checkAllAliases(key, flags.nargs) !== false) {
266
+ i = eatNargs(i, key, args);
267
+ } else {
268
+ next = args[i + 1];
269
+ if (next !== void 0 && (!/^(-|--)[^-]/.test(next) || next.match(negative)) && !checkAllAliases(key, flags.bools) && !checkAllAliases(key, flags.counts)) {
270
+ setArg(key, next);
271
+ i++;
272
+ } else if (/^(true|false)$/.test(next)) {
273
+ setArg(key, next);
274
+ i++;
275
+ } else {
276
+ setArg(key, defaultValue(key));
277
+ }
278
+ }
279
+ }
280
+ } else if (arg.match(/^-[0-9]$/) && arg.match(negative) && checkAllAliases(arg.slice(1), flags.bools)) {
281
+ key = arg.slice(1);
282
+ setArg(key, defaultValue(key));
283
+ } else if (arg === "--") {
284
+ notFlags = args.slice(i + 1);
285
+ break;
286
+ } else if (configuration["halt-at-non-option"]) {
287
+ notFlags = args.slice(i);
288
+ break;
289
+ } else {
290
+ pushPositional(arg);
291
+ }
292
+ }
293
+ applyEnvVars(argv, true);
294
+ applyEnvVars(argv, false);
295
+ setConfig(argv);
296
+ setConfigObjects();
297
+ applyDefaultsAndAliases(argv, flags.aliases, defaults, true);
298
+ applyCoercions(argv);
299
+ if (configuration["set-placeholder-key"])
300
+ setPlaceholderKeys(argv);
301
+ Object.keys(flags.counts).forEach(function(key) {
302
+ if (!hasKey(argv, key.split(".")))
303
+ setArg(key, 0);
304
+ });
305
+ if (notFlagsOption && notFlags.length)
306
+ argv[notFlagsArgv] = [];
307
+ notFlags.forEach(function(key) {
308
+ argv[notFlagsArgv].push(key);
309
+ });
310
+ if (configuration["camel-case-expansion"] && configuration["strip-dashed"]) {
311
+ Object.keys(argv).filter((key) => key !== "--" && key.includes("-")).forEach((key) => {
312
+ delete argv[key];
313
+ });
314
+ }
315
+ if (configuration["strip-aliased"]) {
316
+ [].concat(...Object.keys(aliases).map((k) => aliases[k])).forEach((alias) => {
317
+ if (configuration["camel-case-expansion"] && alias.includes("-")) {
318
+ delete argv[alias.split(".").map((prop) => stringUtils.camelCase(prop)).join(".")];
319
+ }
320
+ delete argv[alias];
321
+ });
322
+ }
323
+ function pushPositional(arg) {
324
+ const maybeCoercedNumber = maybeCoerceNumber("_", arg);
325
+ if (typeof maybeCoercedNumber === "string" || typeof maybeCoercedNumber === "number") {
326
+ argv._.push(maybeCoercedNumber);
327
+ }
328
+ }
329
+ function eatNargs(i, key, args2, argAfterEqualSign) {
330
+ let ii;
331
+ let toEat = checkAllAliases(key, flags.nargs);
332
+ toEat = typeof toEat !== "number" || isNaN(toEat) ? 1 : toEat;
333
+ if (toEat === 0) {
334
+ if (!isUndefined(argAfterEqualSign)) {
335
+ error = Error(__("Argument unexpected for: %s", key));
336
+ }
337
+ setArg(key, defaultValue(key));
338
+ return i;
339
+ }
340
+ let available = isUndefined(argAfterEqualSign) ? 0 : 1;
341
+ if (configuration["nargs-eats-options"]) {
342
+ if (args2.length - (i + 1) + available < toEat) {
343
+ error = Error(__("Not enough arguments following: %s", key));
344
+ }
345
+ available = toEat;
346
+ } else {
347
+ for (ii = i + 1; ii < args2.length; ii++) {
348
+ if (!args2[ii].match(/^-[^0-9]/) || args2[ii].match(negative) || isUnknownOptionAsArg(args2[ii]))
349
+ available++;
350
+ else
351
+ break;
352
+ }
353
+ if (available < toEat)
354
+ error = Error(__("Not enough arguments following: %s", key));
355
+ }
356
+ let consumed = Math.min(available, toEat);
357
+ if (!isUndefined(argAfterEqualSign) && consumed > 0) {
358
+ setArg(key, argAfterEqualSign);
359
+ consumed--;
360
+ }
361
+ for (ii = i + 1; ii < consumed + i + 1; ii++) {
362
+ setArg(key, args2[ii]);
363
+ }
364
+ return i + consumed;
365
+ }
366
+ function eatArray(i, key, args2, argAfterEqualSign) {
367
+ let argsToSet = [];
368
+ let next = argAfterEqualSign || args2[i + 1];
369
+ const nargsCount = checkAllAliases(key, flags.nargs);
370
+ if (checkAllAliases(key, flags.bools) && !/^(true|false)$/.test(next)) {
371
+ argsToSet.push(true);
372
+ } else if (isUndefined(next) || isUndefined(argAfterEqualSign) && /^-/.test(next) && !negative.test(next) && !isUnknownOptionAsArg(next)) {
373
+ if (defaults[key] !== void 0) {
374
+ const defVal = defaults[key];
375
+ argsToSet = Array.isArray(defVal) ? defVal : [defVal];
376
+ }
377
+ } else {
378
+ if (!isUndefined(argAfterEqualSign)) {
379
+ argsToSet.push(processValue(key, argAfterEqualSign, true));
380
+ }
381
+ for (let ii = i + 1; ii < args2.length; ii++) {
382
+ if (!configuration["greedy-arrays"] && argsToSet.length > 0 || nargsCount && typeof nargsCount === "number" && argsToSet.length >= nargsCount)
383
+ break;
384
+ next = args2[ii];
385
+ if (/^-/.test(next) && !negative.test(next) && !isUnknownOptionAsArg(next))
386
+ break;
387
+ i = ii;
388
+ argsToSet.push(processValue(key, next, inputIsString));
389
+ }
390
+ }
391
+ if (typeof nargsCount === "number" && (nargsCount && argsToSet.length < nargsCount || isNaN(nargsCount) && argsToSet.length === 0)) {
392
+ error = Error(__("Not enough arguments following: %s", key));
393
+ }
394
+ setArg(key, argsToSet);
395
+ return i;
396
+ }
397
+ function setArg(key, val, shouldStripQuotes = inputIsString) {
398
+ if (/-/.test(key) && configuration["camel-case-expansion"]) {
399
+ const alias = key.split(".").map(function(prop) {
400
+ return stringUtils.camelCase(prop);
401
+ }).join(".");
402
+ addNewAlias(key, alias);
403
+ }
404
+ const value = processValue(key, val, shouldStripQuotes);
405
+ const splitKey = key.split(".");
406
+ setKey(argv, splitKey, value);
407
+ if (flags.aliases[key]) {
408
+ flags.aliases[key].forEach(function(x) {
409
+ const keyProperties = x.split(".");
410
+ setKey(argv, keyProperties, value);
411
+ });
412
+ }
413
+ if (splitKey.length > 1 && configuration["dot-notation"]) {
414
+ (flags.aliases[splitKey[0]] || []).forEach(function(x) {
415
+ let keyProperties = x.split(".");
416
+ const a = [].concat(splitKey);
417
+ a.shift();
418
+ keyProperties = keyProperties.concat(a);
419
+ if (!(flags.aliases[key] || []).includes(keyProperties.join("."))) {
420
+ setKey(argv, keyProperties, value);
421
+ }
422
+ });
423
+ }
424
+ if (checkAllAliases(key, flags.normalize) && !checkAllAliases(key, flags.arrays)) {
425
+ const keys = [key].concat(flags.aliases[key] || []);
426
+ keys.forEach(function(key2) {
427
+ Object.defineProperty(argvReturn, key2, {
428
+ enumerable: true,
429
+ get() {
430
+ return val;
431
+ },
432
+ set(value2) {
433
+ val = typeof value2 === "string" ? mixin.normalize(value2) : value2;
434
+ }
435
+ });
436
+ });
437
+ }
438
+ }
439
+ function addNewAlias(key, alias) {
440
+ if (!(flags.aliases[key] && flags.aliases[key].length)) {
441
+ flags.aliases[key] = [alias];
442
+ newAliases[alias] = true;
443
+ }
444
+ if (!(flags.aliases[alias] && flags.aliases[alias].length)) {
445
+ addNewAlias(alias, key);
446
+ }
447
+ }
448
+ function processValue(key, val, shouldStripQuotes) {
449
+ if (shouldStripQuotes) {
450
+ val = stripQuotes(val);
451
+ }
452
+ if (checkAllAliases(key, flags.bools) || checkAllAliases(key, flags.counts)) {
453
+ if (typeof val === "string")
454
+ val = val === "true";
455
+ }
456
+ let value = Array.isArray(val) ? val.map(function(v) {
457
+ return maybeCoerceNumber(key, v);
458
+ }) : maybeCoerceNumber(key, val);
459
+ if (checkAllAliases(key, flags.counts) && (isUndefined(value) || typeof value === "boolean")) {
460
+ value = increment();
461
+ }
462
+ if (checkAllAliases(key, flags.normalize) && checkAllAliases(key, flags.arrays)) {
463
+ if (Array.isArray(val))
464
+ value = val.map((val2) => {
465
+ return mixin.normalize(val2);
466
+ });
467
+ else
468
+ value = mixin.normalize(val);
469
+ }
470
+ return value;
471
+ }
472
+ function maybeCoerceNumber(key, value) {
473
+ if (!configuration["parse-positional-numbers"] && key === "_")
474
+ return value;
475
+ if (!checkAllAliases(key, flags.strings) && !checkAllAliases(key, flags.bools) && !Array.isArray(value)) {
476
+ const shouldCoerceNumber = stringUtils.looksLikeNumber(value) && configuration["parse-numbers"] && Number.isSafeInteger(Math.floor(parseFloat(`${value}`)));
477
+ if (shouldCoerceNumber || !isUndefined(value) && checkAllAliases(key, flags.numbers)) {
478
+ value = Number(value);
479
+ }
480
+ }
481
+ return value;
482
+ }
483
+ function setConfig(argv2) {
484
+ const configLookup = /* @__PURE__ */ Object.create(null);
485
+ applyDefaultsAndAliases(configLookup, flags.aliases, defaults);
486
+ Object.keys(flags.configs).forEach(function(configKey) {
487
+ const configPath = argv2[configKey] || configLookup[configKey];
488
+ if (configPath) {
489
+ try {
490
+ let config = null;
491
+ const resolvedConfigPath = mixin.resolve(mixin.cwd(), configPath);
492
+ const resolveConfig = flags.configs[configKey];
493
+ if (typeof resolveConfig === "function") {
494
+ try {
495
+ config = resolveConfig(resolvedConfigPath);
496
+ } catch (e) {
497
+ config = e;
498
+ }
499
+ if (config instanceof Error) {
500
+ error = config;
501
+ return;
502
+ }
503
+ } else {
504
+ config = mixin.require(resolvedConfigPath);
505
+ }
506
+ setConfigObject(config);
507
+ } catch (ex) {
508
+ if (ex.name === "PermissionDenied")
509
+ error = ex;
510
+ else if (argv2[configKey])
511
+ error = Error(__("Invalid JSON config file: %s", configPath));
512
+ }
513
+ }
514
+ });
515
+ }
516
+ function setConfigObject(config, prev) {
517
+ Object.keys(config).forEach(function(key) {
518
+ const value = config[key];
519
+ const fullKey = prev ? prev + "." + key : key;
520
+ if (typeof value === "object" && value !== null && !Array.isArray(value) && configuration["dot-notation"]) {
521
+ setConfigObject(value, fullKey);
522
+ } else {
523
+ if (!hasKey(argv, fullKey.split(".")) || checkAllAliases(fullKey, flags.arrays) && configuration["combine-arrays"]) {
524
+ setArg(fullKey, value);
525
+ }
526
+ }
527
+ });
528
+ }
529
+ function setConfigObjects() {
530
+ if (typeof configObjects !== "undefined") {
531
+ configObjects.forEach(function(configObject) {
532
+ setConfigObject(configObject);
533
+ });
534
+ }
535
+ }
536
+ function applyEnvVars(argv2, configOnly) {
537
+ if (typeof envPrefix === "undefined")
538
+ return;
539
+ const prefix = typeof envPrefix === "string" ? envPrefix : "";
540
+ const env = mixin.env();
541
+ Object.keys(env).forEach(function(envVar) {
542
+ if (prefix === "" || envVar.lastIndexOf(prefix, 0) === 0) {
543
+ const keys = envVar.split("__").map(function(key, i) {
544
+ if (i === 0) {
545
+ key = key.substring(prefix.length);
546
+ }
547
+ return stringUtils.camelCase(key);
548
+ });
549
+ if ((configOnly && flags.configs[keys.join(".")] || !configOnly) && !hasKey(argv2, keys)) {
550
+ setArg(keys.join("."), env[envVar]);
551
+ }
552
+ }
553
+ });
554
+ }
555
+ function applyCoercions(argv2) {
556
+ let coerce;
557
+ const applied = /* @__PURE__ */ new Set();
558
+ Object.keys(argv2).forEach(function(key) {
559
+ if (!applied.has(key)) {
560
+ coerce = checkAllAliases(key, flags.coercions);
561
+ if (typeof coerce === "function") {
562
+ try {
563
+ const value = maybeCoerceNumber(key, coerce(argv2[key]));
564
+ [].concat(flags.aliases[key] || [], key).forEach((ali) => {
565
+ applied.add(ali);
566
+ argv2[ali] = value;
567
+ });
568
+ } catch (err) {
569
+ error = err;
570
+ }
571
+ }
572
+ }
573
+ });
574
+ }
575
+ function setPlaceholderKeys(argv2) {
576
+ flags.keys.forEach((key) => {
577
+ if (~key.indexOf("."))
578
+ return;
579
+ if (typeof argv2[key] === "undefined")
580
+ argv2[key] = void 0;
581
+ });
582
+ return argv2;
583
+ }
584
+ function applyDefaultsAndAliases(obj, aliases2, defaults2, canLog = false) {
585
+ Object.keys(defaults2).forEach(function(key) {
586
+ if (!hasKey(obj, key.split("."))) {
587
+ setKey(obj, key.split("."), defaults2[key]);
588
+ if (canLog)
589
+ defaulted[key] = true;
590
+ (aliases2[key] || []).forEach(function(x) {
591
+ if (hasKey(obj, x.split(".")))
592
+ return;
593
+ setKey(obj, x.split("."), defaults2[key]);
594
+ });
595
+ }
596
+ });
597
+ }
598
+ function hasKey(obj, keys) {
599
+ let o = obj;
600
+ if (!configuration["dot-notation"])
601
+ keys = [keys.join(".")];
602
+ keys.slice(0, -1).forEach(function(key2) {
603
+ o = o[key2] || {};
604
+ });
605
+ const key = keys[keys.length - 1];
606
+ if (typeof o !== "object")
607
+ return false;
608
+ else
609
+ return key in o;
610
+ }
611
+ function setKey(obj, keys, value) {
612
+ let o = obj;
613
+ if (!configuration["dot-notation"])
614
+ keys = [keys.join(".")];
615
+ keys.slice(0, -1).forEach(function(key2) {
616
+ key2 = sanitizeKey(key2);
617
+ if (typeof o === "object" && o[key2] === void 0) {
618
+ o[key2] = {};
619
+ }
620
+ if (typeof o[key2] !== "object" || Array.isArray(o[key2])) {
621
+ if (Array.isArray(o[key2])) {
622
+ o[key2].push({});
623
+ } else {
624
+ o[key2] = [o[key2], {}];
625
+ }
626
+ o = o[key2][o[key2].length - 1];
627
+ } else {
628
+ o = o[key2];
629
+ }
630
+ });
631
+ const key = sanitizeKey(keys[keys.length - 1]);
632
+ const isTypeArray = checkAllAliases(keys.join("."), flags.arrays);
633
+ const isValueArray = Array.isArray(value);
634
+ let duplicate = configuration["duplicate-arguments-array"];
635
+ if (!duplicate && checkAllAliases(key, flags.nargs)) {
636
+ duplicate = true;
637
+ if (!isUndefined(o[key]) && flags.nargs[key] === 1 || Array.isArray(o[key]) && o[key].length === flags.nargs[key]) {
638
+ o[key] = void 0;
639
+ }
640
+ }
641
+ if (value === increment()) {
642
+ o[key] = increment(o[key]);
643
+ } else if (Array.isArray(o[key])) {
644
+ if (duplicate && isTypeArray && isValueArray) {
645
+ o[key] = configuration["flatten-duplicate-arrays"] ? o[key].concat(value) : (Array.isArray(o[key][0]) ? o[key] : [o[key]]).concat([value]);
646
+ } else if (!duplicate && Boolean(isTypeArray) === Boolean(isValueArray)) {
647
+ o[key] = value;
648
+ } else {
649
+ o[key] = o[key].concat([value]);
650
+ }
651
+ } else if (o[key] === void 0 && isTypeArray) {
652
+ o[key] = isValueArray ? value : [value];
653
+ } else if (duplicate && !(o[key] === void 0 || checkAllAliases(key, flags.counts) || checkAllAliases(key, flags.bools))) {
654
+ o[key] = [o[key], value];
655
+ } else {
656
+ o[key] = value;
657
+ }
658
+ }
659
+ function extendAliases(...args2) {
660
+ args2.forEach(function(obj) {
661
+ Object.keys(obj || {}).forEach(function(key) {
662
+ if (flags.aliases[key])
663
+ return;
664
+ flags.aliases[key] = [].concat(aliases[key] || []);
665
+ flags.aliases[key].concat(key).forEach(function(x) {
666
+ if (/-/.test(x) && configuration["camel-case-expansion"]) {
667
+ const c = stringUtils.camelCase(x);
668
+ if (c !== key && flags.aliases[key].indexOf(c) === -1) {
669
+ flags.aliases[key].push(c);
670
+ newAliases[c] = true;
671
+ }
672
+ }
673
+ });
674
+ flags.aliases[key].concat(key).forEach(function(x) {
675
+ if (x.length > 1 && /[A-Z]/.test(x) && configuration["camel-case-expansion"]) {
676
+ const c = stringUtils.decamelize(x, "-");
677
+ if (c !== key && flags.aliases[key].indexOf(c) === -1) {
678
+ flags.aliases[key].push(c);
679
+ newAliases[c] = true;
680
+ }
681
+ }
682
+ });
683
+ flags.aliases[key].forEach(function(x) {
684
+ flags.aliases[x] = [key].concat(flags.aliases[key].filter(function(y) {
685
+ return x !== y;
686
+ }));
687
+ });
688
+ });
689
+ });
690
+ }
691
+ function checkAllAliases(key, flag) {
692
+ const toCheck = [].concat(flags.aliases[key] || [], key);
693
+ const keys = Object.keys(flag);
694
+ const setAlias = toCheck.find((key2) => keys.includes(key2));
695
+ return setAlias ? flag[setAlias] : false;
696
+ }
697
+ function hasAnyFlag(key) {
698
+ const flagsKeys = Object.keys(flags);
699
+ const toCheck = [].concat(flagsKeys.map((k) => flags[k]));
700
+ return toCheck.some(function(flag) {
701
+ return Array.isArray(flag) ? flag.includes(key) : flag[key];
702
+ });
703
+ }
704
+ function hasFlagsMatching(arg, ...patterns) {
705
+ const toCheck = [].concat(...patterns);
706
+ return toCheck.some(function(pattern) {
707
+ const match = arg.match(pattern);
708
+ return match && hasAnyFlag(match[1]);
709
+ });
710
+ }
711
+ function hasAllShortFlags(arg) {
712
+ if (arg.match(negative) || !arg.match(/^-[^-]+/)) {
713
+ return false;
714
+ }
715
+ let hasAllFlags = true;
716
+ let next;
717
+ const letters = arg.slice(1).split("");
718
+ for (let j = 0; j < letters.length; j++) {
719
+ next = arg.slice(j + 2);
720
+ if (!hasAnyFlag(letters[j])) {
721
+ hasAllFlags = false;
722
+ break;
723
+ }
724
+ 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/)) {
725
+ break;
726
+ }
727
+ }
728
+ return hasAllFlags;
729
+ }
730
+ function isUnknownOptionAsArg(arg) {
731
+ return configuration["unknown-options-as-args"] && isUnknownOption(arg);
732
+ }
733
+ function isUnknownOption(arg) {
734
+ arg = arg.replace(/^-{3,}/, "--");
735
+ if (arg.match(negative)) {
736
+ return false;
737
+ }
738
+ if (hasAllShortFlags(arg)) {
739
+ return false;
740
+ }
741
+ const flagWithEquals = /^-+([^=]+?)=[\s\S]*$/;
742
+ const normalFlag = /^-+([^=]+?)$/;
743
+ const flagEndingInHyphen = /^-+([^=]+?)-$/;
744
+ const flagEndingInDigits = /^-+([^=]+?\d+)$/;
745
+ const flagEndingInNonWordCharacters = /^-+([^=]+?)\W+.*$/;
746
+ return !hasFlagsMatching(arg, flagWithEquals, negatedBoolean, normalFlag, flagEndingInHyphen, flagEndingInDigits, flagEndingInNonWordCharacters);
747
+ }
748
+ function defaultValue(key) {
749
+ if (!checkAllAliases(key, flags.bools) && !checkAllAliases(key, flags.counts) && `${key}` in defaults) {
750
+ return defaults[key];
751
+ } else {
752
+ return defaultForType(guessType(key));
753
+ }
754
+ }
755
+ function defaultForType(type) {
756
+ const def = {
757
+ [yargsParserTypes.DefaultValuesForTypeKey.BOOLEAN]: true,
758
+ [yargsParserTypes.DefaultValuesForTypeKey.STRING]: "",
759
+ [yargsParserTypes.DefaultValuesForTypeKey.NUMBER]: void 0,
760
+ [yargsParserTypes.DefaultValuesForTypeKey.ARRAY]: []
761
+ };
762
+ return def[type];
763
+ }
764
+ function guessType(key) {
765
+ let type = yargsParserTypes.DefaultValuesForTypeKey.BOOLEAN;
766
+ if (checkAllAliases(key, flags.strings))
767
+ type = yargsParserTypes.DefaultValuesForTypeKey.STRING;
768
+ else if (checkAllAliases(key, flags.numbers))
769
+ type = yargsParserTypes.DefaultValuesForTypeKey.NUMBER;
770
+ else if (checkAllAliases(key, flags.bools))
771
+ type = yargsParserTypes.DefaultValuesForTypeKey.BOOLEAN;
772
+ else if (checkAllAliases(key, flags.arrays))
773
+ type = yargsParserTypes.DefaultValuesForTypeKey.ARRAY;
774
+ return type;
775
+ }
776
+ function isUndefined(num) {
777
+ return num === void 0;
778
+ }
779
+ function checkConfiguration() {
780
+ Object.keys(flags.counts).find((key) => {
781
+ if (checkAllAliases(key, flags.arrays)) {
782
+ error = Error(__("Invalid configuration: %s, opts.count excludes opts.array.", key));
783
+ return true;
784
+ } else if (checkAllAliases(key, flags.nargs)) {
785
+ error = Error(__("Invalid configuration: %s, opts.count excludes opts.narg.", key));
786
+ return true;
787
+ }
788
+ return false;
789
+ });
790
+ }
791
+ return {
792
+ aliases: Object.assign({}, flags.aliases),
793
+ argv: Object.assign(argvReturn, argv),
794
+ configuration,
795
+ defaulted: Object.assign({}, defaulted),
796
+ error,
797
+ newAliases: Object.assign({}, newAliases)
798
+ };
799
+ }
800
+ }
801
+ function combineAliases(aliases) {
802
+ const aliasArrays = [];
803
+ const combined = /* @__PURE__ */ Object.create(null);
804
+ let change = true;
805
+ Object.keys(aliases).forEach(function(key) {
806
+ aliasArrays.push([].concat(aliases[key], key));
807
+ });
808
+ while (change) {
809
+ change = false;
810
+ for (let i = 0; i < aliasArrays.length; i++) {
811
+ for (let ii = i + 1; ii < aliasArrays.length; ii++) {
812
+ const intersect = aliasArrays[i].filter(function(v) {
813
+ return aliasArrays[ii].indexOf(v) !== -1;
814
+ });
815
+ if (intersect.length) {
816
+ aliasArrays[i] = aliasArrays[i].concat(aliasArrays[ii]);
817
+ aliasArrays.splice(ii, 1);
818
+ change = true;
819
+ break;
820
+ }
821
+ }
822
+ }
823
+ }
824
+ aliasArrays.forEach(function(aliasArray) {
825
+ aliasArray = aliasArray.filter(function(v, i, self) {
826
+ return self.indexOf(v) === i;
827
+ });
828
+ const lastAlias = aliasArray.pop();
829
+ if (lastAlias !== void 0 && typeof lastAlias === "string") {
830
+ combined[lastAlias] = aliasArray;
831
+ }
832
+ });
833
+ return combined;
834
+ }
835
+ function increment(orig) {
836
+ return orig !== void 0 ? orig + 1 : 1;
837
+ }
838
+ function sanitizeKey(key) {
839
+ if (key === "__proto__")
840
+ return "___proto___";
841
+ return key;
842
+ }
843
+ function stripQuotes(val) {
844
+ return typeof val === "string" && (val[0] === "'" || val[0] === '"') && val[val.length - 1] === val[0] ? val.substring(1, val.length - 1) : val;
845
+ }
846
+ exports.YargsParser = YargsParser;
847
+ //# sourceMappingURL=yargs-parser.cjs.map