@vexify-org/yaggs 5.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/parser.js +28 -0
- package/package.json +1 -1
package/lib/parser.js
CHANGED
|
@@ -39,6 +39,8 @@ class ArgumentParser {
|
|
|
39
39
|
demandOption: config.demandOption || config.required || false,
|
|
40
40
|
normalize: config.normalize,
|
|
41
41
|
hidden: config.hidden || false,
|
|
42
|
+
conflicts: config.conflicts || [],
|
|
43
|
+
implies: config.implies || {},
|
|
42
44
|
...config
|
|
43
45
|
};
|
|
44
46
|
|
|
@@ -313,6 +315,8 @@ class ArgumentParser {
|
|
|
313
315
|
this._applyTypeConversion(result);
|
|
314
316
|
this._validateOptions(result);
|
|
315
317
|
this._validatePositionals(result);
|
|
318
|
+
this._validateConflicts(result);
|
|
319
|
+
this._applyImplies(result);
|
|
316
320
|
|
|
317
321
|
if (currentCommand && this.commands[currentCommand]) {
|
|
318
322
|
result.command = currentCommand;
|
|
@@ -453,6 +457,30 @@ class ArgumentParser {
|
|
|
453
457
|
}
|
|
454
458
|
}
|
|
455
459
|
|
|
460
|
+
_validateConflicts(result) {
|
|
461
|
+
for (const [name, opt] of Object.entries(this.options)) {
|
|
462
|
+
if (result[name] !== undefined && opt.conflicts.length > 0) {
|
|
463
|
+
for (const conflict of opt.conflicts) {
|
|
464
|
+
if (result[conflict] !== undefined) {
|
|
465
|
+
this._handleError(`Option '${name}' conflicts with '${conflict}'`);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
_applyImplies(result) {
|
|
473
|
+
for (const [name, opt] of Object.entries(this.options)) {
|
|
474
|
+
if (result[name] !== undefined && Object.keys(opt.implies).length > 0) {
|
|
475
|
+
for (const [impliedName, impliedValue] of Object.entries(opt.implies)) {
|
|
476
|
+
if (result[impliedName] === undefined) {
|
|
477
|
+
result[impliedName] = impliedValue;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
456
484
|
_handleError(message) {
|
|
457
485
|
if (this.errorHandler) {
|
|
458
486
|
this.errorHandler(message);
|