@releasekit/release 0.7.19 → 0.7.20
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/dist/cli.js +3537 -79
- package/dist/dispatcher.js +3546 -88
- package/package.json +6 -6
package/dist/dispatcher.js
CHANGED
|
@@ -30922,7 +30922,7 @@ var require_runtime = __commonJS({
|
|
|
30922
30922
|
return ret2;
|
|
30923
30923
|
},
|
|
30924
30924
|
programs: [],
|
|
30925
|
-
program: function
|
|
30925
|
+
program: function program2(i, data, declaredBlockParams, blockParams, depths) {
|
|
30926
30926
|
var programWrapper = this.programs[i], fn = this.fn(i);
|
|
30927
30927
|
if (data || depths || blockParams || declaredBlockParams) {
|
|
30928
30928
|
programWrapper = wrapProgram(this, i, fn, data, declaredBlockParams, blockParams, depths);
|
|
@@ -31298,9 +31298,9 @@ var require_parser = __commonJS({
|
|
|
31298
31298
|
this.$ = { strip: yy.stripFlags($$[$0 - 1], $$[$0 - 1]), program: $$[$0] };
|
|
31299
31299
|
break;
|
|
31300
31300
|
case 19:
|
|
31301
|
-
var inverse = yy.prepareBlock($$[$0 - 2], $$[$0 - 1], $$[$0], $$[$0], false, this._$),
|
|
31302
|
-
|
|
31303
|
-
this.$ = { strip: $$[$0 - 2].strip, program, chain: true };
|
|
31301
|
+
var inverse = yy.prepareBlock($$[$0 - 2], $$[$0 - 1], $$[$0], $$[$0], false, this._$), program2 = yy.prepareProgram([inverse], $$[$0 - 1].loc);
|
|
31302
|
+
program2.chained = true;
|
|
31303
|
+
this.$ = { strip: $$[$0 - 2].strip, program: program2, chain: true };
|
|
31304
31304
|
break;
|
|
31305
31305
|
case 20:
|
|
31306
31306
|
this.$ = $$[$0];
|
|
@@ -31992,8 +31992,8 @@ var require_visitor = __commonJS({
|
|
|
31992
31992
|
return object2;
|
|
31993
31993
|
}
|
|
31994
31994
|
},
|
|
31995
|
-
Program: function Program(
|
|
31996
|
-
this.acceptArray(
|
|
31995
|
+
Program: function Program(program2) {
|
|
31996
|
+
this.acceptArray(program2.body);
|
|
31997
31997
|
},
|
|
31998
31998
|
MustacheStatement: visitSubExpression,
|
|
31999
31999
|
Decorator: visitSubExpression,
|
|
@@ -32063,11 +32063,11 @@ var require_whitespace_control = __commonJS({
|
|
|
32063
32063
|
this.options = options;
|
|
32064
32064
|
}
|
|
32065
32065
|
WhitespaceControl.prototype = new _visitor2["default"]();
|
|
32066
|
-
WhitespaceControl.prototype.Program = function(
|
|
32066
|
+
WhitespaceControl.prototype.Program = function(program2) {
|
|
32067
32067
|
var doStandalone = !this.options.ignoreStandalone;
|
|
32068
32068
|
var isRoot2 = !this.isRootSeen;
|
|
32069
32069
|
this.isRootSeen = true;
|
|
32070
|
-
var body =
|
|
32070
|
+
var body = program2.body;
|
|
32071
32071
|
for (var i = 0, l = body.length; i < l; i++) {
|
|
32072
32072
|
var current = body[i], strip3 = this.accept(current);
|
|
32073
32073
|
if (!strip3) {
|
|
@@ -32097,12 +32097,12 @@ var require_whitespace_control = __commonJS({
|
|
|
32097
32097
|
omitLeft((current.inverse || current.program).body);
|
|
32098
32098
|
}
|
|
32099
32099
|
}
|
|
32100
|
-
return
|
|
32100
|
+
return program2;
|
|
32101
32101
|
};
|
|
32102
32102
|
WhitespaceControl.prototype.BlockStatement = WhitespaceControl.prototype.DecoratorBlock = WhitespaceControl.prototype.PartialBlockStatement = function(block) {
|
|
32103
32103
|
this.accept(block.program);
|
|
32104
32104
|
this.accept(block.inverse);
|
|
32105
|
-
var
|
|
32105
|
+
var program2 = block.program || block.inverse, inverse = block.program && block.inverse, firstInverse = inverse, lastInverse = inverse;
|
|
32106
32106
|
if (inverse && inverse.chained) {
|
|
32107
32107
|
firstInverse = inverse.body[0].program;
|
|
32108
32108
|
while (lastInverse.chained) {
|
|
@@ -32114,16 +32114,16 @@ var require_whitespace_control = __commonJS({
|
|
|
32114
32114
|
close: block.closeStrip.close,
|
|
32115
32115
|
// Determine the standalone candiacy. Basically flag our content as being possibly standalone
|
|
32116
32116
|
// so our parent can determine if we actually are standalone
|
|
32117
|
-
openStandalone: isNextWhitespace(
|
|
32118
|
-
closeStandalone: isPrevWhitespace((firstInverse ||
|
|
32117
|
+
openStandalone: isNextWhitespace(program2.body),
|
|
32118
|
+
closeStandalone: isPrevWhitespace((firstInverse || program2).body)
|
|
32119
32119
|
};
|
|
32120
32120
|
if (block.openStrip.close) {
|
|
32121
|
-
omitRight(
|
|
32121
|
+
omitRight(program2.body, null, true);
|
|
32122
32122
|
}
|
|
32123
32123
|
if (inverse) {
|
|
32124
32124
|
var inverseStrip = block.inverseStrip;
|
|
32125
32125
|
if (inverseStrip.open) {
|
|
32126
|
-
omitLeft(
|
|
32126
|
+
omitLeft(program2.body, null, true);
|
|
32127
32127
|
}
|
|
32128
32128
|
if (inverseStrip.close) {
|
|
32129
32129
|
omitRight(firstInverse.body, null, true);
|
|
@@ -32131,12 +32131,12 @@ var require_whitespace_control = __commonJS({
|
|
|
32131
32131
|
if (block.closeStrip.open) {
|
|
32132
32132
|
omitLeft(lastInverse.body, null, true);
|
|
32133
32133
|
}
|
|
32134
|
-
if (!this.options.ignoreStandalone && isPrevWhitespace(
|
|
32135
|
-
omitLeft(
|
|
32134
|
+
if (!this.options.ignoreStandalone && isPrevWhitespace(program2.body) && isNextWhitespace(firstInverse.body)) {
|
|
32135
|
+
omitLeft(program2.body);
|
|
32136
32136
|
omitRight(firstInverse.body);
|
|
32137
32137
|
}
|
|
32138
32138
|
} else if (block.closeStrip.open) {
|
|
32139
|
-
omitLeft(
|
|
32139
|
+
omitLeft(program2.body, null, true);
|
|
32140
32140
|
}
|
|
32141
32141
|
return strip3;
|
|
32142
32142
|
};
|
|
@@ -32294,7 +32294,7 @@ var require_helpers2 = __commonJS({
|
|
|
32294
32294
|
function prepareRawBlock(openRawBlock, contents, close, locInfo) {
|
|
32295
32295
|
validateClose(openRawBlock, close);
|
|
32296
32296
|
locInfo = this.locInfo(locInfo);
|
|
32297
|
-
var
|
|
32297
|
+
var program2 = {
|
|
32298
32298
|
type: "Program",
|
|
32299
32299
|
body: contents,
|
|
32300
32300
|
strip: {},
|
|
@@ -32305,19 +32305,19 @@ var require_helpers2 = __commonJS({
|
|
|
32305
32305
|
path: openRawBlock.path,
|
|
32306
32306
|
params: openRawBlock.params,
|
|
32307
32307
|
hash: openRawBlock.hash,
|
|
32308
|
-
program,
|
|
32308
|
+
program: program2,
|
|
32309
32309
|
openStrip: {},
|
|
32310
32310
|
inverseStrip: {},
|
|
32311
32311
|
closeStrip: {},
|
|
32312
32312
|
loc: locInfo
|
|
32313
32313
|
};
|
|
32314
32314
|
}
|
|
32315
|
-
function prepareBlock(openBlock,
|
|
32315
|
+
function prepareBlock(openBlock, program2, inverseAndProgram, close, inverted, locInfo) {
|
|
32316
32316
|
if (close && close.path) {
|
|
32317
32317
|
validateClose(openBlock, close);
|
|
32318
32318
|
}
|
|
32319
32319
|
var decorator = /\*/.test(openBlock.open);
|
|
32320
|
-
|
|
32320
|
+
program2.blockParams = openBlock.blockParams;
|
|
32321
32321
|
var inverse = void 0, inverseStrip = void 0;
|
|
32322
32322
|
if (inverseAndProgram) {
|
|
32323
32323
|
if (decorator) {
|
|
@@ -32331,15 +32331,15 @@ var require_helpers2 = __commonJS({
|
|
|
32331
32331
|
}
|
|
32332
32332
|
if (inverted) {
|
|
32333
32333
|
inverted = inverse;
|
|
32334
|
-
inverse =
|
|
32335
|
-
|
|
32334
|
+
inverse = program2;
|
|
32335
|
+
program2 = inverted;
|
|
32336
32336
|
}
|
|
32337
32337
|
return {
|
|
32338
32338
|
type: decorator ? "DecoratorBlock" : "BlockStatement",
|
|
32339
32339
|
path: openBlock.path,
|
|
32340
32340
|
params: openBlock.params,
|
|
32341
32341
|
hash: openBlock.hash,
|
|
32342
|
-
program,
|
|
32342
|
+
program: program2,
|
|
32343
32343
|
inverse,
|
|
32344
32344
|
openStrip: openBlock.strip,
|
|
32345
32345
|
inverseStrip,
|
|
@@ -32371,14 +32371,14 @@ var require_helpers2 = __commonJS({
|
|
|
32371
32371
|
loc
|
|
32372
32372
|
};
|
|
32373
32373
|
}
|
|
32374
|
-
function preparePartialBlock(open,
|
|
32374
|
+
function preparePartialBlock(open, program2, close, locInfo) {
|
|
32375
32375
|
validateClose(open, close);
|
|
32376
32376
|
return {
|
|
32377
32377
|
type: "PartialBlockStatement",
|
|
32378
32378
|
name: open.path,
|
|
32379
32379
|
params: open.params,
|
|
32380
32380
|
hash: open.hash,
|
|
32381
|
-
program,
|
|
32381
|
+
program: program2,
|
|
32382
32382
|
openStrip: open.strip,
|
|
32383
32383
|
closeStrip: close && close.strip,
|
|
32384
32384
|
loc: this.locInfo(locInfo)
|
|
@@ -32529,7 +32529,7 @@ var require_compiler = __commonJS({
|
|
|
32529
32529
|
return true;
|
|
32530
32530
|
},
|
|
32531
32531
|
guid: 0,
|
|
32532
|
-
compile: function compile3(
|
|
32532
|
+
compile: function compile3(program2, options) {
|
|
32533
32533
|
this.sourceNode = [];
|
|
32534
32534
|
this.opcodes = [];
|
|
32535
32535
|
this.children = [];
|
|
@@ -32547,10 +32547,10 @@ var require_compiler = __commonJS({
|
|
|
32547
32547
|
log: true,
|
|
32548
32548
|
lookup: true
|
|
32549
32549
|
}, options.knownHelpers);
|
|
32550
|
-
return this.accept(
|
|
32550
|
+
return this.accept(program2);
|
|
32551
32551
|
},
|
|
32552
|
-
compileProgram: function compileProgram(
|
|
32553
|
-
var childCompiler = new this.compiler(), result = childCompiler.compile(
|
|
32552
|
+
compileProgram: function compileProgram(program2) {
|
|
32553
|
+
var childCompiler = new this.compiler(), result = childCompiler.compile(program2, this.options), guid3 = this.guid++;
|
|
32554
32554
|
this.usePartial = this.usePartial || result.usePartial;
|
|
32555
32555
|
this.children[guid3] = result;
|
|
32556
32556
|
this.useDepths = this.useDepths || result.useDepths;
|
|
@@ -32565,34 +32565,34 @@ var require_compiler = __commonJS({
|
|
|
32565
32565
|
this.sourceNode.shift();
|
|
32566
32566
|
return ret;
|
|
32567
32567
|
},
|
|
32568
|
-
Program: function Program(
|
|
32569
|
-
this.options.blockParams.unshift(
|
|
32570
|
-
var body =
|
|
32568
|
+
Program: function Program(program2) {
|
|
32569
|
+
this.options.blockParams.unshift(program2.blockParams);
|
|
32570
|
+
var body = program2.body, bodyLength = body.length;
|
|
32571
32571
|
for (var i = 0; i < bodyLength; i++) {
|
|
32572
32572
|
this.accept(body[i]);
|
|
32573
32573
|
}
|
|
32574
32574
|
this.options.blockParams.shift();
|
|
32575
32575
|
this.isSimple = bodyLength === 1;
|
|
32576
|
-
this.blockParams =
|
|
32576
|
+
this.blockParams = program2.blockParams ? program2.blockParams.length : 0;
|
|
32577
32577
|
return this;
|
|
32578
32578
|
},
|
|
32579
32579
|
BlockStatement: function BlockStatement(block) {
|
|
32580
32580
|
transformLiteralToPath(block);
|
|
32581
|
-
var
|
|
32582
|
-
|
|
32581
|
+
var program2 = block.program, inverse = block.inverse;
|
|
32582
|
+
program2 = program2 && this.compileProgram(program2);
|
|
32583
32583
|
inverse = inverse && this.compileProgram(inverse);
|
|
32584
32584
|
var type2 = this.classifySexpr(block);
|
|
32585
32585
|
if (type2 === "helper") {
|
|
32586
|
-
this.helperSexpr(block,
|
|
32586
|
+
this.helperSexpr(block, program2, inverse);
|
|
32587
32587
|
} else if (type2 === "simple") {
|
|
32588
32588
|
this.simpleSexpr(block);
|
|
32589
|
-
this.opcode("pushProgram",
|
|
32589
|
+
this.opcode("pushProgram", program2);
|
|
32590
32590
|
this.opcode("pushProgram", inverse);
|
|
32591
32591
|
this.opcode("emptyHash");
|
|
32592
32592
|
this.opcode("blockValue", block.path.original);
|
|
32593
32593
|
} else {
|
|
32594
|
-
this.ambiguousSexpr(block,
|
|
32595
|
-
this.opcode("pushProgram",
|
|
32594
|
+
this.ambiguousSexpr(block, program2, inverse);
|
|
32595
|
+
this.opcode("pushProgram", program2);
|
|
32596
32596
|
this.opcode("pushProgram", inverse);
|
|
32597
32597
|
this.opcode("emptyHash");
|
|
32598
32598
|
this.opcode("ambiguousBlockValue");
|
|
@@ -32600,16 +32600,16 @@ var require_compiler = __commonJS({
|
|
|
32600
32600
|
this.opcode("append");
|
|
32601
32601
|
},
|
|
32602
32602
|
DecoratorBlock: function DecoratorBlock(decorator) {
|
|
32603
|
-
var
|
|
32604
|
-
var params = this.setupFullMustacheParams(decorator,
|
|
32603
|
+
var program2 = decorator.program && this.compileProgram(decorator.program);
|
|
32604
|
+
var params = this.setupFullMustacheParams(decorator, program2, void 0), path19 = decorator.path;
|
|
32605
32605
|
this.useDecorators = true;
|
|
32606
32606
|
this.opcode("registerDecorator", params.length, path19.original);
|
|
32607
32607
|
},
|
|
32608
32608
|
PartialStatement: function PartialStatement(partial2) {
|
|
32609
32609
|
this.usePartial = true;
|
|
32610
|
-
var
|
|
32611
|
-
if (
|
|
32612
|
-
|
|
32610
|
+
var program2 = partial2.program;
|
|
32611
|
+
if (program2) {
|
|
32612
|
+
program2 = this.compileProgram(partial2.program);
|
|
32613
32613
|
}
|
|
32614
32614
|
var params = partial2.params;
|
|
32615
32615
|
if (params.length > 1) {
|
|
@@ -32625,7 +32625,7 @@ var require_compiler = __commonJS({
|
|
|
32625
32625
|
if (isDynamic) {
|
|
32626
32626
|
this.accept(partial2.name);
|
|
32627
32627
|
}
|
|
32628
|
-
this.setupFullMustacheParams(partial2,
|
|
32628
|
+
this.setupFullMustacheParams(partial2, program2, void 0, true);
|
|
32629
32629
|
var indent = partial2.indent || "";
|
|
32630
32630
|
if (this.options.preventIndent && indent) {
|
|
32631
32631
|
this.opcode("appendContent", indent);
|
|
@@ -32666,10 +32666,10 @@ var require_compiler = __commonJS({
|
|
|
32666
32666
|
this.ambiguousSexpr(sexpr);
|
|
32667
32667
|
}
|
|
32668
32668
|
},
|
|
32669
|
-
ambiguousSexpr: function ambiguousSexpr(sexpr,
|
|
32670
|
-
var path19 = sexpr.path, name = path19.parts[0], isBlock =
|
|
32669
|
+
ambiguousSexpr: function ambiguousSexpr(sexpr, program2, inverse) {
|
|
32670
|
+
var path19 = sexpr.path, name = path19.parts[0], isBlock = program2 != null || inverse != null;
|
|
32671
32671
|
this.opcode("getContext", path19.depth);
|
|
32672
|
-
this.opcode("pushProgram",
|
|
32672
|
+
this.opcode("pushProgram", program2);
|
|
32673
32673
|
this.opcode("pushProgram", inverse);
|
|
32674
32674
|
path19.strict = true;
|
|
32675
32675
|
this.accept(path19);
|
|
@@ -32681,8 +32681,8 @@ var require_compiler = __commonJS({
|
|
|
32681
32681
|
this.accept(path19);
|
|
32682
32682
|
this.opcode("resolvePossibleLambda");
|
|
32683
32683
|
},
|
|
32684
|
-
helperSexpr: function helperSexpr(sexpr,
|
|
32685
|
-
var params = this.setupFullMustacheParams(sexpr,
|
|
32684
|
+
helperSexpr: function helperSexpr(sexpr, program2, inverse) {
|
|
32685
|
+
var params = this.setupFullMustacheParams(sexpr, program2, inverse), path19 = sexpr.path, name = path19.parts[0];
|
|
32686
32686
|
if (this.options.knownHelpers[name]) {
|
|
32687
32687
|
this.opcode("invokeKnownHelper", params.length, name);
|
|
32688
32688
|
} else if (this.options.knownHelpersOnly) {
|
|
@@ -32809,10 +32809,10 @@ var require_compiler = __commonJS({
|
|
|
32809
32809
|
this.accept(val);
|
|
32810
32810
|
}
|
|
32811
32811
|
},
|
|
32812
|
-
setupFullMustacheParams: function setupFullMustacheParams(sexpr,
|
|
32812
|
+
setupFullMustacheParams: function setupFullMustacheParams(sexpr, program2, inverse, omitEmpty) {
|
|
32813
32813
|
var params = sexpr.params;
|
|
32814
32814
|
this.pushParams(params);
|
|
32815
|
-
this.opcode("pushProgram",
|
|
32815
|
+
this.opcode("pushProgram", program2);
|
|
32816
32816
|
this.opcode("pushProgram", inverse);
|
|
32817
32817
|
if (sexpr.hash) {
|
|
32818
32818
|
this.accept(sexpr.hash);
|
|
@@ -35642,9 +35642,9 @@ var require_javascript_compiler = __commonJS({
|
|
|
35642
35642
|
options.hashTypes = this.popStack();
|
|
35643
35643
|
options.hashContexts = this.popStack();
|
|
35644
35644
|
}
|
|
35645
|
-
var inverse = this.popStack(),
|
|
35646
|
-
if (
|
|
35647
|
-
options.fn =
|
|
35645
|
+
var inverse = this.popStack(), program2 = this.popStack();
|
|
35646
|
+
if (program2 || inverse) {
|
|
35647
|
+
options.fn = program2 || "container.noop";
|
|
35648
35648
|
options.inverse = inverse || "container.noop";
|
|
35649
35649
|
}
|
|
35650
35650
|
var i = paramSize;
|
|
@@ -35796,12 +35796,12 @@ var require_printer = __commonJS({
|
|
|
35796
35796
|
out += string4 + "\n";
|
|
35797
35797
|
return out;
|
|
35798
35798
|
};
|
|
35799
|
-
PrintVisitor.prototype.Program = function(
|
|
35800
|
-
var out = "", body =
|
|
35801
|
-
if (
|
|
35799
|
+
PrintVisitor.prototype.Program = function(program2) {
|
|
35800
|
+
var out = "", body = program2.body, i = void 0, l = void 0;
|
|
35801
|
+
if (program2.blockParams) {
|
|
35802
35802
|
var blockParams = "BLOCK PARAMS: [";
|
|
35803
|
-
for (i = 0, l =
|
|
35804
|
-
blockParams += " " +
|
|
35803
|
+
for (i = 0, l = program2.blockParams.length; i < l; i++) {
|
|
35804
|
+
blockParams += " " + program2.blockParams[i];
|
|
35805
35805
|
}
|
|
35806
35806
|
blockParams += " ]";
|
|
35807
35807
|
out += this.pad(blockParams);
|
|
@@ -40559,6 +40559,3464 @@ var init_liquid_node = __esm({
|
|
|
40559
40559
|
}
|
|
40560
40560
|
});
|
|
40561
40561
|
|
|
40562
|
+
// ../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/error.js
|
|
40563
|
+
var require_error = __commonJS({
|
|
40564
|
+
"../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/error.js"(exports2) {
|
|
40565
|
+
"use strict";
|
|
40566
|
+
var CommanderError2 = class extends Error {
|
|
40567
|
+
/**
|
|
40568
|
+
* Constructs the CommanderError class
|
|
40569
|
+
* @param {number} exitCode suggested exit code which could be used with process.exit
|
|
40570
|
+
* @param {string} code an id string representing the error
|
|
40571
|
+
* @param {string} message human-readable description of the error
|
|
40572
|
+
*/
|
|
40573
|
+
constructor(exitCode3, code, message) {
|
|
40574
|
+
super(message);
|
|
40575
|
+
Error.captureStackTrace(this, this.constructor);
|
|
40576
|
+
this.name = this.constructor.name;
|
|
40577
|
+
this.code = code;
|
|
40578
|
+
this.exitCode = exitCode3;
|
|
40579
|
+
this.nestedError = void 0;
|
|
40580
|
+
}
|
|
40581
|
+
};
|
|
40582
|
+
var InvalidArgumentError2 = class extends CommanderError2 {
|
|
40583
|
+
/**
|
|
40584
|
+
* Constructs the InvalidArgumentError class
|
|
40585
|
+
* @param {string} [message] explanation of why argument is invalid
|
|
40586
|
+
*/
|
|
40587
|
+
constructor(message) {
|
|
40588
|
+
super(1, "commander.invalidArgument", message);
|
|
40589
|
+
Error.captureStackTrace(this, this.constructor);
|
|
40590
|
+
this.name = this.constructor.name;
|
|
40591
|
+
}
|
|
40592
|
+
};
|
|
40593
|
+
exports2.CommanderError = CommanderError2;
|
|
40594
|
+
exports2.InvalidArgumentError = InvalidArgumentError2;
|
|
40595
|
+
}
|
|
40596
|
+
});
|
|
40597
|
+
|
|
40598
|
+
// ../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/argument.js
|
|
40599
|
+
var require_argument = __commonJS({
|
|
40600
|
+
"../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/argument.js"(exports2) {
|
|
40601
|
+
"use strict";
|
|
40602
|
+
var { InvalidArgumentError: InvalidArgumentError2 } = require_error();
|
|
40603
|
+
var Argument2 = class {
|
|
40604
|
+
/**
|
|
40605
|
+
* Initialize a new command argument with the given name and description.
|
|
40606
|
+
* The default is that the argument is required, and you can explicitly
|
|
40607
|
+
* indicate this with <> around the name. Put [] around the name for an optional argument.
|
|
40608
|
+
*
|
|
40609
|
+
* @param {string} name
|
|
40610
|
+
* @param {string} [description]
|
|
40611
|
+
*/
|
|
40612
|
+
constructor(name, description) {
|
|
40613
|
+
this.description = description || "";
|
|
40614
|
+
this.variadic = false;
|
|
40615
|
+
this.parseArg = void 0;
|
|
40616
|
+
this.defaultValue = void 0;
|
|
40617
|
+
this.defaultValueDescription = void 0;
|
|
40618
|
+
this.argChoices = void 0;
|
|
40619
|
+
switch (name[0]) {
|
|
40620
|
+
case "<":
|
|
40621
|
+
this.required = true;
|
|
40622
|
+
this._name = name.slice(1, -1);
|
|
40623
|
+
break;
|
|
40624
|
+
case "[":
|
|
40625
|
+
this.required = false;
|
|
40626
|
+
this._name = name.slice(1, -1);
|
|
40627
|
+
break;
|
|
40628
|
+
default:
|
|
40629
|
+
this.required = true;
|
|
40630
|
+
this._name = name;
|
|
40631
|
+
break;
|
|
40632
|
+
}
|
|
40633
|
+
if (this._name.endsWith("...")) {
|
|
40634
|
+
this.variadic = true;
|
|
40635
|
+
this._name = this._name.slice(0, -3);
|
|
40636
|
+
}
|
|
40637
|
+
}
|
|
40638
|
+
/**
|
|
40639
|
+
* Return argument name.
|
|
40640
|
+
*
|
|
40641
|
+
* @return {string}
|
|
40642
|
+
*/
|
|
40643
|
+
name() {
|
|
40644
|
+
return this._name;
|
|
40645
|
+
}
|
|
40646
|
+
/**
|
|
40647
|
+
* @package
|
|
40648
|
+
*/
|
|
40649
|
+
_collectValue(value, previous) {
|
|
40650
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
40651
|
+
return [value];
|
|
40652
|
+
}
|
|
40653
|
+
previous.push(value);
|
|
40654
|
+
return previous;
|
|
40655
|
+
}
|
|
40656
|
+
/**
|
|
40657
|
+
* Set the default value, and optionally supply the description to be displayed in the help.
|
|
40658
|
+
*
|
|
40659
|
+
* @param {*} value
|
|
40660
|
+
* @param {string} [description]
|
|
40661
|
+
* @return {Argument}
|
|
40662
|
+
*/
|
|
40663
|
+
default(value, description) {
|
|
40664
|
+
this.defaultValue = value;
|
|
40665
|
+
this.defaultValueDescription = description;
|
|
40666
|
+
return this;
|
|
40667
|
+
}
|
|
40668
|
+
/**
|
|
40669
|
+
* Set the custom handler for processing CLI command arguments into argument values.
|
|
40670
|
+
*
|
|
40671
|
+
* @param {Function} [fn]
|
|
40672
|
+
* @return {Argument}
|
|
40673
|
+
*/
|
|
40674
|
+
argParser(fn) {
|
|
40675
|
+
this.parseArg = fn;
|
|
40676
|
+
return this;
|
|
40677
|
+
}
|
|
40678
|
+
/**
|
|
40679
|
+
* Only allow argument value to be one of choices.
|
|
40680
|
+
*
|
|
40681
|
+
* @param {string[]} values
|
|
40682
|
+
* @return {Argument}
|
|
40683
|
+
*/
|
|
40684
|
+
choices(values) {
|
|
40685
|
+
this.argChoices = values.slice();
|
|
40686
|
+
this.parseArg = (arg, previous) => {
|
|
40687
|
+
if (!this.argChoices.includes(arg)) {
|
|
40688
|
+
throw new InvalidArgumentError2(
|
|
40689
|
+
`Allowed choices are ${this.argChoices.join(", ")}.`
|
|
40690
|
+
);
|
|
40691
|
+
}
|
|
40692
|
+
if (this.variadic) {
|
|
40693
|
+
return this._collectValue(arg, previous);
|
|
40694
|
+
}
|
|
40695
|
+
return arg;
|
|
40696
|
+
};
|
|
40697
|
+
return this;
|
|
40698
|
+
}
|
|
40699
|
+
/**
|
|
40700
|
+
* Make argument required.
|
|
40701
|
+
*
|
|
40702
|
+
* @returns {Argument}
|
|
40703
|
+
*/
|
|
40704
|
+
argRequired() {
|
|
40705
|
+
this.required = true;
|
|
40706
|
+
return this;
|
|
40707
|
+
}
|
|
40708
|
+
/**
|
|
40709
|
+
* Make argument optional.
|
|
40710
|
+
*
|
|
40711
|
+
* @returns {Argument}
|
|
40712
|
+
*/
|
|
40713
|
+
argOptional() {
|
|
40714
|
+
this.required = false;
|
|
40715
|
+
return this;
|
|
40716
|
+
}
|
|
40717
|
+
};
|
|
40718
|
+
function humanReadableArgName(arg) {
|
|
40719
|
+
const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
|
|
40720
|
+
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
|
|
40721
|
+
}
|
|
40722
|
+
exports2.Argument = Argument2;
|
|
40723
|
+
exports2.humanReadableArgName = humanReadableArgName;
|
|
40724
|
+
}
|
|
40725
|
+
});
|
|
40726
|
+
|
|
40727
|
+
// ../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/help.js
|
|
40728
|
+
var require_help = __commonJS({
|
|
40729
|
+
"../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/help.js"(exports2) {
|
|
40730
|
+
"use strict";
|
|
40731
|
+
var { humanReadableArgName } = require_argument();
|
|
40732
|
+
var Help2 = class {
|
|
40733
|
+
constructor() {
|
|
40734
|
+
this.helpWidth = void 0;
|
|
40735
|
+
this.minWidthToWrap = 40;
|
|
40736
|
+
this.sortSubcommands = false;
|
|
40737
|
+
this.sortOptions = false;
|
|
40738
|
+
this.showGlobalOptions = false;
|
|
40739
|
+
}
|
|
40740
|
+
/**
|
|
40741
|
+
* prepareContext is called by Commander after applying overrides from `Command.configureHelp()`
|
|
40742
|
+
* and just before calling `formatHelp()`.
|
|
40743
|
+
*
|
|
40744
|
+
* Commander just uses the helpWidth and the rest is provided for optional use by more complex subclasses.
|
|
40745
|
+
*
|
|
40746
|
+
* @param {{ error?: boolean, helpWidth?: number, outputHasColors?: boolean }} contextOptions
|
|
40747
|
+
*/
|
|
40748
|
+
prepareContext(contextOptions) {
|
|
40749
|
+
this.helpWidth = this.helpWidth ?? contextOptions.helpWidth ?? 80;
|
|
40750
|
+
}
|
|
40751
|
+
/**
|
|
40752
|
+
* Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one.
|
|
40753
|
+
*
|
|
40754
|
+
* @param {Command} cmd
|
|
40755
|
+
* @returns {Command[]}
|
|
40756
|
+
*/
|
|
40757
|
+
visibleCommands(cmd) {
|
|
40758
|
+
const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
|
|
40759
|
+
const helpCommand = cmd._getHelpCommand();
|
|
40760
|
+
if (helpCommand && !helpCommand._hidden) {
|
|
40761
|
+
visibleCommands.push(helpCommand);
|
|
40762
|
+
}
|
|
40763
|
+
if (this.sortSubcommands) {
|
|
40764
|
+
visibleCommands.sort((a, b) => {
|
|
40765
|
+
return a.name().localeCompare(b.name());
|
|
40766
|
+
});
|
|
40767
|
+
}
|
|
40768
|
+
return visibleCommands;
|
|
40769
|
+
}
|
|
40770
|
+
/**
|
|
40771
|
+
* Compare options for sort.
|
|
40772
|
+
*
|
|
40773
|
+
* @param {Option} a
|
|
40774
|
+
* @param {Option} b
|
|
40775
|
+
* @returns {number}
|
|
40776
|
+
*/
|
|
40777
|
+
compareOptions(a, b) {
|
|
40778
|
+
const getSortKey = (option) => {
|
|
40779
|
+
return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
|
|
40780
|
+
};
|
|
40781
|
+
return getSortKey(a).localeCompare(getSortKey(b));
|
|
40782
|
+
}
|
|
40783
|
+
/**
|
|
40784
|
+
* Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one.
|
|
40785
|
+
*
|
|
40786
|
+
* @param {Command} cmd
|
|
40787
|
+
* @returns {Option[]}
|
|
40788
|
+
*/
|
|
40789
|
+
visibleOptions(cmd) {
|
|
40790
|
+
const visibleOptions = cmd.options.filter((option) => !option.hidden);
|
|
40791
|
+
const helpOption = cmd._getHelpOption();
|
|
40792
|
+
if (helpOption && !helpOption.hidden) {
|
|
40793
|
+
const removeShort = helpOption.short && cmd._findOption(helpOption.short);
|
|
40794
|
+
const removeLong = helpOption.long && cmd._findOption(helpOption.long);
|
|
40795
|
+
if (!removeShort && !removeLong) {
|
|
40796
|
+
visibleOptions.push(helpOption);
|
|
40797
|
+
} else if (helpOption.long && !removeLong) {
|
|
40798
|
+
visibleOptions.push(
|
|
40799
|
+
cmd.createOption(helpOption.long, helpOption.description)
|
|
40800
|
+
);
|
|
40801
|
+
} else if (helpOption.short && !removeShort) {
|
|
40802
|
+
visibleOptions.push(
|
|
40803
|
+
cmd.createOption(helpOption.short, helpOption.description)
|
|
40804
|
+
);
|
|
40805
|
+
}
|
|
40806
|
+
}
|
|
40807
|
+
if (this.sortOptions) {
|
|
40808
|
+
visibleOptions.sort(this.compareOptions);
|
|
40809
|
+
}
|
|
40810
|
+
return visibleOptions;
|
|
40811
|
+
}
|
|
40812
|
+
/**
|
|
40813
|
+
* Get an array of the visible global options. (Not including help.)
|
|
40814
|
+
*
|
|
40815
|
+
* @param {Command} cmd
|
|
40816
|
+
* @returns {Option[]}
|
|
40817
|
+
*/
|
|
40818
|
+
visibleGlobalOptions(cmd) {
|
|
40819
|
+
if (!this.showGlobalOptions) return [];
|
|
40820
|
+
const globalOptions = [];
|
|
40821
|
+
for (let ancestorCmd = cmd.parent; ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
40822
|
+
const visibleOptions = ancestorCmd.options.filter(
|
|
40823
|
+
(option) => !option.hidden
|
|
40824
|
+
);
|
|
40825
|
+
globalOptions.push(...visibleOptions);
|
|
40826
|
+
}
|
|
40827
|
+
if (this.sortOptions) {
|
|
40828
|
+
globalOptions.sort(this.compareOptions);
|
|
40829
|
+
}
|
|
40830
|
+
return globalOptions;
|
|
40831
|
+
}
|
|
40832
|
+
/**
|
|
40833
|
+
* Get an array of the arguments if any have a description.
|
|
40834
|
+
*
|
|
40835
|
+
* @param {Command} cmd
|
|
40836
|
+
* @returns {Argument[]}
|
|
40837
|
+
*/
|
|
40838
|
+
visibleArguments(cmd) {
|
|
40839
|
+
if (cmd._argsDescription) {
|
|
40840
|
+
cmd.registeredArguments.forEach((argument) => {
|
|
40841
|
+
argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
|
|
40842
|
+
});
|
|
40843
|
+
}
|
|
40844
|
+
if (cmd.registeredArguments.find((argument) => argument.description)) {
|
|
40845
|
+
return cmd.registeredArguments;
|
|
40846
|
+
}
|
|
40847
|
+
return [];
|
|
40848
|
+
}
|
|
40849
|
+
/**
|
|
40850
|
+
* Get the command term to show in the list of subcommands.
|
|
40851
|
+
*
|
|
40852
|
+
* @param {Command} cmd
|
|
40853
|
+
* @returns {string}
|
|
40854
|
+
*/
|
|
40855
|
+
subcommandTerm(cmd) {
|
|
40856
|
+
const args = cmd.registeredArguments.map((arg) => humanReadableArgName(arg)).join(" ");
|
|
40857
|
+
return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + // simplistic check for non-help option
|
|
40858
|
+
(args ? " " + args : "");
|
|
40859
|
+
}
|
|
40860
|
+
/**
|
|
40861
|
+
* Get the option term to show in the list of options.
|
|
40862
|
+
*
|
|
40863
|
+
* @param {Option} option
|
|
40864
|
+
* @returns {string}
|
|
40865
|
+
*/
|
|
40866
|
+
optionTerm(option) {
|
|
40867
|
+
return option.flags;
|
|
40868
|
+
}
|
|
40869
|
+
/**
|
|
40870
|
+
* Get the argument term to show in the list of arguments.
|
|
40871
|
+
*
|
|
40872
|
+
* @param {Argument} argument
|
|
40873
|
+
* @returns {string}
|
|
40874
|
+
*/
|
|
40875
|
+
argumentTerm(argument) {
|
|
40876
|
+
return argument.name();
|
|
40877
|
+
}
|
|
40878
|
+
/**
|
|
40879
|
+
* Get the longest command term length.
|
|
40880
|
+
*
|
|
40881
|
+
* @param {Command} cmd
|
|
40882
|
+
* @param {Help} helper
|
|
40883
|
+
* @returns {number}
|
|
40884
|
+
*/
|
|
40885
|
+
longestSubcommandTermLength(cmd, helper) {
|
|
40886
|
+
return helper.visibleCommands(cmd).reduce((max, command) => {
|
|
40887
|
+
return Math.max(
|
|
40888
|
+
max,
|
|
40889
|
+
this.displayWidth(
|
|
40890
|
+
helper.styleSubcommandTerm(helper.subcommandTerm(command))
|
|
40891
|
+
)
|
|
40892
|
+
);
|
|
40893
|
+
}, 0);
|
|
40894
|
+
}
|
|
40895
|
+
/**
|
|
40896
|
+
* Get the longest option term length.
|
|
40897
|
+
*
|
|
40898
|
+
* @param {Command} cmd
|
|
40899
|
+
* @param {Help} helper
|
|
40900
|
+
* @returns {number}
|
|
40901
|
+
*/
|
|
40902
|
+
longestOptionTermLength(cmd, helper) {
|
|
40903
|
+
return helper.visibleOptions(cmd).reduce((max, option) => {
|
|
40904
|
+
return Math.max(
|
|
40905
|
+
max,
|
|
40906
|
+
this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option)))
|
|
40907
|
+
);
|
|
40908
|
+
}, 0);
|
|
40909
|
+
}
|
|
40910
|
+
/**
|
|
40911
|
+
* Get the longest global option term length.
|
|
40912
|
+
*
|
|
40913
|
+
* @param {Command} cmd
|
|
40914
|
+
* @param {Help} helper
|
|
40915
|
+
* @returns {number}
|
|
40916
|
+
*/
|
|
40917
|
+
longestGlobalOptionTermLength(cmd, helper) {
|
|
40918
|
+
return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
|
|
40919
|
+
return Math.max(
|
|
40920
|
+
max,
|
|
40921
|
+
this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option)))
|
|
40922
|
+
);
|
|
40923
|
+
}, 0);
|
|
40924
|
+
}
|
|
40925
|
+
/**
|
|
40926
|
+
* Get the longest argument term length.
|
|
40927
|
+
*
|
|
40928
|
+
* @param {Command} cmd
|
|
40929
|
+
* @param {Help} helper
|
|
40930
|
+
* @returns {number}
|
|
40931
|
+
*/
|
|
40932
|
+
longestArgumentTermLength(cmd, helper) {
|
|
40933
|
+
return helper.visibleArguments(cmd).reduce((max, argument) => {
|
|
40934
|
+
return Math.max(
|
|
40935
|
+
max,
|
|
40936
|
+
this.displayWidth(
|
|
40937
|
+
helper.styleArgumentTerm(helper.argumentTerm(argument))
|
|
40938
|
+
)
|
|
40939
|
+
);
|
|
40940
|
+
}, 0);
|
|
40941
|
+
}
|
|
40942
|
+
/**
|
|
40943
|
+
* Get the command usage to be displayed at the top of the built-in help.
|
|
40944
|
+
*
|
|
40945
|
+
* @param {Command} cmd
|
|
40946
|
+
* @returns {string}
|
|
40947
|
+
*/
|
|
40948
|
+
commandUsage(cmd) {
|
|
40949
|
+
let cmdName = cmd._name;
|
|
40950
|
+
if (cmd._aliases[0]) {
|
|
40951
|
+
cmdName = cmdName + "|" + cmd._aliases[0];
|
|
40952
|
+
}
|
|
40953
|
+
let ancestorCmdNames = "";
|
|
40954
|
+
for (let ancestorCmd = cmd.parent; ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
40955
|
+
ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
|
|
40956
|
+
}
|
|
40957
|
+
return ancestorCmdNames + cmdName + " " + cmd.usage();
|
|
40958
|
+
}
|
|
40959
|
+
/**
|
|
40960
|
+
* Get the description for the command.
|
|
40961
|
+
*
|
|
40962
|
+
* @param {Command} cmd
|
|
40963
|
+
* @returns {string}
|
|
40964
|
+
*/
|
|
40965
|
+
commandDescription(cmd) {
|
|
40966
|
+
return cmd.description();
|
|
40967
|
+
}
|
|
40968
|
+
/**
|
|
40969
|
+
* Get the subcommand summary to show in the list of subcommands.
|
|
40970
|
+
* (Fallback to description for backwards compatibility.)
|
|
40971
|
+
*
|
|
40972
|
+
* @param {Command} cmd
|
|
40973
|
+
* @returns {string}
|
|
40974
|
+
*/
|
|
40975
|
+
subcommandDescription(cmd) {
|
|
40976
|
+
return cmd.summary() || cmd.description();
|
|
40977
|
+
}
|
|
40978
|
+
/**
|
|
40979
|
+
* Get the option description to show in the list of options.
|
|
40980
|
+
*
|
|
40981
|
+
* @param {Option} option
|
|
40982
|
+
* @return {string}
|
|
40983
|
+
*/
|
|
40984
|
+
optionDescription(option) {
|
|
40985
|
+
const extraInfo = [];
|
|
40986
|
+
if (option.argChoices) {
|
|
40987
|
+
extraInfo.push(
|
|
40988
|
+
// use stringify to match the display of the default value
|
|
40989
|
+
`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`
|
|
40990
|
+
);
|
|
40991
|
+
}
|
|
40992
|
+
if (option.defaultValue !== void 0) {
|
|
40993
|
+
const showDefault = option.required || option.optional || option.isBoolean() && typeof option.defaultValue === "boolean";
|
|
40994
|
+
if (showDefault) {
|
|
40995
|
+
extraInfo.push(
|
|
40996
|
+
`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`
|
|
40997
|
+
);
|
|
40998
|
+
}
|
|
40999
|
+
}
|
|
41000
|
+
if (option.presetArg !== void 0 && option.optional) {
|
|
41001
|
+
extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
|
|
41002
|
+
}
|
|
41003
|
+
if (option.envVar !== void 0) {
|
|
41004
|
+
extraInfo.push(`env: ${option.envVar}`);
|
|
41005
|
+
}
|
|
41006
|
+
if (extraInfo.length > 0) {
|
|
41007
|
+
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
41008
|
+
if (option.description) {
|
|
41009
|
+
return `${option.description} ${extraDescription}`;
|
|
41010
|
+
}
|
|
41011
|
+
return extraDescription;
|
|
41012
|
+
}
|
|
41013
|
+
return option.description;
|
|
41014
|
+
}
|
|
41015
|
+
/**
|
|
41016
|
+
* Get the argument description to show in the list of arguments.
|
|
41017
|
+
*
|
|
41018
|
+
* @param {Argument} argument
|
|
41019
|
+
* @return {string}
|
|
41020
|
+
*/
|
|
41021
|
+
argumentDescription(argument) {
|
|
41022
|
+
const extraInfo = [];
|
|
41023
|
+
if (argument.argChoices) {
|
|
41024
|
+
extraInfo.push(
|
|
41025
|
+
// use stringify to match the display of the default value
|
|
41026
|
+
`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`
|
|
41027
|
+
);
|
|
41028
|
+
}
|
|
41029
|
+
if (argument.defaultValue !== void 0) {
|
|
41030
|
+
extraInfo.push(
|
|
41031
|
+
`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`
|
|
41032
|
+
);
|
|
41033
|
+
}
|
|
41034
|
+
if (extraInfo.length > 0) {
|
|
41035
|
+
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
41036
|
+
if (argument.description) {
|
|
41037
|
+
return `${argument.description} ${extraDescription}`;
|
|
41038
|
+
}
|
|
41039
|
+
return extraDescription;
|
|
41040
|
+
}
|
|
41041
|
+
return argument.description;
|
|
41042
|
+
}
|
|
41043
|
+
/**
|
|
41044
|
+
* Format a list of items, given a heading and an array of formatted items.
|
|
41045
|
+
*
|
|
41046
|
+
* @param {string} heading
|
|
41047
|
+
* @param {string[]} items
|
|
41048
|
+
* @param {Help} helper
|
|
41049
|
+
* @returns string[]
|
|
41050
|
+
*/
|
|
41051
|
+
formatItemList(heading, items, helper) {
|
|
41052
|
+
if (items.length === 0) return [];
|
|
41053
|
+
return [helper.styleTitle(heading), ...items, ""];
|
|
41054
|
+
}
|
|
41055
|
+
/**
|
|
41056
|
+
* Group items by their help group heading.
|
|
41057
|
+
*
|
|
41058
|
+
* @param {Command[] | Option[]} unsortedItems
|
|
41059
|
+
* @param {Command[] | Option[]} visibleItems
|
|
41060
|
+
* @param {Function} getGroup
|
|
41061
|
+
* @returns {Map<string, Command[] | Option[]>}
|
|
41062
|
+
*/
|
|
41063
|
+
groupItems(unsortedItems, visibleItems, getGroup) {
|
|
41064
|
+
const result = /* @__PURE__ */ new Map();
|
|
41065
|
+
unsortedItems.forEach((item) => {
|
|
41066
|
+
const group = getGroup(item);
|
|
41067
|
+
if (!result.has(group)) result.set(group, []);
|
|
41068
|
+
});
|
|
41069
|
+
visibleItems.forEach((item) => {
|
|
41070
|
+
const group = getGroup(item);
|
|
41071
|
+
if (!result.has(group)) {
|
|
41072
|
+
result.set(group, []);
|
|
41073
|
+
}
|
|
41074
|
+
result.get(group).push(item);
|
|
41075
|
+
});
|
|
41076
|
+
return result;
|
|
41077
|
+
}
|
|
41078
|
+
/**
|
|
41079
|
+
* Generate the built-in help text.
|
|
41080
|
+
*
|
|
41081
|
+
* @param {Command} cmd
|
|
41082
|
+
* @param {Help} helper
|
|
41083
|
+
* @returns {string}
|
|
41084
|
+
*/
|
|
41085
|
+
formatHelp(cmd, helper) {
|
|
41086
|
+
const termWidth = helper.padWidth(cmd, helper);
|
|
41087
|
+
const helpWidth = helper.helpWidth ?? 80;
|
|
41088
|
+
function callFormatItem(term, description) {
|
|
41089
|
+
return helper.formatItem(term, termWidth, description, helper);
|
|
41090
|
+
}
|
|
41091
|
+
let output3 = [
|
|
41092
|
+
`${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`,
|
|
41093
|
+
""
|
|
41094
|
+
];
|
|
41095
|
+
const commandDescription = helper.commandDescription(cmd);
|
|
41096
|
+
if (commandDescription.length > 0) {
|
|
41097
|
+
output3 = output3.concat([
|
|
41098
|
+
helper.boxWrap(
|
|
41099
|
+
helper.styleCommandDescription(commandDescription),
|
|
41100
|
+
helpWidth
|
|
41101
|
+
),
|
|
41102
|
+
""
|
|
41103
|
+
]);
|
|
41104
|
+
}
|
|
41105
|
+
const argumentList = helper.visibleArguments(cmd).map((argument) => {
|
|
41106
|
+
return callFormatItem(
|
|
41107
|
+
helper.styleArgumentTerm(helper.argumentTerm(argument)),
|
|
41108
|
+
helper.styleArgumentDescription(helper.argumentDescription(argument))
|
|
41109
|
+
);
|
|
41110
|
+
});
|
|
41111
|
+
output3 = output3.concat(
|
|
41112
|
+
this.formatItemList("Arguments:", argumentList, helper)
|
|
41113
|
+
);
|
|
41114
|
+
const optionGroups = this.groupItems(
|
|
41115
|
+
cmd.options,
|
|
41116
|
+
helper.visibleOptions(cmd),
|
|
41117
|
+
(option) => option.helpGroupHeading ?? "Options:"
|
|
41118
|
+
);
|
|
41119
|
+
optionGroups.forEach((options, group) => {
|
|
41120
|
+
const optionList = options.map((option) => {
|
|
41121
|
+
return callFormatItem(
|
|
41122
|
+
helper.styleOptionTerm(helper.optionTerm(option)),
|
|
41123
|
+
helper.styleOptionDescription(helper.optionDescription(option))
|
|
41124
|
+
);
|
|
41125
|
+
});
|
|
41126
|
+
output3 = output3.concat(this.formatItemList(group, optionList, helper));
|
|
41127
|
+
});
|
|
41128
|
+
if (helper.showGlobalOptions) {
|
|
41129
|
+
const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
|
|
41130
|
+
return callFormatItem(
|
|
41131
|
+
helper.styleOptionTerm(helper.optionTerm(option)),
|
|
41132
|
+
helper.styleOptionDescription(helper.optionDescription(option))
|
|
41133
|
+
);
|
|
41134
|
+
});
|
|
41135
|
+
output3 = output3.concat(
|
|
41136
|
+
this.formatItemList("Global Options:", globalOptionList, helper)
|
|
41137
|
+
);
|
|
41138
|
+
}
|
|
41139
|
+
const commandGroups = this.groupItems(
|
|
41140
|
+
cmd.commands,
|
|
41141
|
+
helper.visibleCommands(cmd),
|
|
41142
|
+
(sub) => sub.helpGroup() || "Commands:"
|
|
41143
|
+
);
|
|
41144
|
+
commandGroups.forEach((commands, group) => {
|
|
41145
|
+
const commandList = commands.map((sub) => {
|
|
41146
|
+
return callFormatItem(
|
|
41147
|
+
helper.styleSubcommandTerm(helper.subcommandTerm(sub)),
|
|
41148
|
+
helper.styleSubcommandDescription(helper.subcommandDescription(sub))
|
|
41149
|
+
);
|
|
41150
|
+
});
|
|
41151
|
+
output3 = output3.concat(this.formatItemList(group, commandList, helper));
|
|
41152
|
+
});
|
|
41153
|
+
return output3.join("\n");
|
|
41154
|
+
}
|
|
41155
|
+
/**
|
|
41156
|
+
* Return display width of string, ignoring ANSI escape sequences. Used in padding and wrapping calculations.
|
|
41157
|
+
*
|
|
41158
|
+
* @param {string} str
|
|
41159
|
+
* @returns {number}
|
|
41160
|
+
*/
|
|
41161
|
+
displayWidth(str3) {
|
|
41162
|
+
return stripColor(str3).length;
|
|
41163
|
+
}
|
|
41164
|
+
/**
|
|
41165
|
+
* Style the title for displaying in the help. Called with 'Usage:', 'Options:', etc.
|
|
41166
|
+
*
|
|
41167
|
+
* @param {string} str
|
|
41168
|
+
* @returns {string}
|
|
41169
|
+
*/
|
|
41170
|
+
styleTitle(str3) {
|
|
41171
|
+
return str3;
|
|
41172
|
+
}
|
|
41173
|
+
styleUsage(str3) {
|
|
41174
|
+
return str3.split(" ").map((word) => {
|
|
41175
|
+
if (word === "[options]") return this.styleOptionText(word);
|
|
41176
|
+
if (word === "[command]") return this.styleSubcommandText(word);
|
|
41177
|
+
if (word[0] === "[" || word[0] === "<")
|
|
41178
|
+
return this.styleArgumentText(word);
|
|
41179
|
+
return this.styleCommandText(word);
|
|
41180
|
+
}).join(" ");
|
|
41181
|
+
}
|
|
41182
|
+
styleCommandDescription(str3) {
|
|
41183
|
+
return this.styleDescriptionText(str3);
|
|
41184
|
+
}
|
|
41185
|
+
styleOptionDescription(str3) {
|
|
41186
|
+
return this.styleDescriptionText(str3);
|
|
41187
|
+
}
|
|
41188
|
+
styleSubcommandDescription(str3) {
|
|
41189
|
+
return this.styleDescriptionText(str3);
|
|
41190
|
+
}
|
|
41191
|
+
styleArgumentDescription(str3) {
|
|
41192
|
+
return this.styleDescriptionText(str3);
|
|
41193
|
+
}
|
|
41194
|
+
styleDescriptionText(str3) {
|
|
41195
|
+
return str3;
|
|
41196
|
+
}
|
|
41197
|
+
styleOptionTerm(str3) {
|
|
41198
|
+
return this.styleOptionText(str3);
|
|
41199
|
+
}
|
|
41200
|
+
styleSubcommandTerm(str3) {
|
|
41201
|
+
return str3.split(" ").map((word) => {
|
|
41202
|
+
if (word === "[options]") return this.styleOptionText(word);
|
|
41203
|
+
if (word[0] === "[" || word[0] === "<")
|
|
41204
|
+
return this.styleArgumentText(word);
|
|
41205
|
+
return this.styleSubcommandText(word);
|
|
41206
|
+
}).join(" ");
|
|
41207
|
+
}
|
|
41208
|
+
styleArgumentTerm(str3) {
|
|
41209
|
+
return this.styleArgumentText(str3);
|
|
41210
|
+
}
|
|
41211
|
+
styleOptionText(str3) {
|
|
41212
|
+
return str3;
|
|
41213
|
+
}
|
|
41214
|
+
styleArgumentText(str3) {
|
|
41215
|
+
return str3;
|
|
41216
|
+
}
|
|
41217
|
+
styleSubcommandText(str3) {
|
|
41218
|
+
return str3;
|
|
41219
|
+
}
|
|
41220
|
+
styleCommandText(str3) {
|
|
41221
|
+
return str3;
|
|
41222
|
+
}
|
|
41223
|
+
/**
|
|
41224
|
+
* Calculate the pad width from the maximum term length.
|
|
41225
|
+
*
|
|
41226
|
+
* @param {Command} cmd
|
|
41227
|
+
* @param {Help} helper
|
|
41228
|
+
* @returns {number}
|
|
41229
|
+
*/
|
|
41230
|
+
padWidth(cmd, helper) {
|
|
41231
|
+
return Math.max(
|
|
41232
|
+
helper.longestOptionTermLength(cmd, helper),
|
|
41233
|
+
helper.longestGlobalOptionTermLength(cmd, helper),
|
|
41234
|
+
helper.longestSubcommandTermLength(cmd, helper),
|
|
41235
|
+
helper.longestArgumentTermLength(cmd, helper)
|
|
41236
|
+
);
|
|
41237
|
+
}
|
|
41238
|
+
/**
|
|
41239
|
+
* Detect manually wrapped and indented strings by checking for line break followed by whitespace.
|
|
41240
|
+
*
|
|
41241
|
+
* @param {string} str
|
|
41242
|
+
* @returns {boolean}
|
|
41243
|
+
*/
|
|
41244
|
+
preformatted(str3) {
|
|
41245
|
+
return /\n[^\S\r\n]/.test(str3);
|
|
41246
|
+
}
|
|
41247
|
+
/**
|
|
41248
|
+
* Format the "item", which consists of a term and description. Pad the term and wrap the description, indenting the following lines.
|
|
41249
|
+
*
|
|
41250
|
+
* So "TTT", 5, "DDD DDDD DD DDD" might be formatted for this.helpWidth=17 like so:
|
|
41251
|
+
* TTT DDD DDDD
|
|
41252
|
+
* DD DDD
|
|
41253
|
+
*
|
|
41254
|
+
* @param {string} term
|
|
41255
|
+
* @param {number} termWidth
|
|
41256
|
+
* @param {string} description
|
|
41257
|
+
* @param {Help} helper
|
|
41258
|
+
* @returns {string}
|
|
41259
|
+
*/
|
|
41260
|
+
formatItem(term, termWidth, description, helper) {
|
|
41261
|
+
const itemIndent = 2;
|
|
41262
|
+
const itemIndentStr = " ".repeat(itemIndent);
|
|
41263
|
+
if (!description) return itemIndentStr + term;
|
|
41264
|
+
const paddedTerm = term.padEnd(
|
|
41265
|
+
termWidth + term.length - helper.displayWidth(term)
|
|
41266
|
+
);
|
|
41267
|
+
const spacerWidth = 2;
|
|
41268
|
+
const helpWidth = this.helpWidth ?? 80;
|
|
41269
|
+
const remainingWidth = helpWidth - termWidth - spacerWidth - itemIndent;
|
|
41270
|
+
let formattedDescription;
|
|
41271
|
+
if (remainingWidth < this.minWidthToWrap || helper.preformatted(description)) {
|
|
41272
|
+
formattedDescription = description;
|
|
41273
|
+
} else {
|
|
41274
|
+
const wrappedDescription = helper.boxWrap(description, remainingWidth);
|
|
41275
|
+
formattedDescription = wrappedDescription.replace(
|
|
41276
|
+
/\n/g,
|
|
41277
|
+
"\n" + " ".repeat(termWidth + spacerWidth)
|
|
41278
|
+
);
|
|
41279
|
+
}
|
|
41280
|
+
return itemIndentStr + paddedTerm + " ".repeat(spacerWidth) + formattedDescription.replace(/\n/g, `
|
|
41281
|
+
${itemIndentStr}`);
|
|
41282
|
+
}
|
|
41283
|
+
/**
|
|
41284
|
+
* Wrap a string at whitespace, preserving existing line breaks.
|
|
41285
|
+
* Wrapping is skipped if the width is less than `minWidthToWrap`.
|
|
41286
|
+
*
|
|
41287
|
+
* @param {string} str
|
|
41288
|
+
* @param {number} width
|
|
41289
|
+
* @returns {string}
|
|
41290
|
+
*/
|
|
41291
|
+
boxWrap(str3, width) {
|
|
41292
|
+
if (width < this.minWidthToWrap) return str3;
|
|
41293
|
+
const rawLines = str3.split(/\r\n|\n/);
|
|
41294
|
+
const chunkPattern = /[\s]*[^\s]+/g;
|
|
41295
|
+
const wrappedLines = [];
|
|
41296
|
+
rawLines.forEach((line) => {
|
|
41297
|
+
const chunks = line.match(chunkPattern);
|
|
41298
|
+
if (chunks === null) {
|
|
41299
|
+
wrappedLines.push("");
|
|
41300
|
+
return;
|
|
41301
|
+
}
|
|
41302
|
+
let sumChunks = [chunks.shift()];
|
|
41303
|
+
let sumWidth = this.displayWidth(sumChunks[0]);
|
|
41304
|
+
chunks.forEach((chunk) => {
|
|
41305
|
+
const visibleWidth = this.displayWidth(chunk);
|
|
41306
|
+
if (sumWidth + visibleWidth <= width) {
|
|
41307
|
+
sumChunks.push(chunk);
|
|
41308
|
+
sumWidth += visibleWidth;
|
|
41309
|
+
return;
|
|
41310
|
+
}
|
|
41311
|
+
wrappedLines.push(sumChunks.join(""));
|
|
41312
|
+
const nextChunk = chunk.trimStart();
|
|
41313
|
+
sumChunks = [nextChunk];
|
|
41314
|
+
sumWidth = this.displayWidth(nextChunk);
|
|
41315
|
+
});
|
|
41316
|
+
wrappedLines.push(sumChunks.join(""));
|
|
41317
|
+
});
|
|
41318
|
+
return wrappedLines.join("\n");
|
|
41319
|
+
}
|
|
41320
|
+
};
|
|
41321
|
+
function stripColor(str3) {
|
|
41322
|
+
const sgrPattern = /\x1b\[\d*(;\d*)*m/g;
|
|
41323
|
+
return str3.replace(sgrPattern, "");
|
|
41324
|
+
}
|
|
41325
|
+
exports2.Help = Help2;
|
|
41326
|
+
exports2.stripColor = stripColor;
|
|
41327
|
+
}
|
|
41328
|
+
});
|
|
41329
|
+
|
|
41330
|
+
// ../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/option.js
|
|
41331
|
+
var require_option = __commonJS({
|
|
41332
|
+
"../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/option.js"(exports2) {
|
|
41333
|
+
"use strict";
|
|
41334
|
+
var { InvalidArgumentError: InvalidArgumentError2 } = require_error();
|
|
41335
|
+
var Option2 = class {
|
|
41336
|
+
/**
|
|
41337
|
+
* Initialize a new `Option` with the given `flags` and `description`.
|
|
41338
|
+
*
|
|
41339
|
+
* @param {string} flags
|
|
41340
|
+
* @param {string} [description]
|
|
41341
|
+
*/
|
|
41342
|
+
constructor(flags, description) {
|
|
41343
|
+
this.flags = flags;
|
|
41344
|
+
this.description = description || "";
|
|
41345
|
+
this.required = flags.includes("<");
|
|
41346
|
+
this.optional = flags.includes("[");
|
|
41347
|
+
this.variadic = /\w\.\.\.[>\]]$/.test(flags);
|
|
41348
|
+
this.mandatory = false;
|
|
41349
|
+
const optionFlags = splitOptionFlags(flags);
|
|
41350
|
+
this.short = optionFlags.shortFlag;
|
|
41351
|
+
this.long = optionFlags.longFlag;
|
|
41352
|
+
this.negate = false;
|
|
41353
|
+
if (this.long) {
|
|
41354
|
+
this.negate = this.long.startsWith("--no-");
|
|
41355
|
+
}
|
|
41356
|
+
this.defaultValue = void 0;
|
|
41357
|
+
this.defaultValueDescription = void 0;
|
|
41358
|
+
this.presetArg = void 0;
|
|
41359
|
+
this.envVar = void 0;
|
|
41360
|
+
this.parseArg = void 0;
|
|
41361
|
+
this.hidden = false;
|
|
41362
|
+
this.argChoices = void 0;
|
|
41363
|
+
this.conflictsWith = [];
|
|
41364
|
+
this.implied = void 0;
|
|
41365
|
+
this.helpGroupHeading = void 0;
|
|
41366
|
+
}
|
|
41367
|
+
/**
|
|
41368
|
+
* Set the default value, and optionally supply the description to be displayed in the help.
|
|
41369
|
+
*
|
|
41370
|
+
* @param {*} value
|
|
41371
|
+
* @param {string} [description]
|
|
41372
|
+
* @return {Option}
|
|
41373
|
+
*/
|
|
41374
|
+
default(value, description) {
|
|
41375
|
+
this.defaultValue = value;
|
|
41376
|
+
this.defaultValueDescription = description;
|
|
41377
|
+
return this;
|
|
41378
|
+
}
|
|
41379
|
+
/**
|
|
41380
|
+
* Preset to use when option used without option-argument, especially optional but also boolean and negated.
|
|
41381
|
+
* The custom processing (parseArg) is called.
|
|
41382
|
+
*
|
|
41383
|
+
* @example
|
|
41384
|
+
* new Option('--color').default('GREYSCALE').preset('RGB');
|
|
41385
|
+
* new Option('--donate [amount]').preset('20').argParser(parseFloat);
|
|
41386
|
+
*
|
|
41387
|
+
* @param {*} arg
|
|
41388
|
+
* @return {Option}
|
|
41389
|
+
*/
|
|
41390
|
+
preset(arg) {
|
|
41391
|
+
this.presetArg = arg;
|
|
41392
|
+
return this;
|
|
41393
|
+
}
|
|
41394
|
+
/**
|
|
41395
|
+
* Add option name(s) that conflict with this option.
|
|
41396
|
+
* An error will be displayed if conflicting options are found during parsing.
|
|
41397
|
+
*
|
|
41398
|
+
* @example
|
|
41399
|
+
* new Option('--rgb').conflicts('cmyk');
|
|
41400
|
+
* new Option('--js').conflicts(['ts', 'jsx']);
|
|
41401
|
+
*
|
|
41402
|
+
* @param {(string | string[])} names
|
|
41403
|
+
* @return {Option}
|
|
41404
|
+
*/
|
|
41405
|
+
conflicts(names) {
|
|
41406
|
+
this.conflictsWith = this.conflictsWith.concat(names);
|
|
41407
|
+
return this;
|
|
41408
|
+
}
|
|
41409
|
+
/**
|
|
41410
|
+
* Specify implied option values for when this option is set and the implied options are not.
|
|
41411
|
+
*
|
|
41412
|
+
* The custom processing (parseArg) is not called on the implied values.
|
|
41413
|
+
*
|
|
41414
|
+
* @example
|
|
41415
|
+
* program
|
|
41416
|
+
* .addOption(new Option('--log', 'write logging information to file'))
|
|
41417
|
+
* .addOption(new Option('--trace', 'log extra details').implies({ log: 'trace.txt' }));
|
|
41418
|
+
*
|
|
41419
|
+
* @param {object} impliedOptionValues
|
|
41420
|
+
* @return {Option}
|
|
41421
|
+
*/
|
|
41422
|
+
implies(impliedOptionValues) {
|
|
41423
|
+
let newImplied = impliedOptionValues;
|
|
41424
|
+
if (typeof impliedOptionValues === "string") {
|
|
41425
|
+
newImplied = { [impliedOptionValues]: true };
|
|
41426
|
+
}
|
|
41427
|
+
this.implied = Object.assign(this.implied || {}, newImplied);
|
|
41428
|
+
return this;
|
|
41429
|
+
}
|
|
41430
|
+
/**
|
|
41431
|
+
* Set environment variable to check for option value.
|
|
41432
|
+
*
|
|
41433
|
+
* An environment variable is only used if when processed the current option value is
|
|
41434
|
+
* undefined, or the source of the current value is 'default' or 'config' or 'env'.
|
|
41435
|
+
*
|
|
41436
|
+
* @param {string} name
|
|
41437
|
+
* @return {Option}
|
|
41438
|
+
*/
|
|
41439
|
+
env(name) {
|
|
41440
|
+
this.envVar = name;
|
|
41441
|
+
return this;
|
|
41442
|
+
}
|
|
41443
|
+
/**
|
|
41444
|
+
* Set the custom handler for processing CLI option arguments into option values.
|
|
41445
|
+
*
|
|
41446
|
+
* @param {Function} [fn]
|
|
41447
|
+
* @return {Option}
|
|
41448
|
+
*/
|
|
41449
|
+
argParser(fn) {
|
|
41450
|
+
this.parseArg = fn;
|
|
41451
|
+
return this;
|
|
41452
|
+
}
|
|
41453
|
+
/**
|
|
41454
|
+
* Whether the option is mandatory and must have a value after parsing.
|
|
41455
|
+
*
|
|
41456
|
+
* @param {boolean} [mandatory=true]
|
|
41457
|
+
* @return {Option}
|
|
41458
|
+
*/
|
|
41459
|
+
makeOptionMandatory(mandatory = true) {
|
|
41460
|
+
this.mandatory = !!mandatory;
|
|
41461
|
+
return this;
|
|
41462
|
+
}
|
|
41463
|
+
/**
|
|
41464
|
+
* Hide option in help.
|
|
41465
|
+
*
|
|
41466
|
+
* @param {boolean} [hide=true]
|
|
41467
|
+
* @return {Option}
|
|
41468
|
+
*/
|
|
41469
|
+
hideHelp(hide = true) {
|
|
41470
|
+
this.hidden = !!hide;
|
|
41471
|
+
return this;
|
|
41472
|
+
}
|
|
41473
|
+
/**
|
|
41474
|
+
* @package
|
|
41475
|
+
*/
|
|
41476
|
+
_collectValue(value, previous) {
|
|
41477
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
41478
|
+
return [value];
|
|
41479
|
+
}
|
|
41480
|
+
previous.push(value);
|
|
41481
|
+
return previous;
|
|
41482
|
+
}
|
|
41483
|
+
/**
|
|
41484
|
+
* Only allow option value to be one of choices.
|
|
41485
|
+
*
|
|
41486
|
+
* @param {string[]} values
|
|
41487
|
+
* @return {Option}
|
|
41488
|
+
*/
|
|
41489
|
+
choices(values) {
|
|
41490
|
+
this.argChoices = values.slice();
|
|
41491
|
+
this.parseArg = (arg, previous) => {
|
|
41492
|
+
if (!this.argChoices.includes(arg)) {
|
|
41493
|
+
throw new InvalidArgumentError2(
|
|
41494
|
+
`Allowed choices are ${this.argChoices.join(", ")}.`
|
|
41495
|
+
);
|
|
41496
|
+
}
|
|
41497
|
+
if (this.variadic) {
|
|
41498
|
+
return this._collectValue(arg, previous);
|
|
41499
|
+
}
|
|
41500
|
+
return arg;
|
|
41501
|
+
};
|
|
41502
|
+
return this;
|
|
41503
|
+
}
|
|
41504
|
+
/**
|
|
41505
|
+
* Return option name.
|
|
41506
|
+
*
|
|
41507
|
+
* @return {string}
|
|
41508
|
+
*/
|
|
41509
|
+
name() {
|
|
41510
|
+
if (this.long) {
|
|
41511
|
+
return this.long.replace(/^--/, "");
|
|
41512
|
+
}
|
|
41513
|
+
return this.short.replace(/^-/, "");
|
|
41514
|
+
}
|
|
41515
|
+
/**
|
|
41516
|
+
* Return option name, in a camelcase format that can be used
|
|
41517
|
+
* as an object attribute key.
|
|
41518
|
+
*
|
|
41519
|
+
* @return {string}
|
|
41520
|
+
*/
|
|
41521
|
+
attributeName() {
|
|
41522
|
+
if (this.negate) {
|
|
41523
|
+
return camelcase(this.name().replace(/^no-/, ""));
|
|
41524
|
+
}
|
|
41525
|
+
return camelcase(this.name());
|
|
41526
|
+
}
|
|
41527
|
+
/**
|
|
41528
|
+
* Set the help group heading.
|
|
41529
|
+
*
|
|
41530
|
+
* @param {string} heading
|
|
41531
|
+
* @return {Option}
|
|
41532
|
+
*/
|
|
41533
|
+
helpGroup(heading) {
|
|
41534
|
+
this.helpGroupHeading = heading;
|
|
41535
|
+
return this;
|
|
41536
|
+
}
|
|
41537
|
+
/**
|
|
41538
|
+
* Check if `arg` matches the short or long flag.
|
|
41539
|
+
*
|
|
41540
|
+
* @param {string} arg
|
|
41541
|
+
* @return {boolean}
|
|
41542
|
+
* @package
|
|
41543
|
+
*/
|
|
41544
|
+
is(arg) {
|
|
41545
|
+
return this.short === arg || this.long === arg;
|
|
41546
|
+
}
|
|
41547
|
+
/**
|
|
41548
|
+
* Return whether a boolean option.
|
|
41549
|
+
*
|
|
41550
|
+
* Options are one of boolean, negated, required argument, or optional argument.
|
|
41551
|
+
*
|
|
41552
|
+
* @return {boolean}
|
|
41553
|
+
* @package
|
|
41554
|
+
*/
|
|
41555
|
+
isBoolean() {
|
|
41556
|
+
return !this.required && !this.optional && !this.negate;
|
|
41557
|
+
}
|
|
41558
|
+
};
|
|
41559
|
+
var DualOptions = class {
|
|
41560
|
+
/**
|
|
41561
|
+
* @param {Option[]} options
|
|
41562
|
+
*/
|
|
41563
|
+
constructor(options) {
|
|
41564
|
+
this.positiveOptions = /* @__PURE__ */ new Map();
|
|
41565
|
+
this.negativeOptions = /* @__PURE__ */ new Map();
|
|
41566
|
+
this.dualOptions = /* @__PURE__ */ new Set();
|
|
41567
|
+
options.forEach((option) => {
|
|
41568
|
+
if (option.negate) {
|
|
41569
|
+
this.negativeOptions.set(option.attributeName(), option);
|
|
41570
|
+
} else {
|
|
41571
|
+
this.positiveOptions.set(option.attributeName(), option);
|
|
41572
|
+
}
|
|
41573
|
+
});
|
|
41574
|
+
this.negativeOptions.forEach((value, key) => {
|
|
41575
|
+
if (this.positiveOptions.has(key)) {
|
|
41576
|
+
this.dualOptions.add(key);
|
|
41577
|
+
}
|
|
41578
|
+
});
|
|
41579
|
+
}
|
|
41580
|
+
/**
|
|
41581
|
+
* Did the value come from the option, and not from possible matching dual option?
|
|
41582
|
+
*
|
|
41583
|
+
* @param {*} value
|
|
41584
|
+
* @param {Option} option
|
|
41585
|
+
* @returns {boolean}
|
|
41586
|
+
*/
|
|
41587
|
+
valueFromOption(value, option) {
|
|
41588
|
+
const optionKey = option.attributeName();
|
|
41589
|
+
if (!this.dualOptions.has(optionKey)) return true;
|
|
41590
|
+
const preset = this.negativeOptions.get(optionKey).presetArg;
|
|
41591
|
+
const negativeValue = preset !== void 0 ? preset : false;
|
|
41592
|
+
return option.negate === (negativeValue === value);
|
|
41593
|
+
}
|
|
41594
|
+
};
|
|
41595
|
+
function camelcase(str3) {
|
|
41596
|
+
return str3.split("-").reduce((str4, word) => {
|
|
41597
|
+
return str4 + word[0].toUpperCase() + word.slice(1);
|
|
41598
|
+
});
|
|
41599
|
+
}
|
|
41600
|
+
function splitOptionFlags(flags) {
|
|
41601
|
+
let shortFlag;
|
|
41602
|
+
let longFlag;
|
|
41603
|
+
const shortFlagExp = /^-[^-]$/;
|
|
41604
|
+
const longFlagExp = /^--[^-]/;
|
|
41605
|
+
const flagParts = flags.split(/[ |,]+/).concat("guard");
|
|
41606
|
+
if (shortFlagExp.test(flagParts[0])) shortFlag = flagParts.shift();
|
|
41607
|
+
if (longFlagExp.test(flagParts[0])) longFlag = flagParts.shift();
|
|
41608
|
+
if (!shortFlag && shortFlagExp.test(flagParts[0]))
|
|
41609
|
+
shortFlag = flagParts.shift();
|
|
41610
|
+
if (!shortFlag && longFlagExp.test(flagParts[0])) {
|
|
41611
|
+
shortFlag = longFlag;
|
|
41612
|
+
longFlag = flagParts.shift();
|
|
41613
|
+
}
|
|
41614
|
+
if (flagParts[0].startsWith("-")) {
|
|
41615
|
+
const unsupportedFlag = flagParts[0];
|
|
41616
|
+
const baseError = `option creation failed due to '${unsupportedFlag}' in option flags '${flags}'`;
|
|
41617
|
+
if (/^-[^-][^-]/.test(unsupportedFlag))
|
|
41618
|
+
throw new Error(
|
|
41619
|
+
`${baseError}
|
|
41620
|
+
- a short flag is a single dash and a single character
|
|
41621
|
+
- either use a single dash and a single character (for a short flag)
|
|
41622
|
+
- or use a double dash for a long option (and can have two, like '--ws, --workspace')`
|
|
41623
|
+
);
|
|
41624
|
+
if (shortFlagExp.test(unsupportedFlag))
|
|
41625
|
+
throw new Error(`${baseError}
|
|
41626
|
+
- too many short flags`);
|
|
41627
|
+
if (longFlagExp.test(unsupportedFlag))
|
|
41628
|
+
throw new Error(`${baseError}
|
|
41629
|
+
- too many long flags`);
|
|
41630
|
+
throw new Error(`${baseError}
|
|
41631
|
+
- unrecognised flag format`);
|
|
41632
|
+
}
|
|
41633
|
+
if (shortFlag === void 0 && longFlag === void 0)
|
|
41634
|
+
throw new Error(
|
|
41635
|
+
`option creation failed due to no flags found in '${flags}'.`
|
|
41636
|
+
);
|
|
41637
|
+
return { shortFlag, longFlag };
|
|
41638
|
+
}
|
|
41639
|
+
exports2.Option = Option2;
|
|
41640
|
+
exports2.DualOptions = DualOptions;
|
|
41641
|
+
}
|
|
41642
|
+
});
|
|
41643
|
+
|
|
41644
|
+
// ../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/suggestSimilar.js
|
|
41645
|
+
var require_suggestSimilar = __commonJS({
|
|
41646
|
+
"../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/suggestSimilar.js"(exports2) {
|
|
41647
|
+
"use strict";
|
|
41648
|
+
var maxDistance = 3;
|
|
41649
|
+
function editDistance(a, b) {
|
|
41650
|
+
if (Math.abs(a.length - b.length) > maxDistance)
|
|
41651
|
+
return Math.max(a.length, b.length);
|
|
41652
|
+
const d = [];
|
|
41653
|
+
for (let i = 0; i <= a.length; i++) {
|
|
41654
|
+
d[i] = [i];
|
|
41655
|
+
}
|
|
41656
|
+
for (let j = 0; j <= b.length; j++) {
|
|
41657
|
+
d[0][j] = j;
|
|
41658
|
+
}
|
|
41659
|
+
for (let j = 1; j <= b.length; j++) {
|
|
41660
|
+
for (let i = 1; i <= a.length; i++) {
|
|
41661
|
+
let cost = 1;
|
|
41662
|
+
if (a[i - 1] === b[j - 1]) {
|
|
41663
|
+
cost = 0;
|
|
41664
|
+
} else {
|
|
41665
|
+
cost = 1;
|
|
41666
|
+
}
|
|
41667
|
+
d[i][j] = Math.min(
|
|
41668
|
+
d[i - 1][j] + 1,
|
|
41669
|
+
// deletion
|
|
41670
|
+
d[i][j - 1] + 1,
|
|
41671
|
+
// insertion
|
|
41672
|
+
d[i - 1][j - 1] + cost
|
|
41673
|
+
// substitution
|
|
41674
|
+
);
|
|
41675
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
|
|
41676
|
+
d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
|
|
41677
|
+
}
|
|
41678
|
+
}
|
|
41679
|
+
}
|
|
41680
|
+
return d[a.length][b.length];
|
|
41681
|
+
}
|
|
41682
|
+
function suggestSimilar(word, candidates) {
|
|
41683
|
+
if (!candidates || candidates.length === 0) return "";
|
|
41684
|
+
candidates = Array.from(new Set(candidates));
|
|
41685
|
+
const searchingOptions = word.startsWith("--");
|
|
41686
|
+
if (searchingOptions) {
|
|
41687
|
+
word = word.slice(2);
|
|
41688
|
+
candidates = candidates.map((candidate) => candidate.slice(2));
|
|
41689
|
+
}
|
|
41690
|
+
let similar = [];
|
|
41691
|
+
let bestDistance = maxDistance;
|
|
41692
|
+
const minSimilarity = 0.4;
|
|
41693
|
+
candidates.forEach((candidate) => {
|
|
41694
|
+
if (candidate.length <= 1) return;
|
|
41695
|
+
const distance = editDistance(word, candidate);
|
|
41696
|
+
const length = Math.max(word.length, candidate.length);
|
|
41697
|
+
const similarity = (length - distance) / length;
|
|
41698
|
+
if (similarity > minSimilarity) {
|
|
41699
|
+
if (distance < bestDistance) {
|
|
41700
|
+
bestDistance = distance;
|
|
41701
|
+
similar = [candidate];
|
|
41702
|
+
} else if (distance === bestDistance) {
|
|
41703
|
+
similar.push(candidate);
|
|
41704
|
+
}
|
|
41705
|
+
}
|
|
41706
|
+
});
|
|
41707
|
+
similar.sort((a, b) => a.localeCompare(b));
|
|
41708
|
+
if (searchingOptions) {
|
|
41709
|
+
similar = similar.map((candidate) => `--${candidate}`);
|
|
41710
|
+
}
|
|
41711
|
+
if (similar.length > 1) {
|
|
41712
|
+
return `
|
|
41713
|
+
(Did you mean one of ${similar.join(", ")}?)`;
|
|
41714
|
+
}
|
|
41715
|
+
if (similar.length === 1) {
|
|
41716
|
+
return `
|
|
41717
|
+
(Did you mean ${similar[0]}?)`;
|
|
41718
|
+
}
|
|
41719
|
+
return "";
|
|
41720
|
+
}
|
|
41721
|
+
exports2.suggestSimilar = suggestSimilar;
|
|
41722
|
+
}
|
|
41723
|
+
});
|
|
41724
|
+
|
|
41725
|
+
// ../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/command.js
|
|
41726
|
+
var require_command = __commonJS({
|
|
41727
|
+
"../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/command.js"(exports2) {
|
|
41728
|
+
"use strict";
|
|
41729
|
+
var EventEmitter = __require("events").EventEmitter;
|
|
41730
|
+
var childProcess = __require("child_process");
|
|
41731
|
+
var path19 = __require("path");
|
|
41732
|
+
var fs19 = __require("fs");
|
|
41733
|
+
var process4 = __require("process");
|
|
41734
|
+
var { Argument: Argument2, humanReadableArgName } = require_argument();
|
|
41735
|
+
var { CommanderError: CommanderError2 } = require_error();
|
|
41736
|
+
var { Help: Help2, stripColor } = require_help();
|
|
41737
|
+
var { Option: Option2, DualOptions } = require_option();
|
|
41738
|
+
var { suggestSimilar } = require_suggestSimilar();
|
|
41739
|
+
var Command2 = class _Command extends EventEmitter {
|
|
41740
|
+
/**
|
|
41741
|
+
* Initialize a new `Command`.
|
|
41742
|
+
*
|
|
41743
|
+
* @param {string} [name]
|
|
41744
|
+
*/
|
|
41745
|
+
constructor(name) {
|
|
41746
|
+
super();
|
|
41747
|
+
this.commands = [];
|
|
41748
|
+
this.options = [];
|
|
41749
|
+
this.parent = null;
|
|
41750
|
+
this._allowUnknownOption = false;
|
|
41751
|
+
this._allowExcessArguments = false;
|
|
41752
|
+
this.registeredArguments = [];
|
|
41753
|
+
this._args = this.registeredArguments;
|
|
41754
|
+
this.args = [];
|
|
41755
|
+
this.rawArgs = [];
|
|
41756
|
+
this.processedArgs = [];
|
|
41757
|
+
this._scriptPath = null;
|
|
41758
|
+
this._name = name || "";
|
|
41759
|
+
this._optionValues = {};
|
|
41760
|
+
this._optionValueSources = {};
|
|
41761
|
+
this._storeOptionsAsProperties = false;
|
|
41762
|
+
this._actionHandler = null;
|
|
41763
|
+
this._executableHandler = false;
|
|
41764
|
+
this._executableFile = null;
|
|
41765
|
+
this._executableDir = null;
|
|
41766
|
+
this._defaultCommandName = null;
|
|
41767
|
+
this._exitCallback = null;
|
|
41768
|
+
this._aliases = [];
|
|
41769
|
+
this._combineFlagAndOptionalValue = true;
|
|
41770
|
+
this._description = "";
|
|
41771
|
+
this._summary = "";
|
|
41772
|
+
this._argsDescription = void 0;
|
|
41773
|
+
this._enablePositionalOptions = false;
|
|
41774
|
+
this._passThroughOptions = false;
|
|
41775
|
+
this._lifeCycleHooks = {};
|
|
41776
|
+
this._showHelpAfterError = false;
|
|
41777
|
+
this._showSuggestionAfterError = true;
|
|
41778
|
+
this._savedState = null;
|
|
41779
|
+
this._outputConfiguration = {
|
|
41780
|
+
writeOut: (str3) => process4.stdout.write(str3),
|
|
41781
|
+
writeErr: (str3) => process4.stderr.write(str3),
|
|
41782
|
+
outputError: (str3, write) => write(str3),
|
|
41783
|
+
getOutHelpWidth: () => process4.stdout.isTTY ? process4.stdout.columns : void 0,
|
|
41784
|
+
getErrHelpWidth: () => process4.stderr.isTTY ? process4.stderr.columns : void 0,
|
|
41785
|
+
getOutHasColors: () => useColor() ?? (process4.stdout.isTTY && process4.stdout.hasColors?.()),
|
|
41786
|
+
getErrHasColors: () => useColor() ?? (process4.stderr.isTTY && process4.stderr.hasColors?.()),
|
|
41787
|
+
stripColor: (str3) => stripColor(str3)
|
|
41788
|
+
};
|
|
41789
|
+
this._hidden = false;
|
|
41790
|
+
this._helpOption = void 0;
|
|
41791
|
+
this._addImplicitHelpCommand = void 0;
|
|
41792
|
+
this._helpCommand = void 0;
|
|
41793
|
+
this._helpConfiguration = {};
|
|
41794
|
+
this._helpGroupHeading = void 0;
|
|
41795
|
+
this._defaultCommandGroup = void 0;
|
|
41796
|
+
this._defaultOptionGroup = void 0;
|
|
41797
|
+
}
|
|
41798
|
+
/**
|
|
41799
|
+
* Copy settings that are useful to have in common across root command and subcommands.
|
|
41800
|
+
*
|
|
41801
|
+
* (Used internally when adding a command using `.command()` so subcommands inherit parent settings.)
|
|
41802
|
+
*
|
|
41803
|
+
* @param {Command} sourceCommand
|
|
41804
|
+
* @return {Command} `this` command for chaining
|
|
41805
|
+
*/
|
|
41806
|
+
copyInheritedSettings(sourceCommand) {
|
|
41807
|
+
this._outputConfiguration = sourceCommand._outputConfiguration;
|
|
41808
|
+
this._helpOption = sourceCommand._helpOption;
|
|
41809
|
+
this._helpCommand = sourceCommand._helpCommand;
|
|
41810
|
+
this._helpConfiguration = sourceCommand._helpConfiguration;
|
|
41811
|
+
this._exitCallback = sourceCommand._exitCallback;
|
|
41812
|
+
this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
|
|
41813
|
+
this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
|
|
41814
|
+
this._allowExcessArguments = sourceCommand._allowExcessArguments;
|
|
41815
|
+
this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
|
|
41816
|
+
this._showHelpAfterError = sourceCommand._showHelpAfterError;
|
|
41817
|
+
this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
|
|
41818
|
+
return this;
|
|
41819
|
+
}
|
|
41820
|
+
/**
|
|
41821
|
+
* @returns {Command[]}
|
|
41822
|
+
* @private
|
|
41823
|
+
*/
|
|
41824
|
+
_getCommandAndAncestors() {
|
|
41825
|
+
const result = [];
|
|
41826
|
+
for (let command = this; command; command = command.parent) {
|
|
41827
|
+
result.push(command);
|
|
41828
|
+
}
|
|
41829
|
+
return result;
|
|
41830
|
+
}
|
|
41831
|
+
/**
|
|
41832
|
+
* Define a command.
|
|
41833
|
+
*
|
|
41834
|
+
* There are two styles of command: pay attention to where to put the description.
|
|
41835
|
+
*
|
|
41836
|
+
* @example
|
|
41837
|
+
* // Command implemented using action handler (description is supplied separately to `.command`)
|
|
41838
|
+
* program
|
|
41839
|
+
* .command('clone <source> [destination]')
|
|
41840
|
+
* .description('clone a repository into a newly created directory')
|
|
41841
|
+
* .action((source, destination) => {
|
|
41842
|
+
* console.log('clone command called');
|
|
41843
|
+
* });
|
|
41844
|
+
*
|
|
41845
|
+
* // Command implemented using separate executable file (description is second parameter to `.command`)
|
|
41846
|
+
* program
|
|
41847
|
+
* .command('start <service>', 'start named service')
|
|
41848
|
+
* .command('stop [service]', 'stop named service, or all if no name supplied');
|
|
41849
|
+
*
|
|
41850
|
+
* @param {string} nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
|
|
41851
|
+
* @param {(object | string)} [actionOptsOrExecDesc] - configuration options (for action), or description (for executable)
|
|
41852
|
+
* @param {object} [execOpts] - configuration options (for executable)
|
|
41853
|
+
* @return {Command} returns new command for action handler, or `this` for executable command
|
|
41854
|
+
*/
|
|
41855
|
+
command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
|
|
41856
|
+
let desc = actionOptsOrExecDesc;
|
|
41857
|
+
let opts = execOpts;
|
|
41858
|
+
if (typeof desc === "object" && desc !== null) {
|
|
41859
|
+
opts = desc;
|
|
41860
|
+
desc = null;
|
|
41861
|
+
}
|
|
41862
|
+
opts = opts || {};
|
|
41863
|
+
const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
41864
|
+
const cmd = this.createCommand(name);
|
|
41865
|
+
if (desc) {
|
|
41866
|
+
cmd.description(desc);
|
|
41867
|
+
cmd._executableHandler = true;
|
|
41868
|
+
}
|
|
41869
|
+
if (opts.isDefault) this._defaultCommandName = cmd._name;
|
|
41870
|
+
cmd._hidden = !!(opts.noHelp || opts.hidden);
|
|
41871
|
+
cmd._executableFile = opts.executableFile || null;
|
|
41872
|
+
if (args) cmd.arguments(args);
|
|
41873
|
+
this._registerCommand(cmd);
|
|
41874
|
+
cmd.parent = this;
|
|
41875
|
+
cmd.copyInheritedSettings(this);
|
|
41876
|
+
if (desc) return this;
|
|
41877
|
+
return cmd;
|
|
41878
|
+
}
|
|
41879
|
+
/**
|
|
41880
|
+
* Factory routine to create a new unattached command.
|
|
41881
|
+
*
|
|
41882
|
+
* See .command() for creating an attached subcommand, which uses this routine to
|
|
41883
|
+
* create the command. You can override createCommand to customise subcommands.
|
|
41884
|
+
*
|
|
41885
|
+
* @param {string} [name]
|
|
41886
|
+
* @return {Command} new command
|
|
41887
|
+
*/
|
|
41888
|
+
createCommand(name) {
|
|
41889
|
+
return new _Command(name);
|
|
41890
|
+
}
|
|
41891
|
+
/**
|
|
41892
|
+
* You can customise the help with a subclass of Help by overriding createHelp,
|
|
41893
|
+
* or by overriding Help properties using configureHelp().
|
|
41894
|
+
*
|
|
41895
|
+
* @return {Help}
|
|
41896
|
+
*/
|
|
41897
|
+
createHelp() {
|
|
41898
|
+
return Object.assign(new Help2(), this.configureHelp());
|
|
41899
|
+
}
|
|
41900
|
+
/**
|
|
41901
|
+
* You can customise the help by overriding Help properties using configureHelp(),
|
|
41902
|
+
* or with a subclass of Help by overriding createHelp().
|
|
41903
|
+
*
|
|
41904
|
+
* @param {object} [configuration] - configuration options
|
|
41905
|
+
* @return {(Command | object)} `this` command for chaining, or stored configuration
|
|
41906
|
+
*/
|
|
41907
|
+
configureHelp(configuration) {
|
|
41908
|
+
if (configuration === void 0) return this._helpConfiguration;
|
|
41909
|
+
this._helpConfiguration = configuration;
|
|
41910
|
+
return this;
|
|
41911
|
+
}
|
|
41912
|
+
/**
|
|
41913
|
+
* The default output goes to stdout and stderr. You can customise this for special
|
|
41914
|
+
* applications. You can also customise the display of errors by overriding outputError.
|
|
41915
|
+
*
|
|
41916
|
+
* The configuration properties are all functions:
|
|
41917
|
+
*
|
|
41918
|
+
* // change how output being written, defaults to stdout and stderr
|
|
41919
|
+
* writeOut(str)
|
|
41920
|
+
* writeErr(str)
|
|
41921
|
+
* // change how output being written for errors, defaults to writeErr
|
|
41922
|
+
* outputError(str, write) // used for displaying errors and not used for displaying help
|
|
41923
|
+
* // specify width for wrapping help
|
|
41924
|
+
* getOutHelpWidth()
|
|
41925
|
+
* getErrHelpWidth()
|
|
41926
|
+
* // color support, currently only used with Help
|
|
41927
|
+
* getOutHasColors()
|
|
41928
|
+
* getErrHasColors()
|
|
41929
|
+
* stripColor() // used to remove ANSI escape codes if output does not have colors
|
|
41930
|
+
*
|
|
41931
|
+
* @param {object} [configuration] - configuration options
|
|
41932
|
+
* @return {(Command | object)} `this` command for chaining, or stored configuration
|
|
41933
|
+
*/
|
|
41934
|
+
configureOutput(configuration) {
|
|
41935
|
+
if (configuration === void 0) return this._outputConfiguration;
|
|
41936
|
+
this._outputConfiguration = {
|
|
41937
|
+
...this._outputConfiguration,
|
|
41938
|
+
...configuration
|
|
41939
|
+
};
|
|
41940
|
+
return this;
|
|
41941
|
+
}
|
|
41942
|
+
/**
|
|
41943
|
+
* Display the help or a custom message after an error occurs.
|
|
41944
|
+
*
|
|
41945
|
+
* @param {(boolean|string)} [displayHelp]
|
|
41946
|
+
* @return {Command} `this` command for chaining
|
|
41947
|
+
*/
|
|
41948
|
+
showHelpAfterError(displayHelp = true) {
|
|
41949
|
+
if (typeof displayHelp !== "string") displayHelp = !!displayHelp;
|
|
41950
|
+
this._showHelpAfterError = displayHelp;
|
|
41951
|
+
return this;
|
|
41952
|
+
}
|
|
41953
|
+
/**
|
|
41954
|
+
* Display suggestion of similar commands for unknown commands, or options for unknown options.
|
|
41955
|
+
*
|
|
41956
|
+
* @param {boolean} [displaySuggestion]
|
|
41957
|
+
* @return {Command} `this` command for chaining
|
|
41958
|
+
*/
|
|
41959
|
+
showSuggestionAfterError(displaySuggestion = true) {
|
|
41960
|
+
this._showSuggestionAfterError = !!displaySuggestion;
|
|
41961
|
+
return this;
|
|
41962
|
+
}
|
|
41963
|
+
/**
|
|
41964
|
+
* Add a prepared subcommand.
|
|
41965
|
+
*
|
|
41966
|
+
* See .command() for creating an attached subcommand which inherits settings from its parent.
|
|
41967
|
+
*
|
|
41968
|
+
* @param {Command} cmd - new subcommand
|
|
41969
|
+
* @param {object} [opts] - configuration options
|
|
41970
|
+
* @return {Command} `this` command for chaining
|
|
41971
|
+
*/
|
|
41972
|
+
addCommand(cmd, opts) {
|
|
41973
|
+
if (!cmd._name) {
|
|
41974
|
+
throw new Error(`Command passed to .addCommand() must have a name
|
|
41975
|
+
- specify the name in Command constructor or using .name()`);
|
|
41976
|
+
}
|
|
41977
|
+
opts = opts || {};
|
|
41978
|
+
if (opts.isDefault) this._defaultCommandName = cmd._name;
|
|
41979
|
+
if (opts.noHelp || opts.hidden) cmd._hidden = true;
|
|
41980
|
+
this._registerCommand(cmd);
|
|
41981
|
+
cmd.parent = this;
|
|
41982
|
+
cmd._checkForBrokenPassThrough();
|
|
41983
|
+
return this;
|
|
41984
|
+
}
|
|
41985
|
+
/**
|
|
41986
|
+
* Factory routine to create a new unattached argument.
|
|
41987
|
+
*
|
|
41988
|
+
* See .argument() for creating an attached argument, which uses this routine to
|
|
41989
|
+
* create the argument. You can override createArgument to return a custom argument.
|
|
41990
|
+
*
|
|
41991
|
+
* @param {string} name
|
|
41992
|
+
* @param {string} [description]
|
|
41993
|
+
* @return {Argument} new argument
|
|
41994
|
+
*/
|
|
41995
|
+
createArgument(name, description) {
|
|
41996
|
+
return new Argument2(name, description);
|
|
41997
|
+
}
|
|
41998
|
+
/**
|
|
41999
|
+
* Define argument syntax for command.
|
|
42000
|
+
*
|
|
42001
|
+
* The default is that the argument is required, and you can explicitly
|
|
42002
|
+
* indicate this with <> around the name. Put [] around the name for an optional argument.
|
|
42003
|
+
*
|
|
42004
|
+
* @example
|
|
42005
|
+
* program.argument('<input-file>');
|
|
42006
|
+
* program.argument('[output-file]');
|
|
42007
|
+
*
|
|
42008
|
+
* @param {string} name
|
|
42009
|
+
* @param {string} [description]
|
|
42010
|
+
* @param {(Function|*)} [parseArg] - custom argument processing function or default value
|
|
42011
|
+
* @param {*} [defaultValue]
|
|
42012
|
+
* @return {Command} `this` command for chaining
|
|
42013
|
+
*/
|
|
42014
|
+
argument(name, description, parseArg, defaultValue) {
|
|
42015
|
+
const argument = this.createArgument(name, description);
|
|
42016
|
+
if (typeof parseArg === "function") {
|
|
42017
|
+
argument.default(defaultValue).argParser(parseArg);
|
|
42018
|
+
} else {
|
|
42019
|
+
argument.default(parseArg);
|
|
42020
|
+
}
|
|
42021
|
+
this.addArgument(argument);
|
|
42022
|
+
return this;
|
|
42023
|
+
}
|
|
42024
|
+
/**
|
|
42025
|
+
* Define argument syntax for command, adding multiple at once (without descriptions).
|
|
42026
|
+
*
|
|
42027
|
+
* See also .argument().
|
|
42028
|
+
*
|
|
42029
|
+
* @example
|
|
42030
|
+
* program.arguments('<cmd> [env]');
|
|
42031
|
+
*
|
|
42032
|
+
* @param {string} names
|
|
42033
|
+
* @return {Command} `this` command for chaining
|
|
42034
|
+
*/
|
|
42035
|
+
arguments(names) {
|
|
42036
|
+
names.trim().split(/ +/).forEach((detail) => {
|
|
42037
|
+
this.argument(detail);
|
|
42038
|
+
});
|
|
42039
|
+
return this;
|
|
42040
|
+
}
|
|
42041
|
+
/**
|
|
42042
|
+
* Define argument syntax for command, adding a prepared argument.
|
|
42043
|
+
*
|
|
42044
|
+
* @param {Argument} argument
|
|
42045
|
+
* @return {Command} `this` command for chaining
|
|
42046
|
+
*/
|
|
42047
|
+
addArgument(argument) {
|
|
42048
|
+
const previousArgument = this.registeredArguments.slice(-1)[0];
|
|
42049
|
+
if (previousArgument?.variadic) {
|
|
42050
|
+
throw new Error(
|
|
42051
|
+
`only the last argument can be variadic '${previousArgument.name()}'`
|
|
42052
|
+
);
|
|
42053
|
+
}
|
|
42054
|
+
if (argument.required && argument.defaultValue !== void 0 && argument.parseArg === void 0) {
|
|
42055
|
+
throw new Error(
|
|
42056
|
+
`a default value for a required argument is never used: '${argument.name()}'`
|
|
42057
|
+
);
|
|
42058
|
+
}
|
|
42059
|
+
this.registeredArguments.push(argument);
|
|
42060
|
+
return this;
|
|
42061
|
+
}
|
|
42062
|
+
/**
|
|
42063
|
+
* Customise or override default help command. By default a help command is automatically added if your command has subcommands.
|
|
42064
|
+
*
|
|
42065
|
+
* @example
|
|
42066
|
+
* program.helpCommand('help [cmd]');
|
|
42067
|
+
* program.helpCommand('help [cmd]', 'show help');
|
|
42068
|
+
* program.helpCommand(false); // suppress default help command
|
|
42069
|
+
* program.helpCommand(true); // add help command even if no subcommands
|
|
42070
|
+
*
|
|
42071
|
+
* @param {string|boolean} enableOrNameAndArgs - enable with custom name and/or arguments, or boolean to override whether added
|
|
42072
|
+
* @param {string} [description] - custom description
|
|
42073
|
+
* @return {Command} `this` command for chaining
|
|
42074
|
+
*/
|
|
42075
|
+
helpCommand(enableOrNameAndArgs, description) {
|
|
42076
|
+
if (typeof enableOrNameAndArgs === "boolean") {
|
|
42077
|
+
this._addImplicitHelpCommand = enableOrNameAndArgs;
|
|
42078
|
+
if (enableOrNameAndArgs && this._defaultCommandGroup) {
|
|
42079
|
+
this._initCommandGroup(this._getHelpCommand());
|
|
42080
|
+
}
|
|
42081
|
+
return this;
|
|
42082
|
+
}
|
|
42083
|
+
const nameAndArgs = enableOrNameAndArgs ?? "help [command]";
|
|
42084
|
+
const [, helpName, helpArgs] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
42085
|
+
const helpDescription = description ?? "display help for command";
|
|
42086
|
+
const helpCommand = this.createCommand(helpName);
|
|
42087
|
+
helpCommand.helpOption(false);
|
|
42088
|
+
if (helpArgs) helpCommand.arguments(helpArgs);
|
|
42089
|
+
if (helpDescription) helpCommand.description(helpDescription);
|
|
42090
|
+
this._addImplicitHelpCommand = true;
|
|
42091
|
+
this._helpCommand = helpCommand;
|
|
42092
|
+
if (enableOrNameAndArgs || description) this._initCommandGroup(helpCommand);
|
|
42093
|
+
return this;
|
|
42094
|
+
}
|
|
42095
|
+
/**
|
|
42096
|
+
* Add prepared custom help command.
|
|
42097
|
+
*
|
|
42098
|
+
* @param {(Command|string|boolean)} helpCommand - custom help command, or deprecated enableOrNameAndArgs as for `.helpCommand()`
|
|
42099
|
+
* @param {string} [deprecatedDescription] - deprecated custom description used with custom name only
|
|
42100
|
+
* @return {Command} `this` command for chaining
|
|
42101
|
+
*/
|
|
42102
|
+
addHelpCommand(helpCommand, deprecatedDescription) {
|
|
42103
|
+
if (typeof helpCommand !== "object") {
|
|
42104
|
+
this.helpCommand(helpCommand, deprecatedDescription);
|
|
42105
|
+
return this;
|
|
42106
|
+
}
|
|
42107
|
+
this._addImplicitHelpCommand = true;
|
|
42108
|
+
this._helpCommand = helpCommand;
|
|
42109
|
+
this._initCommandGroup(helpCommand);
|
|
42110
|
+
return this;
|
|
42111
|
+
}
|
|
42112
|
+
/**
|
|
42113
|
+
* Lazy create help command.
|
|
42114
|
+
*
|
|
42115
|
+
* @return {(Command|null)}
|
|
42116
|
+
* @package
|
|
42117
|
+
*/
|
|
42118
|
+
_getHelpCommand() {
|
|
42119
|
+
const hasImplicitHelpCommand = this._addImplicitHelpCommand ?? (this.commands.length && !this._actionHandler && !this._findCommand("help"));
|
|
42120
|
+
if (hasImplicitHelpCommand) {
|
|
42121
|
+
if (this._helpCommand === void 0) {
|
|
42122
|
+
this.helpCommand(void 0, void 0);
|
|
42123
|
+
}
|
|
42124
|
+
return this._helpCommand;
|
|
42125
|
+
}
|
|
42126
|
+
return null;
|
|
42127
|
+
}
|
|
42128
|
+
/**
|
|
42129
|
+
* Add hook for life cycle event.
|
|
42130
|
+
*
|
|
42131
|
+
* @param {string} event
|
|
42132
|
+
* @param {Function} listener
|
|
42133
|
+
* @return {Command} `this` command for chaining
|
|
42134
|
+
*/
|
|
42135
|
+
hook(event, listener) {
|
|
42136
|
+
const allowedValues = ["preSubcommand", "preAction", "postAction"];
|
|
42137
|
+
if (!allowedValues.includes(event)) {
|
|
42138
|
+
throw new Error(`Unexpected value for event passed to hook : '${event}'.
|
|
42139
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
42140
|
+
}
|
|
42141
|
+
if (this._lifeCycleHooks[event]) {
|
|
42142
|
+
this._lifeCycleHooks[event].push(listener);
|
|
42143
|
+
} else {
|
|
42144
|
+
this._lifeCycleHooks[event] = [listener];
|
|
42145
|
+
}
|
|
42146
|
+
return this;
|
|
42147
|
+
}
|
|
42148
|
+
/**
|
|
42149
|
+
* Register callback to use as replacement for calling process.exit.
|
|
42150
|
+
*
|
|
42151
|
+
* @param {Function} [fn] optional callback which will be passed a CommanderError, defaults to throwing
|
|
42152
|
+
* @return {Command} `this` command for chaining
|
|
42153
|
+
*/
|
|
42154
|
+
exitOverride(fn) {
|
|
42155
|
+
if (fn) {
|
|
42156
|
+
this._exitCallback = fn;
|
|
42157
|
+
} else {
|
|
42158
|
+
this._exitCallback = (err) => {
|
|
42159
|
+
if (err.code !== "commander.executeSubCommandAsync") {
|
|
42160
|
+
throw err;
|
|
42161
|
+
} else {
|
|
42162
|
+
}
|
|
42163
|
+
};
|
|
42164
|
+
}
|
|
42165
|
+
return this;
|
|
42166
|
+
}
|
|
42167
|
+
/**
|
|
42168
|
+
* Call process.exit, and _exitCallback if defined.
|
|
42169
|
+
*
|
|
42170
|
+
* @param {number} exitCode exit code for using with process.exit
|
|
42171
|
+
* @param {string} code an id string representing the error
|
|
42172
|
+
* @param {string} message human-readable description of the error
|
|
42173
|
+
* @return never
|
|
42174
|
+
* @private
|
|
42175
|
+
*/
|
|
42176
|
+
_exit(exitCode3, code, message) {
|
|
42177
|
+
if (this._exitCallback) {
|
|
42178
|
+
this._exitCallback(new CommanderError2(exitCode3, code, message));
|
|
42179
|
+
}
|
|
42180
|
+
process4.exit(exitCode3);
|
|
42181
|
+
}
|
|
42182
|
+
/**
|
|
42183
|
+
* Register callback `fn` for the command.
|
|
42184
|
+
*
|
|
42185
|
+
* @example
|
|
42186
|
+
* program
|
|
42187
|
+
* .command('serve')
|
|
42188
|
+
* .description('start service')
|
|
42189
|
+
* .action(function() {
|
|
42190
|
+
* // do work here
|
|
42191
|
+
* });
|
|
42192
|
+
*
|
|
42193
|
+
* @param {Function} fn
|
|
42194
|
+
* @return {Command} `this` command for chaining
|
|
42195
|
+
*/
|
|
42196
|
+
action(fn) {
|
|
42197
|
+
const listener = (args) => {
|
|
42198
|
+
const expectedArgsCount = this.registeredArguments.length;
|
|
42199
|
+
const actionArgs = args.slice(0, expectedArgsCount);
|
|
42200
|
+
if (this._storeOptionsAsProperties) {
|
|
42201
|
+
actionArgs[expectedArgsCount] = this;
|
|
42202
|
+
} else {
|
|
42203
|
+
actionArgs[expectedArgsCount] = this.opts();
|
|
42204
|
+
}
|
|
42205
|
+
actionArgs.push(this);
|
|
42206
|
+
return fn.apply(this, actionArgs);
|
|
42207
|
+
};
|
|
42208
|
+
this._actionHandler = listener;
|
|
42209
|
+
return this;
|
|
42210
|
+
}
|
|
42211
|
+
/**
|
|
42212
|
+
* Factory routine to create a new unattached option.
|
|
42213
|
+
*
|
|
42214
|
+
* See .option() for creating an attached option, which uses this routine to
|
|
42215
|
+
* create the option. You can override createOption to return a custom option.
|
|
42216
|
+
*
|
|
42217
|
+
* @param {string} flags
|
|
42218
|
+
* @param {string} [description]
|
|
42219
|
+
* @return {Option} new option
|
|
42220
|
+
*/
|
|
42221
|
+
createOption(flags, description) {
|
|
42222
|
+
return new Option2(flags, description);
|
|
42223
|
+
}
|
|
42224
|
+
/**
|
|
42225
|
+
* Wrap parseArgs to catch 'commander.invalidArgument'.
|
|
42226
|
+
*
|
|
42227
|
+
* @param {(Option | Argument)} target
|
|
42228
|
+
* @param {string} value
|
|
42229
|
+
* @param {*} previous
|
|
42230
|
+
* @param {string} invalidArgumentMessage
|
|
42231
|
+
* @private
|
|
42232
|
+
*/
|
|
42233
|
+
_callParseArg(target, value, previous, invalidArgumentMessage) {
|
|
42234
|
+
try {
|
|
42235
|
+
return target.parseArg(value, previous);
|
|
42236
|
+
} catch (err) {
|
|
42237
|
+
if (err.code === "commander.invalidArgument") {
|
|
42238
|
+
const message = `${invalidArgumentMessage} ${err.message}`;
|
|
42239
|
+
this.error(message, { exitCode: err.exitCode, code: err.code });
|
|
42240
|
+
}
|
|
42241
|
+
throw err;
|
|
42242
|
+
}
|
|
42243
|
+
}
|
|
42244
|
+
/**
|
|
42245
|
+
* Check for option flag conflicts.
|
|
42246
|
+
* Register option if no conflicts found, or throw on conflict.
|
|
42247
|
+
*
|
|
42248
|
+
* @param {Option} option
|
|
42249
|
+
* @private
|
|
42250
|
+
*/
|
|
42251
|
+
_registerOption(option) {
|
|
42252
|
+
const matchingOption = option.short && this._findOption(option.short) || option.long && this._findOption(option.long);
|
|
42253
|
+
if (matchingOption) {
|
|
42254
|
+
const matchingFlag = option.long && this._findOption(option.long) ? option.long : option.short;
|
|
42255
|
+
throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
|
|
42256
|
+
- already used by option '${matchingOption.flags}'`);
|
|
42257
|
+
}
|
|
42258
|
+
this._initOptionGroup(option);
|
|
42259
|
+
this.options.push(option);
|
|
42260
|
+
}
|
|
42261
|
+
/**
|
|
42262
|
+
* Check for command name and alias conflicts with existing commands.
|
|
42263
|
+
* Register command if no conflicts found, or throw on conflict.
|
|
42264
|
+
*
|
|
42265
|
+
* @param {Command} command
|
|
42266
|
+
* @private
|
|
42267
|
+
*/
|
|
42268
|
+
_registerCommand(command) {
|
|
42269
|
+
const knownBy = (cmd) => {
|
|
42270
|
+
return [cmd.name()].concat(cmd.aliases());
|
|
42271
|
+
};
|
|
42272
|
+
const alreadyUsed = knownBy(command).find(
|
|
42273
|
+
(name) => this._findCommand(name)
|
|
42274
|
+
);
|
|
42275
|
+
if (alreadyUsed) {
|
|
42276
|
+
const existingCmd = knownBy(this._findCommand(alreadyUsed)).join("|");
|
|
42277
|
+
const newCmd = knownBy(command).join("|");
|
|
42278
|
+
throw new Error(
|
|
42279
|
+
`cannot add command '${newCmd}' as already have command '${existingCmd}'`
|
|
42280
|
+
);
|
|
42281
|
+
}
|
|
42282
|
+
this._initCommandGroup(command);
|
|
42283
|
+
this.commands.push(command);
|
|
42284
|
+
}
|
|
42285
|
+
/**
|
|
42286
|
+
* Add an option.
|
|
42287
|
+
*
|
|
42288
|
+
* @param {Option} option
|
|
42289
|
+
* @return {Command} `this` command for chaining
|
|
42290
|
+
*/
|
|
42291
|
+
addOption(option) {
|
|
42292
|
+
this._registerOption(option);
|
|
42293
|
+
const oname = option.name();
|
|
42294
|
+
const name = option.attributeName();
|
|
42295
|
+
if (option.negate) {
|
|
42296
|
+
const positiveLongFlag = option.long.replace(/^--no-/, "--");
|
|
42297
|
+
if (!this._findOption(positiveLongFlag)) {
|
|
42298
|
+
this.setOptionValueWithSource(
|
|
42299
|
+
name,
|
|
42300
|
+
option.defaultValue === void 0 ? true : option.defaultValue,
|
|
42301
|
+
"default"
|
|
42302
|
+
);
|
|
42303
|
+
}
|
|
42304
|
+
} else if (option.defaultValue !== void 0) {
|
|
42305
|
+
this.setOptionValueWithSource(name, option.defaultValue, "default");
|
|
42306
|
+
}
|
|
42307
|
+
const handleOptionValue = (val, invalidValueMessage, valueSource) => {
|
|
42308
|
+
if (val == null && option.presetArg !== void 0) {
|
|
42309
|
+
val = option.presetArg;
|
|
42310
|
+
}
|
|
42311
|
+
const oldValue = this.getOptionValue(name);
|
|
42312
|
+
if (val !== null && option.parseArg) {
|
|
42313
|
+
val = this._callParseArg(option, val, oldValue, invalidValueMessage);
|
|
42314
|
+
} else if (val !== null && option.variadic) {
|
|
42315
|
+
val = option._collectValue(val, oldValue);
|
|
42316
|
+
}
|
|
42317
|
+
if (val == null) {
|
|
42318
|
+
if (option.negate) {
|
|
42319
|
+
val = false;
|
|
42320
|
+
} else if (option.isBoolean() || option.optional) {
|
|
42321
|
+
val = true;
|
|
42322
|
+
} else {
|
|
42323
|
+
val = "";
|
|
42324
|
+
}
|
|
42325
|
+
}
|
|
42326
|
+
this.setOptionValueWithSource(name, val, valueSource);
|
|
42327
|
+
};
|
|
42328
|
+
this.on("option:" + oname, (val) => {
|
|
42329
|
+
const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
|
|
42330
|
+
handleOptionValue(val, invalidValueMessage, "cli");
|
|
42331
|
+
});
|
|
42332
|
+
if (option.envVar) {
|
|
42333
|
+
this.on("optionEnv:" + oname, (val) => {
|
|
42334
|
+
const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
|
|
42335
|
+
handleOptionValue(val, invalidValueMessage, "env");
|
|
42336
|
+
});
|
|
42337
|
+
}
|
|
42338
|
+
return this;
|
|
42339
|
+
}
|
|
42340
|
+
/**
|
|
42341
|
+
* Internal implementation shared by .option() and .requiredOption()
|
|
42342
|
+
*
|
|
42343
|
+
* @return {Command} `this` command for chaining
|
|
42344
|
+
* @private
|
|
42345
|
+
*/
|
|
42346
|
+
_optionEx(config2, flags, description, fn, defaultValue) {
|
|
42347
|
+
if (typeof flags === "object" && flags instanceof Option2) {
|
|
42348
|
+
throw new Error(
|
|
42349
|
+
"To add an Option object use addOption() instead of option() or requiredOption()"
|
|
42350
|
+
);
|
|
42351
|
+
}
|
|
42352
|
+
const option = this.createOption(flags, description);
|
|
42353
|
+
option.makeOptionMandatory(!!config2.mandatory);
|
|
42354
|
+
if (typeof fn === "function") {
|
|
42355
|
+
option.default(defaultValue).argParser(fn);
|
|
42356
|
+
} else if (fn instanceof RegExp) {
|
|
42357
|
+
const regex = fn;
|
|
42358
|
+
fn = (val, def) => {
|
|
42359
|
+
const m = regex.exec(val);
|
|
42360
|
+
return m ? m[0] : def;
|
|
42361
|
+
};
|
|
42362
|
+
option.default(defaultValue).argParser(fn);
|
|
42363
|
+
} else {
|
|
42364
|
+
option.default(fn);
|
|
42365
|
+
}
|
|
42366
|
+
return this.addOption(option);
|
|
42367
|
+
}
|
|
42368
|
+
/**
|
|
42369
|
+
* Define option with `flags`, `description`, and optional argument parsing function or `defaultValue` or both.
|
|
42370
|
+
*
|
|
42371
|
+
* The `flags` string contains the short and/or long flags, separated by comma, a pipe or space. A required
|
|
42372
|
+
* option-argument is indicated by `<>` and an optional option-argument by `[]`.
|
|
42373
|
+
*
|
|
42374
|
+
* See the README for more details, and see also addOption() and requiredOption().
|
|
42375
|
+
*
|
|
42376
|
+
* @example
|
|
42377
|
+
* program
|
|
42378
|
+
* .option('-p, --pepper', 'add pepper')
|
|
42379
|
+
* .option('--pt, --pizza-type <TYPE>', 'type of pizza') // required option-argument
|
|
42380
|
+
* .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default
|
|
42381
|
+
* .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function
|
|
42382
|
+
*
|
|
42383
|
+
* @param {string} flags
|
|
42384
|
+
* @param {string} [description]
|
|
42385
|
+
* @param {(Function|*)} [parseArg] - custom option processing function or default value
|
|
42386
|
+
* @param {*} [defaultValue]
|
|
42387
|
+
* @return {Command} `this` command for chaining
|
|
42388
|
+
*/
|
|
42389
|
+
option(flags, description, parseArg, defaultValue) {
|
|
42390
|
+
return this._optionEx({}, flags, description, parseArg, defaultValue);
|
|
42391
|
+
}
|
|
42392
|
+
/**
|
|
42393
|
+
* Add a required option which must have a value after parsing. This usually means
|
|
42394
|
+
* the option must be specified on the command line. (Otherwise the same as .option().)
|
|
42395
|
+
*
|
|
42396
|
+
* The `flags` string contains the short and/or long flags, separated by comma, a pipe or space.
|
|
42397
|
+
*
|
|
42398
|
+
* @param {string} flags
|
|
42399
|
+
* @param {string} [description]
|
|
42400
|
+
* @param {(Function|*)} [parseArg] - custom option processing function or default value
|
|
42401
|
+
* @param {*} [defaultValue]
|
|
42402
|
+
* @return {Command} `this` command for chaining
|
|
42403
|
+
*/
|
|
42404
|
+
requiredOption(flags, description, parseArg, defaultValue) {
|
|
42405
|
+
return this._optionEx(
|
|
42406
|
+
{ mandatory: true },
|
|
42407
|
+
flags,
|
|
42408
|
+
description,
|
|
42409
|
+
parseArg,
|
|
42410
|
+
defaultValue
|
|
42411
|
+
);
|
|
42412
|
+
}
|
|
42413
|
+
/**
|
|
42414
|
+
* Alter parsing of short flags with optional values.
|
|
42415
|
+
*
|
|
42416
|
+
* @example
|
|
42417
|
+
* // for `.option('-f,--flag [value]'):
|
|
42418
|
+
* program.combineFlagAndOptionalValue(true); // `-f80` is treated like `--flag=80`, this is the default behaviour
|
|
42419
|
+
* program.combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
|
|
42420
|
+
*
|
|
42421
|
+
* @param {boolean} [combine] - if `true` or omitted, an optional value can be specified directly after the flag.
|
|
42422
|
+
* @return {Command} `this` command for chaining
|
|
42423
|
+
*/
|
|
42424
|
+
combineFlagAndOptionalValue(combine = true) {
|
|
42425
|
+
this._combineFlagAndOptionalValue = !!combine;
|
|
42426
|
+
return this;
|
|
42427
|
+
}
|
|
42428
|
+
/**
|
|
42429
|
+
* Allow unknown options on the command line.
|
|
42430
|
+
*
|
|
42431
|
+
* @param {boolean} [allowUnknown] - if `true` or omitted, no error will be thrown for unknown options.
|
|
42432
|
+
* @return {Command} `this` command for chaining
|
|
42433
|
+
*/
|
|
42434
|
+
allowUnknownOption(allowUnknown = true) {
|
|
42435
|
+
this._allowUnknownOption = !!allowUnknown;
|
|
42436
|
+
return this;
|
|
42437
|
+
}
|
|
42438
|
+
/**
|
|
42439
|
+
* Allow excess command-arguments on the command line. Pass false to make excess arguments an error.
|
|
42440
|
+
*
|
|
42441
|
+
* @param {boolean} [allowExcess] - if `true` or omitted, no error will be thrown for excess arguments.
|
|
42442
|
+
* @return {Command} `this` command for chaining
|
|
42443
|
+
*/
|
|
42444
|
+
allowExcessArguments(allowExcess = true) {
|
|
42445
|
+
this._allowExcessArguments = !!allowExcess;
|
|
42446
|
+
return this;
|
|
42447
|
+
}
|
|
42448
|
+
/**
|
|
42449
|
+
* Enable positional options. Positional means global options are specified before subcommands which lets
|
|
42450
|
+
* subcommands reuse the same option names, and also enables subcommands to turn on passThroughOptions.
|
|
42451
|
+
* The default behaviour is non-positional and global options may appear anywhere on the command line.
|
|
42452
|
+
*
|
|
42453
|
+
* @param {boolean} [positional]
|
|
42454
|
+
* @return {Command} `this` command for chaining
|
|
42455
|
+
*/
|
|
42456
|
+
enablePositionalOptions(positional = true) {
|
|
42457
|
+
this._enablePositionalOptions = !!positional;
|
|
42458
|
+
return this;
|
|
42459
|
+
}
|
|
42460
|
+
/**
|
|
42461
|
+
* Pass through options that come after command-arguments rather than treat them as command-options,
|
|
42462
|
+
* so actual command-options come before command-arguments. Turning this on for a subcommand requires
|
|
42463
|
+
* positional options to have been enabled on the program (parent commands).
|
|
42464
|
+
* The default behaviour is non-positional and options may appear before or after command-arguments.
|
|
42465
|
+
*
|
|
42466
|
+
* @param {boolean} [passThrough] for unknown options.
|
|
42467
|
+
* @return {Command} `this` command for chaining
|
|
42468
|
+
*/
|
|
42469
|
+
passThroughOptions(passThrough = true) {
|
|
42470
|
+
this._passThroughOptions = !!passThrough;
|
|
42471
|
+
this._checkForBrokenPassThrough();
|
|
42472
|
+
return this;
|
|
42473
|
+
}
|
|
42474
|
+
/**
|
|
42475
|
+
* @private
|
|
42476
|
+
*/
|
|
42477
|
+
_checkForBrokenPassThrough() {
|
|
42478
|
+
if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
|
|
42479
|
+
throw new Error(
|
|
42480
|
+
`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`
|
|
42481
|
+
);
|
|
42482
|
+
}
|
|
42483
|
+
}
|
|
42484
|
+
/**
|
|
42485
|
+
* Whether to store option values as properties on command object,
|
|
42486
|
+
* or store separately (specify false). In both cases the option values can be accessed using .opts().
|
|
42487
|
+
*
|
|
42488
|
+
* @param {boolean} [storeAsProperties=true]
|
|
42489
|
+
* @return {Command} `this` command for chaining
|
|
42490
|
+
*/
|
|
42491
|
+
storeOptionsAsProperties(storeAsProperties = true) {
|
|
42492
|
+
if (this.options.length) {
|
|
42493
|
+
throw new Error("call .storeOptionsAsProperties() before adding options");
|
|
42494
|
+
}
|
|
42495
|
+
if (Object.keys(this._optionValues).length) {
|
|
42496
|
+
throw new Error(
|
|
42497
|
+
"call .storeOptionsAsProperties() before setting option values"
|
|
42498
|
+
);
|
|
42499
|
+
}
|
|
42500
|
+
this._storeOptionsAsProperties = !!storeAsProperties;
|
|
42501
|
+
return this;
|
|
42502
|
+
}
|
|
42503
|
+
/**
|
|
42504
|
+
* Retrieve option value.
|
|
42505
|
+
*
|
|
42506
|
+
* @param {string} key
|
|
42507
|
+
* @return {object} value
|
|
42508
|
+
*/
|
|
42509
|
+
getOptionValue(key) {
|
|
42510
|
+
if (this._storeOptionsAsProperties) {
|
|
42511
|
+
return this[key];
|
|
42512
|
+
}
|
|
42513
|
+
return this._optionValues[key];
|
|
42514
|
+
}
|
|
42515
|
+
/**
|
|
42516
|
+
* Store option value.
|
|
42517
|
+
*
|
|
42518
|
+
* @param {string} key
|
|
42519
|
+
* @param {object} value
|
|
42520
|
+
* @return {Command} `this` command for chaining
|
|
42521
|
+
*/
|
|
42522
|
+
setOptionValue(key, value) {
|
|
42523
|
+
return this.setOptionValueWithSource(key, value, void 0);
|
|
42524
|
+
}
|
|
42525
|
+
/**
|
|
42526
|
+
* Store option value and where the value came from.
|
|
42527
|
+
*
|
|
42528
|
+
* @param {string} key
|
|
42529
|
+
* @param {object} value
|
|
42530
|
+
* @param {string} source - expected values are default/config/env/cli/implied
|
|
42531
|
+
* @return {Command} `this` command for chaining
|
|
42532
|
+
*/
|
|
42533
|
+
setOptionValueWithSource(key, value, source) {
|
|
42534
|
+
if (this._storeOptionsAsProperties) {
|
|
42535
|
+
this[key] = value;
|
|
42536
|
+
} else {
|
|
42537
|
+
this._optionValues[key] = value;
|
|
42538
|
+
}
|
|
42539
|
+
this._optionValueSources[key] = source;
|
|
42540
|
+
return this;
|
|
42541
|
+
}
|
|
42542
|
+
/**
|
|
42543
|
+
* Get source of option value.
|
|
42544
|
+
* Expected values are default | config | env | cli | implied
|
|
42545
|
+
*
|
|
42546
|
+
* @param {string} key
|
|
42547
|
+
* @return {string}
|
|
42548
|
+
*/
|
|
42549
|
+
getOptionValueSource(key) {
|
|
42550
|
+
return this._optionValueSources[key];
|
|
42551
|
+
}
|
|
42552
|
+
/**
|
|
42553
|
+
* Get source of option value. See also .optsWithGlobals().
|
|
42554
|
+
* Expected values are default | config | env | cli | implied
|
|
42555
|
+
*
|
|
42556
|
+
* @param {string} key
|
|
42557
|
+
* @return {string}
|
|
42558
|
+
*/
|
|
42559
|
+
getOptionValueSourceWithGlobals(key) {
|
|
42560
|
+
let source;
|
|
42561
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
42562
|
+
if (cmd.getOptionValueSource(key) !== void 0) {
|
|
42563
|
+
source = cmd.getOptionValueSource(key);
|
|
42564
|
+
}
|
|
42565
|
+
});
|
|
42566
|
+
return source;
|
|
42567
|
+
}
|
|
42568
|
+
/**
|
|
42569
|
+
* Get user arguments from implied or explicit arguments.
|
|
42570
|
+
* Side-effects: set _scriptPath if args included script. Used for default program name, and subcommand searches.
|
|
42571
|
+
*
|
|
42572
|
+
* @private
|
|
42573
|
+
*/
|
|
42574
|
+
_prepareUserArgs(argv, parseOptions) {
|
|
42575
|
+
if (argv !== void 0 && !Array.isArray(argv)) {
|
|
42576
|
+
throw new Error("first parameter to parse must be array or undefined");
|
|
42577
|
+
}
|
|
42578
|
+
parseOptions = parseOptions || {};
|
|
42579
|
+
if (argv === void 0 && parseOptions.from === void 0) {
|
|
42580
|
+
if (process4.versions?.electron) {
|
|
42581
|
+
parseOptions.from = "electron";
|
|
42582
|
+
}
|
|
42583
|
+
const execArgv = process4.execArgv ?? [];
|
|
42584
|
+
if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
|
|
42585
|
+
parseOptions.from = "eval";
|
|
42586
|
+
}
|
|
42587
|
+
}
|
|
42588
|
+
if (argv === void 0) {
|
|
42589
|
+
argv = process4.argv;
|
|
42590
|
+
}
|
|
42591
|
+
this.rawArgs = argv.slice();
|
|
42592
|
+
let userArgs;
|
|
42593
|
+
switch (parseOptions.from) {
|
|
42594
|
+
case void 0:
|
|
42595
|
+
case "node":
|
|
42596
|
+
this._scriptPath = argv[1];
|
|
42597
|
+
userArgs = argv.slice(2);
|
|
42598
|
+
break;
|
|
42599
|
+
case "electron":
|
|
42600
|
+
if (process4.defaultApp) {
|
|
42601
|
+
this._scriptPath = argv[1];
|
|
42602
|
+
userArgs = argv.slice(2);
|
|
42603
|
+
} else {
|
|
42604
|
+
userArgs = argv.slice(1);
|
|
42605
|
+
}
|
|
42606
|
+
break;
|
|
42607
|
+
case "user":
|
|
42608
|
+
userArgs = argv.slice(0);
|
|
42609
|
+
break;
|
|
42610
|
+
case "eval":
|
|
42611
|
+
userArgs = argv.slice(1);
|
|
42612
|
+
break;
|
|
42613
|
+
default:
|
|
42614
|
+
throw new Error(
|
|
42615
|
+
`unexpected parse option { from: '${parseOptions.from}' }`
|
|
42616
|
+
);
|
|
42617
|
+
}
|
|
42618
|
+
if (!this._name && this._scriptPath)
|
|
42619
|
+
this.nameFromFilename(this._scriptPath);
|
|
42620
|
+
this._name = this._name || "program";
|
|
42621
|
+
return userArgs;
|
|
42622
|
+
}
|
|
42623
|
+
/**
|
|
42624
|
+
* Parse `argv`, setting options and invoking commands when defined.
|
|
42625
|
+
*
|
|
42626
|
+
* Use parseAsync instead of parse if any of your action handlers are async.
|
|
42627
|
+
*
|
|
42628
|
+
* Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
|
|
42629
|
+
*
|
|
42630
|
+
* Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
|
|
42631
|
+
* - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
|
|
42632
|
+
* - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
|
|
42633
|
+
* - `'user'`: just user arguments
|
|
42634
|
+
*
|
|
42635
|
+
* @example
|
|
42636
|
+
* program.parse(); // parse process.argv and auto-detect electron and special node flags
|
|
42637
|
+
* program.parse(process.argv); // assume argv[0] is app and argv[1] is script
|
|
42638
|
+
* program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
|
42639
|
+
*
|
|
42640
|
+
* @param {string[]} [argv] - optional, defaults to process.argv
|
|
42641
|
+
* @param {object} [parseOptions] - optionally specify style of options with from: node/user/electron
|
|
42642
|
+
* @param {string} [parseOptions.from] - where the args are from: 'node', 'user', 'electron'
|
|
42643
|
+
* @return {Command} `this` command for chaining
|
|
42644
|
+
*/
|
|
42645
|
+
parse(argv, parseOptions) {
|
|
42646
|
+
this._prepareForParse();
|
|
42647
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
42648
|
+
this._parseCommand([], userArgs);
|
|
42649
|
+
return this;
|
|
42650
|
+
}
|
|
42651
|
+
/**
|
|
42652
|
+
* Parse `argv`, setting options and invoking commands when defined.
|
|
42653
|
+
*
|
|
42654
|
+
* Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
|
|
42655
|
+
*
|
|
42656
|
+
* Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
|
|
42657
|
+
* - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
|
|
42658
|
+
* - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
|
|
42659
|
+
* - `'user'`: just user arguments
|
|
42660
|
+
*
|
|
42661
|
+
* @example
|
|
42662
|
+
* await program.parseAsync(); // parse process.argv and auto-detect electron and special node flags
|
|
42663
|
+
* await program.parseAsync(process.argv); // assume argv[0] is app and argv[1] is script
|
|
42664
|
+
* await program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
|
42665
|
+
*
|
|
42666
|
+
* @param {string[]} [argv]
|
|
42667
|
+
* @param {object} [parseOptions]
|
|
42668
|
+
* @param {string} parseOptions.from - where the args are from: 'node', 'user', 'electron'
|
|
42669
|
+
* @return {Promise}
|
|
42670
|
+
*/
|
|
42671
|
+
async parseAsync(argv, parseOptions) {
|
|
42672
|
+
this._prepareForParse();
|
|
42673
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
42674
|
+
await this._parseCommand([], userArgs);
|
|
42675
|
+
return this;
|
|
42676
|
+
}
|
|
42677
|
+
_prepareForParse() {
|
|
42678
|
+
if (this._savedState === null) {
|
|
42679
|
+
this.saveStateBeforeParse();
|
|
42680
|
+
} else {
|
|
42681
|
+
this.restoreStateBeforeParse();
|
|
42682
|
+
}
|
|
42683
|
+
}
|
|
42684
|
+
/**
|
|
42685
|
+
* Called the first time parse is called to save state and allow a restore before subsequent calls to parse.
|
|
42686
|
+
* Not usually called directly, but available for subclasses to save their custom state.
|
|
42687
|
+
*
|
|
42688
|
+
* This is called in a lazy way. Only commands used in parsing chain will have state saved.
|
|
42689
|
+
*/
|
|
42690
|
+
saveStateBeforeParse() {
|
|
42691
|
+
this._savedState = {
|
|
42692
|
+
// name is stable if supplied by author, but may be unspecified for root command and deduced during parsing
|
|
42693
|
+
_name: this._name,
|
|
42694
|
+
// option values before parse have default values (including false for negated options)
|
|
42695
|
+
// shallow clones
|
|
42696
|
+
_optionValues: { ...this._optionValues },
|
|
42697
|
+
_optionValueSources: { ...this._optionValueSources }
|
|
42698
|
+
};
|
|
42699
|
+
}
|
|
42700
|
+
/**
|
|
42701
|
+
* Restore state before parse for calls after the first.
|
|
42702
|
+
* Not usually called directly, but available for subclasses to save their custom state.
|
|
42703
|
+
*
|
|
42704
|
+
* This is called in a lazy way. Only commands used in parsing chain will have state restored.
|
|
42705
|
+
*/
|
|
42706
|
+
restoreStateBeforeParse() {
|
|
42707
|
+
if (this._storeOptionsAsProperties)
|
|
42708
|
+
throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
|
|
42709
|
+
- either make a new Command for each call to parse, or stop storing options as properties`);
|
|
42710
|
+
this._name = this._savedState._name;
|
|
42711
|
+
this._scriptPath = null;
|
|
42712
|
+
this.rawArgs = [];
|
|
42713
|
+
this._optionValues = { ...this._savedState._optionValues };
|
|
42714
|
+
this._optionValueSources = { ...this._savedState._optionValueSources };
|
|
42715
|
+
this.args = [];
|
|
42716
|
+
this.processedArgs = [];
|
|
42717
|
+
}
|
|
42718
|
+
/**
|
|
42719
|
+
* Throw if expected executable is missing. Add lots of help for author.
|
|
42720
|
+
*
|
|
42721
|
+
* @param {string} executableFile
|
|
42722
|
+
* @param {string} executableDir
|
|
42723
|
+
* @param {string} subcommandName
|
|
42724
|
+
*/
|
|
42725
|
+
_checkForMissingExecutable(executableFile, executableDir, subcommandName) {
|
|
42726
|
+
if (fs19.existsSync(executableFile)) return;
|
|
42727
|
+
const executableDirMessage = executableDir ? `searched for local subcommand relative to directory '${executableDir}'` : "no directory for search for local subcommand, use .executableDir() to supply a custom directory";
|
|
42728
|
+
const executableMissing = `'${executableFile}' does not exist
|
|
42729
|
+
- if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
42730
|
+
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
42731
|
+
- ${executableDirMessage}`;
|
|
42732
|
+
throw new Error(executableMissing);
|
|
42733
|
+
}
|
|
42734
|
+
/**
|
|
42735
|
+
* Execute a sub-command executable.
|
|
42736
|
+
*
|
|
42737
|
+
* @private
|
|
42738
|
+
*/
|
|
42739
|
+
_executeSubCommand(subcommand, args) {
|
|
42740
|
+
args = args.slice();
|
|
42741
|
+
let launchWithNode = false;
|
|
42742
|
+
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
42743
|
+
function findFile(baseDir, baseName) {
|
|
42744
|
+
const localBin = path19.resolve(baseDir, baseName);
|
|
42745
|
+
if (fs19.existsSync(localBin)) return localBin;
|
|
42746
|
+
if (sourceExt.includes(path19.extname(baseName))) return void 0;
|
|
42747
|
+
const foundExt = sourceExt.find(
|
|
42748
|
+
(ext2) => fs19.existsSync(`${localBin}${ext2}`)
|
|
42749
|
+
);
|
|
42750
|
+
if (foundExt) return `${localBin}${foundExt}`;
|
|
42751
|
+
return void 0;
|
|
42752
|
+
}
|
|
42753
|
+
this._checkForMissingMandatoryOptions();
|
|
42754
|
+
this._checkForConflictingOptions();
|
|
42755
|
+
let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
|
|
42756
|
+
let executableDir = this._executableDir || "";
|
|
42757
|
+
if (this._scriptPath) {
|
|
42758
|
+
let resolvedScriptPath;
|
|
42759
|
+
try {
|
|
42760
|
+
resolvedScriptPath = fs19.realpathSync(this._scriptPath);
|
|
42761
|
+
} catch {
|
|
42762
|
+
resolvedScriptPath = this._scriptPath;
|
|
42763
|
+
}
|
|
42764
|
+
executableDir = path19.resolve(
|
|
42765
|
+
path19.dirname(resolvedScriptPath),
|
|
42766
|
+
executableDir
|
|
42767
|
+
);
|
|
42768
|
+
}
|
|
42769
|
+
if (executableDir) {
|
|
42770
|
+
let localFile = findFile(executableDir, executableFile);
|
|
42771
|
+
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
42772
|
+
const legacyName = path19.basename(
|
|
42773
|
+
this._scriptPath,
|
|
42774
|
+
path19.extname(this._scriptPath)
|
|
42775
|
+
);
|
|
42776
|
+
if (legacyName !== this._name) {
|
|
42777
|
+
localFile = findFile(
|
|
42778
|
+
executableDir,
|
|
42779
|
+
`${legacyName}-${subcommand._name}`
|
|
42780
|
+
);
|
|
42781
|
+
}
|
|
42782
|
+
}
|
|
42783
|
+
executableFile = localFile || executableFile;
|
|
42784
|
+
}
|
|
42785
|
+
launchWithNode = sourceExt.includes(path19.extname(executableFile));
|
|
42786
|
+
let proc;
|
|
42787
|
+
if (process4.platform !== "win32") {
|
|
42788
|
+
if (launchWithNode) {
|
|
42789
|
+
args.unshift(executableFile);
|
|
42790
|
+
args = incrementNodeInspectorPort(process4.execArgv).concat(args);
|
|
42791
|
+
proc = childProcess.spawn(process4.argv[0], args, { stdio: "inherit" });
|
|
42792
|
+
} else {
|
|
42793
|
+
proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
|
|
42794
|
+
}
|
|
42795
|
+
} else {
|
|
42796
|
+
this._checkForMissingExecutable(
|
|
42797
|
+
executableFile,
|
|
42798
|
+
executableDir,
|
|
42799
|
+
subcommand._name
|
|
42800
|
+
);
|
|
42801
|
+
args.unshift(executableFile);
|
|
42802
|
+
args = incrementNodeInspectorPort(process4.execArgv).concat(args);
|
|
42803
|
+
proc = childProcess.spawn(process4.execPath, args, { stdio: "inherit" });
|
|
42804
|
+
}
|
|
42805
|
+
if (!proc.killed) {
|
|
42806
|
+
const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
|
|
42807
|
+
signals.forEach((signal) => {
|
|
42808
|
+
process4.on(signal, () => {
|
|
42809
|
+
if (proc.killed === false && proc.exitCode === null) {
|
|
42810
|
+
proc.kill(signal);
|
|
42811
|
+
}
|
|
42812
|
+
});
|
|
42813
|
+
});
|
|
42814
|
+
}
|
|
42815
|
+
const exitCallback = this._exitCallback;
|
|
42816
|
+
proc.on("close", (code) => {
|
|
42817
|
+
code = code ?? 1;
|
|
42818
|
+
if (!exitCallback) {
|
|
42819
|
+
process4.exit(code);
|
|
42820
|
+
} else {
|
|
42821
|
+
exitCallback(
|
|
42822
|
+
new CommanderError2(
|
|
42823
|
+
code,
|
|
42824
|
+
"commander.executeSubCommandAsync",
|
|
42825
|
+
"(close)"
|
|
42826
|
+
)
|
|
42827
|
+
);
|
|
42828
|
+
}
|
|
42829
|
+
});
|
|
42830
|
+
proc.on("error", (err) => {
|
|
42831
|
+
if (err.code === "ENOENT") {
|
|
42832
|
+
this._checkForMissingExecutable(
|
|
42833
|
+
executableFile,
|
|
42834
|
+
executableDir,
|
|
42835
|
+
subcommand._name
|
|
42836
|
+
);
|
|
42837
|
+
} else if (err.code === "EACCES") {
|
|
42838
|
+
throw new Error(`'${executableFile}' not executable`);
|
|
42839
|
+
}
|
|
42840
|
+
if (!exitCallback) {
|
|
42841
|
+
process4.exit(1);
|
|
42842
|
+
} else {
|
|
42843
|
+
const wrappedError = new CommanderError2(
|
|
42844
|
+
1,
|
|
42845
|
+
"commander.executeSubCommandAsync",
|
|
42846
|
+
"(error)"
|
|
42847
|
+
);
|
|
42848
|
+
wrappedError.nestedError = err;
|
|
42849
|
+
exitCallback(wrappedError);
|
|
42850
|
+
}
|
|
42851
|
+
});
|
|
42852
|
+
this.runningCommand = proc;
|
|
42853
|
+
}
|
|
42854
|
+
/**
|
|
42855
|
+
* @private
|
|
42856
|
+
*/
|
|
42857
|
+
_dispatchSubcommand(commandName, operands, unknown2) {
|
|
42858
|
+
const subCommand = this._findCommand(commandName);
|
|
42859
|
+
if (!subCommand) this.help({ error: true });
|
|
42860
|
+
subCommand._prepareForParse();
|
|
42861
|
+
let promiseChain;
|
|
42862
|
+
promiseChain = this._chainOrCallSubCommandHook(
|
|
42863
|
+
promiseChain,
|
|
42864
|
+
subCommand,
|
|
42865
|
+
"preSubcommand"
|
|
42866
|
+
);
|
|
42867
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
42868
|
+
if (subCommand._executableHandler) {
|
|
42869
|
+
this._executeSubCommand(subCommand, operands.concat(unknown2));
|
|
42870
|
+
} else {
|
|
42871
|
+
return subCommand._parseCommand(operands, unknown2);
|
|
42872
|
+
}
|
|
42873
|
+
});
|
|
42874
|
+
return promiseChain;
|
|
42875
|
+
}
|
|
42876
|
+
/**
|
|
42877
|
+
* Invoke help directly if possible, or dispatch if necessary.
|
|
42878
|
+
* e.g. help foo
|
|
42879
|
+
*
|
|
42880
|
+
* @private
|
|
42881
|
+
*/
|
|
42882
|
+
_dispatchHelpCommand(subcommandName) {
|
|
42883
|
+
if (!subcommandName) {
|
|
42884
|
+
this.help();
|
|
42885
|
+
}
|
|
42886
|
+
const subCommand = this._findCommand(subcommandName);
|
|
42887
|
+
if (subCommand && !subCommand._executableHandler) {
|
|
42888
|
+
subCommand.help();
|
|
42889
|
+
}
|
|
42890
|
+
return this._dispatchSubcommand(
|
|
42891
|
+
subcommandName,
|
|
42892
|
+
[],
|
|
42893
|
+
[this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? "--help"]
|
|
42894
|
+
);
|
|
42895
|
+
}
|
|
42896
|
+
/**
|
|
42897
|
+
* Check this.args against expected this.registeredArguments.
|
|
42898
|
+
*
|
|
42899
|
+
* @private
|
|
42900
|
+
*/
|
|
42901
|
+
_checkNumberOfArguments() {
|
|
42902
|
+
this.registeredArguments.forEach((arg, i) => {
|
|
42903
|
+
if (arg.required && this.args[i] == null) {
|
|
42904
|
+
this.missingArgument(arg.name());
|
|
42905
|
+
}
|
|
42906
|
+
});
|
|
42907
|
+
if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) {
|
|
42908
|
+
return;
|
|
42909
|
+
}
|
|
42910
|
+
if (this.args.length > this.registeredArguments.length) {
|
|
42911
|
+
this._excessArguments(this.args);
|
|
42912
|
+
}
|
|
42913
|
+
}
|
|
42914
|
+
/**
|
|
42915
|
+
* Process this.args using this.registeredArguments and save as this.processedArgs!
|
|
42916
|
+
*
|
|
42917
|
+
* @private
|
|
42918
|
+
*/
|
|
42919
|
+
_processArguments() {
|
|
42920
|
+
const myParseArg = (argument, value, previous) => {
|
|
42921
|
+
let parsedValue = value;
|
|
42922
|
+
if (value !== null && argument.parseArg) {
|
|
42923
|
+
const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
|
|
42924
|
+
parsedValue = this._callParseArg(
|
|
42925
|
+
argument,
|
|
42926
|
+
value,
|
|
42927
|
+
previous,
|
|
42928
|
+
invalidValueMessage
|
|
42929
|
+
);
|
|
42930
|
+
}
|
|
42931
|
+
return parsedValue;
|
|
42932
|
+
};
|
|
42933
|
+
this._checkNumberOfArguments();
|
|
42934
|
+
const processedArgs = [];
|
|
42935
|
+
this.registeredArguments.forEach((declaredArg, index) => {
|
|
42936
|
+
let value = declaredArg.defaultValue;
|
|
42937
|
+
if (declaredArg.variadic) {
|
|
42938
|
+
if (index < this.args.length) {
|
|
42939
|
+
value = this.args.slice(index);
|
|
42940
|
+
if (declaredArg.parseArg) {
|
|
42941
|
+
value = value.reduce((processed, v) => {
|
|
42942
|
+
return myParseArg(declaredArg, v, processed);
|
|
42943
|
+
}, declaredArg.defaultValue);
|
|
42944
|
+
}
|
|
42945
|
+
} else if (value === void 0) {
|
|
42946
|
+
value = [];
|
|
42947
|
+
}
|
|
42948
|
+
} else if (index < this.args.length) {
|
|
42949
|
+
value = this.args[index];
|
|
42950
|
+
if (declaredArg.parseArg) {
|
|
42951
|
+
value = myParseArg(declaredArg, value, declaredArg.defaultValue);
|
|
42952
|
+
}
|
|
42953
|
+
}
|
|
42954
|
+
processedArgs[index] = value;
|
|
42955
|
+
});
|
|
42956
|
+
this.processedArgs = processedArgs;
|
|
42957
|
+
}
|
|
42958
|
+
/**
|
|
42959
|
+
* Once we have a promise we chain, but call synchronously until then.
|
|
42960
|
+
*
|
|
42961
|
+
* @param {(Promise|undefined)} promise
|
|
42962
|
+
* @param {Function} fn
|
|
42963
|
+
* @return {(Promise|undefined)}
|
|
42964
|
+
* @private
|
|
42965
|
+
*/
|
|
42966
|
+
_chainOrCall(promise3, fn) {
|
|
42967
|
+
if (promise3?.then && typeof promise3.then === "function") {
|
|
42968
|
+
return promise3.then(() => fn());
|
|
42969
|
+
}
|
|
42970
|
+
return fn();
|
|
42971
|
+
}
|
|
42972
|
+
/**
|
|
42973
|
+
*
|
|
42974
|
+
* @param {(Promise|undefined)} promise
|
|
42975
|
+
* @param {string} event
|
|
42976
|
+
* @return {(Promise|undefined)}
|
|
42977
|
+
* @private
|
|
42978
|
+
*/
|
|
42979
|
+
_chainOrCallHooks(promise3, event) {
|
|
42980
|
+
let result = promise3;
|
|
42981
|
+
const hooks = [];
|
|
42982
|
+
this._getCommandAndAncestors().reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== void 0).forEach((hookedCommand) => {
|
|
42983
|
+
hookedCommand._lifeCycleHooks[event].forEach((callback2) => {
|
|
42984
|
+
hooks.push({ hookedCommand, callback: callback2 });
|
|
42985
|
+
});
|
|
42986
|
+
});
|
|
42987
|
+
if (event === "postAction") {
|
|
42988
|
+
hooks.reverse();
|
|
42989
|
+
}
|
|
42990
|
+
hooks.forEach((hookDetail) => {
|
|
42991
|
+
result = this._chainOrCall(result, () => {
|
|
42992
|
+
return hookDetail.callback(hookDetail.hookedCommand, this);
|
|
42993
|
+
});
|
|
42994
|
+
});
|
|
42995
|
+
return result;
|
|
42996
|
+
}
|
|
42997
|
+
/**
|
|
42998
|
+
*
|
|
42999
|
+
* @param {(Promise|undefined)} promise
|
|
43000
|
+
* @param {Command} subCommand
|
|
43001
|
+
* @param {string} event
|
|
43002
|
+
* @return {(Promise|undefined)}
|
|
43003
|
+
* @private
|
|
43004
|
+
*/
|
|
43005
|
+
_chainOrCallSubCommandHook(promise3, subCommand, event) {
|
|
43006
|
+
let result = promise3;
|
|
43007
|
+
if (this._lifeCycleHooks[event] !== void 0) {
|
|
43008
|
+
this._lifeCycleHooks[event].forEach((hook) => {
|
|
43009
|
+
result = this._chainOrCall(result, () => {
|
|
43010
|
+
return hook(this, subCommand);
|
|
43011
|
+
});
|
|
43012
|
+
});
|
|
43013
|
+
}
|
|
43014
|
+
return result;
|
|
43015
|
+
}
|
|
43016
|
+
/**
|
|
43017
|
+
* Process arguments in context of this command.
|
|
43018
|
+
* Returns action result, in case it is a promise.
|
|
43019
|
+
*
|
|
43020
|
+
* @private
|
|
43021
|
+
*/
|
|
43022
|
+
_parseCommand(operands, unknown2) {
|
|
43023
|
+
const parsed = this.parseOptions(unknown2);
|
|
43024
|
+
this._parseOptionsEnv();
|
|
43025
|
+
this._parseOptionsImplied();
|
|
43026
|
+
operands = operands.concat(parsed.operands);
|
|
43027
|
+
unknown2 = parsed.unknown;
|
|
43028
|
+
this.args = operands.concat(unknown2);
|
|
43029
|
+
if (operands && this._findCommand(operands[0])) {
|
|
43030
|
+
return this._dispatchSubcommand(operands[0], operands.slice(1), unknown2);
|
|
43031
|
+
}
|
|
43032
|
+
if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name()) {
|
|
43033
|
+
return this._dispatchHelpCommand(operands[1]);
|
|
43034
|
+
}
|
|
43035
|
+
if (this._defaultCommandName) {
|
|
43036
|
+
this._outputHelpIfRequested(unknown2);
|
|
43037
|
+
return this._dispatchSubcommand(
|
|
43038
|
+
this._defaultCommandName,
|
|
43039
|
+
operands,
|
|
43040
|
+
unknown2
|
|
43041
|
+
);
|
|
43042
|
+
}
|
|
43043
|
+
if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
|
|
43044
|
+
this.help({ error: true });
|
|
43045
|
+
}
|
|
43046
|
+
this._outputHelpIfRequested(parsed.unknown);
|
|
43047
|
+
this._checkForMissingMandatoryOptions();
|
|
43048
|
+
this._checkForConflictingOptions();
|
|
43049
|
+
const checkForUnknownOptions = () => {
|
|
43050
|
+
if (parsed.unknown.length > 0) {
|
|
43051
|
+
this.unknownOption(parsed.unknown[0]);
|
|
43052
|
+
}
|
|
43053
|
+
};
|
|
43054
|
+
const commandEvent = `command:${this.name()}`;
|
|
43055
|
+
if (this._actionHandler) {
|
|
43056
|
+
checkForUnknownOptions();
|
|
43057
|
+
this._processArguments();
|
|
43058
|
+
let promiseChain;
|
|
43059
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
|
|
43060
|
+
promiseChain = this._chainOrCall(
|
|
43061
|
+
promiseChain,
|
|
43062
|
+
() => this._actionHandler(this.processedArgs)
|
|
43063
|
+
);
|
|
43064
|
+
if (this.parent) {
|
|
43065
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
43066
|
+
this.parent.emit(commandEvent, operands, unknown2);
|
|
43067
|
+
});
|
|
43068
|
+
}
|
|
43069
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
|
|
43070
|
+
return promiseChain;
|
|
43071
|
+
}
|
|
43072
|
+
if (this.parent?.listenerCount(commandEvent)) {
|
|
43073
|
+
checkForUnknownOptions();
|
|
43074
|
+
this._processArguments();
|
|
43075
|
+
this.parent.emit(commandEvent, operands, unknown2);
|
|
43076
|
+
} else if (operands.length) {
|
|
43077
|
+
if (this._findCommand("*")) {
|
|
43078
|
+
return this._dispatchSubcommand("*", operands, unknown2);
|
|
43079
|
+
}
|
|
43080
|
+
if (this.listenerCount("command:*")) {
|
|
43081
|
+
this.emit("command:*", operands, unknown2);
|
|
43082
|
+
} else if (this.commands.length) {
|
|
43083
|
+
this.unknownCommand();
|
|
43084
|
+
} else {
|
|
43085
|
+
checkForUnknownOptions();
|
|
43086
|
+
this._processArguments();
|
|
43087
|
+
}
|
|
43088
|
+
} else if (this.commands.length) {
|
|
43089
|
+
checkForUnknownOptions();
|
|
43090
|
+
this.help({ error: true });
|
|
43091
|
+
} else {
|
|
43092
|
+
checkForUnknownOptions();
|
|
43093
|
+
this._processArguments();
|
|
43094
|
+
}
|
|
43095
|
+
}
|
|
43096
|
+
/**
|
|
43097
|
+
* Find matching command.
|
|
43098
|
+
*
|
|
43099
|
+
* @private
|
|
43100
|
+
* @return {Command | undefined}
|
|
43101
|
+
*/
|
|
43102
|
+
_findCommand(name) {
|
|
43103
|
+
if (!name) return void 0;
|
|
43104
|
+
return this.commands.find(
|
|
43105
|
+
(cmd) => cmd._name === name || cmd._aliases.includes(name)
|
|
43106
|
+
);
|
|
43107
|
+
}
|
|
43108
|
+
/**
|
|
43109
|
+
* Return an option matching `arg` if any.
|
|
43110
|
+
*
|
|
43111
|
+
* @param {string} arg
|
|
43112
|
+
* @return {Option}
|
|
43113
|
+
* @package
|
|
43114
|
+
*/
|
|
43115
|
+
_findOption(arg) {
|
|
43116
|
+
return this.options.find((option) => option.is(arg));
|
|
43117
|
+
}
|
|
43118
|
+
/**
|
|
43119
|
+
* Display an error message if a mandatory option does not have a value.
|
|
43120
|
+
* Called after checking for help flags in leaf subcommand.
|
|
43121
|
+
*
|
|
43122
|
+
* @private
|
|
43123
|
+
*/
|
|
43124
|
+
_checkForMissingMandatoryOptions() {
|
|
43125
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
43126
|
+
cmd.options.forEach((anOption) => {
|
|
43127
|
+
if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === void 0) {
|
|
43128
|
+
cmd.missingMandatoryOptionValue(anOption);
|
|
43129
|
+
}
|
|
43130
|
+
});
|
|
43131
|
+
});
|
|
43132
|
+
}
|
|
43133
|
+
/**
|
|
43134
|
+
* Display an error message if conflicting options are used together in this.
|
|
43135
|
+
*
|
|
43136
|
+
* @private
|
|
43137
|
+
*/
|
|
43138
|
+
_checkForConflictingLocalOptions() {
|
|
43139
|
+
const definedNonDefaultOptions = this.options.filter((option) => {
|
|
43140
|
+
const optionKey = option.attributeName();
|
|
43141
|
+
if (this.getOptionValue(optionKey) === void 0) {
|
|
43142
|
+
return false;
|
|
43143
|
+
}
|
|
43144
|
+
return this.getOptionValueSource(optionKey) !== "default";
|
|
43145
|
+
});
|
|
43146
|
+
const optionsWithConflicting = definedNonDefaultOptions.filter(
|
|
43147
|
+
(option) => option.conflictsWith.length > 0
|
|
43148
|
+
);
|
|
43149
|
+
optionsWithConflicting.forEach((option) => {
|
|
43150
|
+
const conflictingAndDefined = definedNonDefaultOptions.find(
|
|
43151
|
+
(defined) => option.conflictsWith.includes(defined.attributeName())
|
|
43152
|
+
);
|
|
43153
|
+
if (conflictingAndDefined) {
|
|
43154
|
+
this._conflictingOption(option, conflictingAndDefined);
|
|
43155
|
+
}
|
|
43156
|
+
});
|
|
43157
|
+
}
|
|
43158
|
+
/**
|
|
43159
|
+
* Display an error message if conflicting options are used together.
|
|
43160
|
+
* Called after checking for help flags in leaf subcommand.
|
|
43161
|
+
*
|
|
43162
|
+
* @private
|
|
43163
|
+
*/
|
|
43164
|
+
_checkForConflictingOptions() {
|
|
43165
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
43166
|
+
cmd._checkForConflictingLocalOptions();
|
|
43167
|
+
});
|
|
43168
|
+
}
|
|
43169
|
+
/**
|
|
43170
|
+
* Parse options from `argv` removing known options,
|
|
43171
|
+
* and return argv split into operands and unknown arguments.
|
|
43172
|
+
*
|
|
43173
|
+
* Side effects: modifies command by storing options. Does not reset state if called again.
|
|
43174
|
+
*
|
|
43175
|
+
* Examples:
|
|
43176
|
+
*
|
|
43177
|
+
* argv => operands, unknown
|
|
43178
|
+
* --known kkk op => [op], []
|
|
43179
|
+
* op --known kkk => [op], []
|
|
43180
|
+
* sub --unknown uuu op => [sub], [--unknown uuu op]
|
|
43181
|
+
* sub -- --unknown uuu op => [sub --unknown uuu op], []
|
|
43182
|
+
*
|
|
43183
|
+
* @param {string[]} args
|
|
43184
|
+
* @return {{operands: string[], unknown: string[]}}
|
|
43185
|
+
*/
|
|
43186
|
+
parseOptions(args) {
|
|
43187
|
+
const operands = [];
|
|
43188
|
+
const unknown2 = [];
|
|
43189
|
+
let dest = operands;
|
|
43190
|
+
function maybeOption(arg) {
|
|
43191
|
+
return arg.length > 1 && arg[0] === "-";
|
|
43192
|
+
}
|
|
43193
|
+
const negativeNumberArg = (arg) => {
|
|
43194
|
+
if (!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(arg)) return false;
|
|
43195
|
+
return !this._getCommandAndAncestors().some(
|
|
43196
|
+
(cmd) => cmd.options.map((opt) => opt.short).some((short) => /^-\d$/.test(short))
|
|
43197
|
+
);
|
|
43198
|
+
};
|
|
43199
|
+
let activeVariadicOption = null;
|
|
43200
|
+
let activeGroup = null;
|
|
43201
|
+
let i = 0;
|
|
43202
|
+
while (i < args.length || activeGroup) {
|
|
43203
|
+
const arg = activeGroup ?? args[i++];
|
|
43204
|
+
activeGroup = null;
|
|
43205
|
+
if (arg === "--") {
|
|
43206
|
+
if (dest === unknown2) dest.push(arg);
|
|
43207
|
+
dest.push(...args.slice(i));
|
|
43208
|
+
break;
|
|
43209
|
+
}
|
|
43210
|
+
if (activeVariadicOption && (!maybeOption(arg) || negativeNumberArg(arg))) {
|
|
43211
|
+
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
43212
|
+
continue;
|
|
43213
|
+
}
|
|
43214
|
+
activeVariadicOption = null;
|
|
43215
|
+
if (maybeOption(arg)) {
|
|
43216
|
+
const option = this._findOption(arg);
|
|
43217
|
+
if (option) {
|
|
43218
|
+
if (option.required) {
|
|
43219
|
+
const value = args[i++];
|
|
43220
|
+
if (value === void 0) this.optionMissingArgument(option);
|
|
43221
|
+
this.emit(`option:${option.name()}`, value);
|
|
43222
|
+
} else if (option.optional) {
|
|
43223
|
+
let value = null;
|
|
43224
|
+
if (i < args.length && (!maybeOption(args[i]) || negativeNumberArg(args[i]))) {
|
|
43225
|
+
value = args[i++];
|
|
43226
|
+
}
|
|
43227
|
+
this.emit(`option:${option.name()}`, value);
|
|
43228
|
+
} else {
|
|
43229
|
+
this.emit(`option:${option.name()}`);
|
|
43230
|
+
}
|
|
43231
|
+
activeVariadicOption = option.variadic ? option : null;
|
|
43232
|
+
continue;
|
|
43233
|
+
}
|
|
43234
|
+
}
|
|
43235
|
+
if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
|
|
43236
|
+
const option = this._findOption(`-${arg[1]}`);
|
|
43237
|
+
if (option) {
|
|
43238
|
+
if (option.required || option.optional && this._combineFlagAndOptionalValue) {
|
|
43239
|
+
this.emit(`option:${option.name()}`, arg.slice(2));
|
|
43240
|
+
} else {
|
|
43241
|
+
this.emit(`option:${option.name()}`);
|
|
43242
|
+
activeGroup = `-${arg.slice(2)}`;
|
|
43243
|
+
}
|
|
43244
|
+
continue;
|
|
43245
|
+
}
|
|
43246
|
+
}
|
|
43247
|
+
if (/^--[^=]+=/.test(arg)) {
|
|
43248
|
+
const index = arg.indexOf("=");
|
|
43249
|
+
const option = this._findOption(arg.slice(0, index));
|
|
43250
|
+
if (option && (option.required || option.optional)) {
|
|
43251
|
+
this.emit(`option:${option.name()}`, arg.slice(index + 1));
|
|
43252
|
+
continue;
|
|
43253
|
+
}
|
|
43254
|
+
}
|
|
43255
|
+
if (dest === operands && maybeOption(arg) && !(this.commands.length === 0 && negativeNumberArg(arg))) {
|
|
43256
|
+
dest = unknown2;
|
|
43257
|
+
}
|
|
43258
|
+
if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown2.length === 0) {
|
|
43259
|
+
if (this._findCommand(arg)) {
|
|
43260
|
+
operands.push(arg);
|
|
43261
|
+
unknown2.push(...args.slice(i));
|
|
43262
|
+
break;
|
|
43263
|
+
} else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
|
|
43264
|
+
operands.push(arg, ...args.slice(i));
|
|
43265
|
+
break;
|
|
43266
|
+
} else if (this._defaultCommandName) {
|
|
43267
|
+
unknown2.push(arg, ...args.slice(i));
|
|
43268
|
+
break;
|
|
43269
|
+
}
|
|
43270
|
+
}
|
|
43271
|
+
if (this._passThroughOptions) {
|
|
43272
|
+
dest.push(arg, ...args.slice(i));
|
|
43273
|
+
break;
|
|
43274
|
+
}
|
|
43275
|
+
dest.push(arg);
|
|
43276
|
+
}
|
|
43277
|
+
return { operands, unknown: unknown2 };
|
|
43278
|
+
}
|
|
43279
|
+
/**
|
|
43280
|
+
* Return an object containing local option values as key-value pairs.
|
|
43281
|
+
*
|
|
43282
|
+
* @return {object}
|
|
43283
|
+
*/
|
|
43284
|
+
opts() {
|
|
43285
|
+
if (this._storeOptionsAsProperties) {
|
|
43286
|
+
const result = {};
|
|
43287
|
+
const len = this.options.length;
|
|
43288
|
+
for (let i = 0; i < len; i++) {
|
|
43289
|
+
const key = this.options[i].attributeName();
|
|
43290
|
+
result[key] = key === this._versionOptionName ? this._version : this[key];
|
|
43291
|
+
}
|
|
43292
|
+
return result;
|
|
43293
|
+
}
|
|
43294
|
+
return this._optionValues;
|
|
43295
|
+
}
|
|
43296
|
+
/**
|
|
43297
|
+
* Return an object containing merged local and global option values as key-value pairs.
|
|
43298
|
+
*
|
|
43299
|
+
* @return {object}
|
|
43300
|
+
*/
|
|
43301
|
+
optsWithGlobals() {
|
|
43302
|
+
return this._getCommandAndAncestors().reduce(
|
|
43303
|
+
(combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()),
|
|
43304
|
+
{}
|
|
43305
|
+
);
|
|
43306
|
+
}
|
|
43307
|
+
/**
|
|
43308
|
+
* Display error message and exit (or call exitOverride).
|
|
43309
|
+
*
|
|
43310
|
+
* @param {string} message
|
|
43311
|
+
* @param {object} [errorOptions]
|
|
43312
|
+
* @param {string} [errorOptions.code] - an id string representing the error
|
|
43313
|
+
* @param {number} [errorOptions.exitCode] - used with process.exit
|
|
43314
|
+
*/
|
|
43315
|
+
error(message, errorOptions) {
|
|
43316
|
+
this._outputConfiguration.outputError(
|
|
43317
|
+
`${message}
|
|
43318
|
+
`,
|
|
43319
|
+
this._outputConfiguration.writeErr
|
|
43320
|
+
);
|
|
43321
|
+
if (typeof this._showHelpAfterError === "string") {
|
|
43322
|
+
this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
43323
|
+
`);
|
|
43324
|
+
} else if (this._showHelpAfterError) {
|
|
43325
|
+
this._outputConfiguration.writeErr("\n");
|
|
43326
|
+
this.outputHelp({ error: true });
|
|
43327
|
+
}
|
|
43328
|
+
const config2 = errorOptions || {};
|
|
43329
|
+
const exitCode3 = config2.exitCode || 1;
|
|
43330
|
+
const code = config2.code || "commander.error";
|
|
43331
|
+
this._exit(exitCode3, code, message);
|
|
43332
|
+
}
|
|
43333
|
+
/**
|
|
43334
|
+
* Apply any option related environment variables, if option does
|
|
43335
|
+
* not have a value from cli or client code.
|
|
43336
|
+
*
|
|
43337
|
+
* @private
|
|
43338
|
+
*/
|
|
43339
|
+
_parseOptionsEnv() {
|
|
43340
|
+
this.options.forEach((option) => {
|
|
43341
|
+
if (option.envVar && option.envVar in process4.env) {
|
|
43342
|
+
const optionKey = option.attributeName();
|
|
43343
|
+
if (this.getOptionValue(optionKey) === void 0 || ["default", "config", "env"].includes(
|
|
43344
|
+
this.getOptionValueSource(optionKey)
|
|
43345
|
+
)) {
|
|
43346
|
+
if (option.required || option.optional) {
|
|
43347
|
+
this.emit(`optionEnv:${option.name()}`, process4.env[option.envVar]);
|
|
43348
|
+
} else {
|
|
43349
|
+
this.emit(`optionEnv:${option.name()}`);
|
|
43350
|
+
}
|
|
43351
|
+
}
|
|
43352
|
+
}
|
|
43353
|
+
});
|
|
43354
|
+
}
|
|
43355
|
+
/**
|
|
43356
|
+
* Apply any implied option values, if option is undefined or default value.
|
|
43357
|
+
*
|
|
43358
|
+
* @private
|
|
43359
|
+
*/
|
|
43360
|
+
_parseOptionsImplied() {
|
|
43361
|
+
const dualHelper = new DualOptions(this.options);
|
|
43362
|
+
const hasCustomOptionValue = (optionKey) => {
|
|
43363
|
+
return this.getOptionValue(optionKey) !== void 0 && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
|
|
43364
|
+
};
|
|
43365
|
+
this.options.filter(
|
|
43366
|
+
(option) => option.implied !== void 0 && hasCustomOptionValue(option.attributeName()) && dualHelper.valueFromOption(
|
|
43367
|
+
this.getOptionValue(option.attributeName()),
|
|
43368
|
+
option
|
|
43369
|
+
)
|
|
43370
|
+
).forEach((option) => {
|
|
43371
|
+
Object.keys(option.implied).filter((impliedKey) => !hasCustomOptionValue(impliedKey)).forEach((impliedKey) => {
|
|
43372
|
+
this.setOptionValueWithSource(
|
|
43373
|
+
impliedKey,
|
|
43374
|
+
option.implied[impliedKey],
|
|
43375
|
+
"implied"
|
|
43376
|
+
);
|
|
43377
|
+
});
|
|
43378
|
+
});
|
|
43379
|
+
}
|
|
43380
|
+
/**
|
|
43381
|
+
* Argument `name` is missing.
|
|
43382
|
+
*
|
|
43383
|
+
* @param {string} name
|
|
43384
|
+
* @private
|
|
43385
|
+
*/
|
|
43386
|
+
missingArgument(name) {
|
|
43387
|
+
const message = `error: missing required argument '${name}'`;
|
|
43388
|
+
this.error(message, { code: "commander.missingArgument" });
|
|
43389
|
+
}
|
|
43390
|
+
/**
|
|
43391
|
+
* `Option` is missing an argument.
|
|
43392
|
+
*
|
|
43393
|
+
* @param {Option} option
|
|
43394
|
+
* @private
|
|
43395
|
+
*/
|
|
43396
|
+
optionMissingArgument(option) {
|
|
43397
|
+
const message = `error: option '${option.flags}' argument missing`;
|
|
43398
|
+
this.error(message, { code: "commander.optionMissingArgument" });
|
|
43399
|
+
}
|
|
43400
|
+
/**
|
|
43401
|
+
* `Option` does not have a value, and is a mandatory option.
|
|
43402
|
+
*
|
|
43403
|
+
* @param {Option} option
|
|
43404
|
+
* @private
|
|
43405
|
+
*/
|
|
43406
|
+
missingMandatoryOptionValue(option) {
|
|
43407
|
+
const message = `error: required option '${option.flags}' not specified`;
|
|
43408
|
+
this.error(message, { code: "commander.missingMandatoryOptionValue" });
|
|
43409
|
+
}
|
|
43410
|
+
/**
|
|
43411
|
+
* `Option` conflicts with another option.
|
|
43412
|
+
*
|
|
43413
|
+
* @param {Option} option
|
|
43414
|
+
* @param {Option} conflictingOption
|
|
43415
|
+
* @private
|
|
43416
|
+
*/
|
|
43417
|
+
_conflictingOption(option, conflictingOption) {
|
|
43418
|
+
const findBestOptionFromValue = (option2) => {
|
|
43419
|
+
const optionKey = option2.attributeName();
|
|
43420
|
+
const optionValue = this.getOptionValue(optionKey);
|
|
43421
|
+
const negativeOption = this.options.find(
|
|
43422
|
+
(target) => target.negate && optionKey === target.attributeName()
|
|
43423
|
+
);
|
|
43424
|
+
const positiveOption = this.options.find(
|
|
43425
|
+
(target) => !target.negate && optionKey === target.attributeName()
|
|
43426
|
+
);
|
|
43427
|
+
if (negativeOption && (negativeOption.presetArg === void 0 && optionValue === false || negativeOption.presetArg !== void 0 && optionValue === negativeOption.presetArg)) {
|
|
43428
|
+
return negativeOption;
|
|
43429
|
+
}
|
|
43430
|
+
return positiveOption || option2;
|
|
43431
|
+
};
|
|
43432
|
+
const getErrorMessage = (option2) => {
|
|
43433
|
+
const bestOption = findBestOptionFromValue(option2);
|
|
43434
|
+
const optionKey = bestOption.attributeName();
|
|
43435
|
+
const source = this.getOptionValueSource(optionKey);
|
|
43436
|
+
if (source === "env") {
|
|
43437
|
+
return `environment variable '${bestOption.envVar}'`;
|
|
43438
|
+
}
|
|
43439
|
+
return `option '${bestOption.flags}'`;
|
|
43440
|
+
};
|
|
43441
|
+
const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
|
|
43442
|
+
this.error(message, { code: "commander.conflictingOption" });
|
|
43443
|
+
}
|
|
43444
|
+
/**
|
|
43445
|
+
* Unknown option `flag`.
|
|
43446
|
+
*
|
|
43447
|
+
* @param {string} flag
|
|
43448
|
+
* @private
|
|
43449
|
+
*/
|
|
43450
|
+
unknownOption(flag) {
|
|
43451
|
+
if (this._allowUnknownOption) return;
|
|
43452
|
+
let suggestion = "";
|
|
43453
|
+
if (flag.startsWith("--") && this._showSuggestionAfterError) {
|
|
43454
|
+
let candidateFlags = [];
|
|
43455
|
+
let command = this;
|
|
43456
|
+
do {
|
|
43457
|
+
const moreFlags = command.createHelp().visibleOptions(command).filter((option) => option.long).map((option) => option.long);
|
|
43458
|
+
candidateFlags = candidateFlags.concat(moreFlags);
|
|
43459
|
+
command = command.parent;
|
|
43460
|
+
} while (command && !command._enablePositionalOptions);
|
|
43461
|
+
suggestion = suggestSimilar(flag, candidateFlags);
|
|
43462
|
+
}
|
|
43463
|
+
const message = `error: unknown option '${flag}'${suggestion}`;
|
|
43464
|
+
this.error(message, { code: "commander.unknownOption" });
|
|
43465
|
+
}
|
|
43466
|
+
/**
|
|
43467
|
+
* Excess arguments, more than expected.
|
|
43468
|
+
*
|
|
43469
|
+
* @param {string[]} receivedArgs
|
|
43470
|
+
* @private
|
|
43471
|
+
*/
|
|
43472
|
+
_excessArguments(receivedArgs) {
|
|
43473
|
+
if (this._allowExcessArguments) return;
|
|
43474
|
+
const expected = this.registeredArguments.length;
|
|
43475
|
+
const s = expected === 1 ? "" : "s";
|
|
43476
|
+
const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
|
|
43477
|
+
const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
|
|
43478
|
+
this.error(message, { code: "commander.excessArguments" });
|
|
43479
|
+
}
|
|
43480
|
+
/**
|
|
43481
|
+
* Unknown command.
|
|
43482
|
+
*
|
|
43483
|
+
* @private
|
|
43484
|
+
*/
|
|
43485
|
+
unknownCommand() {
|
|
43486
|
+
const unknownName = this.args[0];
|
|
43487
|
+
let suggestion = "";
|
|
43488
|
+
if (this._showSuggestionAfterError) {
|
|
43489
|
+
const candidateNames = [];
|
|
43490
|
+
this.createHelp().visibleCommands(this).forEach((command) => {
|
|
43491
|
+
candidateNames.push(command.name());
|
|
43492
|
+
if (command.alias()) candidateNames.push(command.alias());
|
|
43493
|
+
});
|
|
43494
|
+
suggestion = suggestSimilar(unknownName, candidateNames);
|
|
43495
|
+
}
|
|
43496
|
+
const message = `error: unknown command '${unknownName}'${suggestion}`;
|
|
43497
|
+
this.error(message, { code: "commander.unknownCommand" });
|
|
43498
|
+
}
|
|
43499
|
+
/**
|
|
43500
|
+
* Get or set the program version.
|
|
43501
|
+
*
|
|
43502
|
+
* This method auto-registers the "-V, --version" option which will print the version number.
|
|
43503
|
+
*
|
|
43504
|
+
* You can optionally supply the flags and description to override the defaults.
|
|
43505
|
+
*
|
|
43506
|
+
* @param {string} [str]
|
|
43507
|
+
* @param {string} [flags]
|
|
43508
|
+
* @param {string} [description]
|
|
43509
|
+
* @return {(this | string | undefined)} `this` command for chaining, or version string if no arguments
|
|
43510
|
+
*/
|
|
43511
|
+
version(str3, flags, description) {
|
|
43512
|
+
if (str3 === void 0) return this._version;
|
|
43513
|
+
this._version = str3;
|
|
43514
|
+
flags = flags || "-V, --version";
|
|
43515
|
+
description = description || "output the version number";
|
|
43516
|
+
const versionOption = this.createOption(flags, description);
|
|
43517
|
+
this._versionOptionName = versionOption.attributeName();
|
|
43518
|
+
this._registerOption(versionOption);
|
|
43519
|
+
this.on("option:" + versionOption.name(), () => {
|
|
43520
|
+
this._outputConfiguration.writeOut(`${str3}
|
|
43521
|
+
`);
|
|
43522
|
+
this._exit(0, "commander.version", str3);
|
|
43523
|
+
});
|
|
43524
|
+
return this;
|
|
43525
|
+
}
|
|
43526
|
+
/**
|
|
43527
|
+
* Set the description.
|
|
43528
|
+
*
|
|
43529
|
+
* @param {string} [str]
|
|
43530
|
+
* @param {object} [argsDescription]
|
|
43531
|
+
* @return {(string|Command)}
|
|
43532
|
+
*/
|
|
43533
|
+
description(str3, argsDescription) {
|
|
43534
|
+
if (str3 === void 0 && argsDescription === void 0)
|
|
43535
|
+
return this._description;
|
|
43536
|
+
this._description = str3;
|
|
43537
|
+
if (argsDescription) {
|
|
43538
|
+
this._argsDescription = argsDescription;
|
|
43539
|
+
}
|
|
43540
|
+
return this;
|
|
43541
|
+
}
|
|
43542
|
+
/**
|
|
43543
|
+
* Set the summary. Used when listed as subcommand of parent.
|
|
43544
|
+
*
|
|
43545
|
+
* @param {string} [str]
|
|
43546
|
+
* @return {(string|Command)}
|
|
43547
|
+
*/
|
|
43548
|
+
summary(str3) {
|
|
43549
|
+
if (str3 === void 0) return this._summary;
|
|
43550
|
+
this._summary = str3;
|
|
43551
|
+
return this;
|
|
43552
|
+
}
|
|
43553
|
+
/**
|
|
43554
|
+
* Set an alias for the command.
|
|
43555
|
+
*
|
|
43556
|
+
* You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.
|
|
43557
|
+
*
|
|
43558
|
+
* @param {string} [alias]
|
|
43559
|
+
* @return {(string|Command)}
|
|
43560
|
+
*/
|
|
43561
|
+
alias(alias) {
|
|
43562
|
+
if (alias === void 0) return this._aliases[0];
|
|
43563
|
+
let command = this;
|
|
43564
|
+
if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
|
|
43565
|
+
command = this.commands[this.commands.length - 1];
|
|
43566
|
+
}
|
|
43567
|
+
if (alias === command._name)
|
|
43568
|
+
throw new Error("Command alias can't be the same as its name");
|
|
43569
|
+
const matchingCommand = this.parent?._findCommand(alias);
|
|
43570
|
+
if (matchingCommand) {
|
|
43571
|
+
const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join("|");
|
|
43572
|
+
throw new Error(
|
|
43573
|
+
`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`
|
|
43574
|
+
);
|
|
43575
|
+
}
|
|
43576
|
+
command._aliases.push(alias);
|
|
43577
|
+
return this;
|
|
43578
|
+
}
|
|
43579
|
+
/**
|
|
43580
|
+
* Set aliases for the command.
|
|
43581
|
+
*
|
|
43582
|
+
* Only the first alias is shown in the auto-generated help.
|
|
43583
|
+
*
|
|
43584
|
+
* @param {string[]} [aliases]
|
|
43585
|
+
* @return {(string[]|Command)}
|
|
43586
|
+
*/
|
|
43587
|
+
aliases(aliases) {
|
|
43588
|
+
if (aliases === void 0) return this._aliases;
|
|
43589
|
+
aliases.forEach((alias) => this.alias(alias));
|
|
43590
|
+
return this;
|
|
43591
|
+
}
|
|
43592
|
+
/**
|
|
43593
|
+
* Set / get the command usage `str`.
|
|
43594
|
+
*
|
|
43595
|
+
* @param {string} [str]
|
|
43596
|
+
* @return {(string|Command)}
|
|
43597
|
+
*/
|
|
43598
|
+
usage(str3) {
|
|
43599
|
+
if (str3 === void 0) {
|
|
43600
|
+
if (this._usage) return this._usage;
|
|
43601
|
+
const args = this.registeredArguments.map((arg) => {
|
|
43602
|
+
return humanReadableArgName(arg);
|
|
43603
|
+
});
|
|
43604
|
+
return [].concat(
|
|
43605
|
+
this.options.length || this._helpOption !== null ? "[options]" : [],
|
|
43606
|
+
this.commands.length ? "[command]" : [],
|
|
43607
|
+
this.registeredArguments.length ? args : []
|
|
43608
|
+
).join(" ");
|
|
43609
|
+
}
|
|
43610
|
+
this._usage = str3;
|
|
43611
|
+
return this;
|
|
43612
|
+
}
|
|
43613
|
+
/**
|
|
43614
|
+
* Get or set the name of the command.
|
|
43615
|
+
*
|
|
43616
|
+
* @param {string} [str]
|
|
43617
|
+
* @return {(string|Command)}
|
|
43618
|
+
*/
|
|
43619
|
+
name(str3) {
|
|
43620
|
+
if (str3 === void 0) return this._name;
|
|
43621
|
+
this._name = str3;
|
|
43622
|
+
return this;
|
|
43623
|
+
}
|
|
43624
|
+
/**
|
|
43625
|
+
* Set/get the help group heading for this subcommand in parent command's help.
|
|
43626
|
+
*
|
|
43627
|
+
* @param {string} [heading]
|
|
43628
|
+
* @return {Command | string}
|
|
43629
|
+
*/
|
|
43630
|
+
helpGroup(heading) {
|
|
43631
|
+
if (heading === void 0) return this._helpGroupHeading ?? "";
|
|
43632
|
+
this._helpGroupHeading = heading;
|
|
43633
|
+
return this;
|
|
43634
|
+
}
|
|
43635
|
+
/**
|
|
43636
|
+
* Set/get the default help group heading for subcommands added to this command.
|
|
43637
|
+
* (This does not override a group set directly on the subcommand using .helpGroup().)
|
|
43638
|
+
*
|
|
43639
|
+
* @example
|
|
43640
|
+
* program.commandsGroup('Development Commands:);
|
|
43641
|
+
* program.command('watch')...
|
|
43642
|
+
* program.command('lint')...
|
|
43643
|
+
* ...
|
|
43644
|
+
*
|
|
43645
|
+
* @param {string} [heading]
|
|
43646
|
+
* @returns {Command | string}
|
|
43647
|
+
*/
|
|
43648
|
+
commandsGroup(heading) {
|
|
43649
|
+
if (heading === void 0) return this._defaultCommandGroup ?? "";
|
|
43650
|
+
this._defaultCommandGroup = heading;
|
|
43651
|
+
return this;
|
|
43652
|
+
}
|
|
43653
|
+
/**
|
|
43654
|
+
* Set/get the default help group heading for options added to this command.
|
|
43655
|
+
* (This does not override a group set directly on the option using .helpGroup().)
|
|
43656
|
+
*
|
|
43657
|
+
* @example
|
|
43658
|
+
* program
|
|
43659
|
+
* .optionsGroup('Development Options:')
|
|
43660
|
+
* .option('-d, --debug', 'output extra debugging')
|
|
43661
|
+
* .option('-p, --profile', 'output profiling information')
|
|
43662
|
+
*
|
|
43663
|
+
* @param {string} [heading]
|
|
43664
|
+
* @returns {Command | string}
|
|
43665
|
+
*/
|
|
43666
|
+
optionsGroup(heading) {
|
|
43667
|
+
if (heading === void 0) return this._defaultOptionGroup ?? "";
|
|
43668
|
+
this._defaultOptionGroup = heading;
|
|
43669
|
+
return this;
|
|
43670
|
+
}
|
|
43671
|
+
/**
|
|
43672
|
+
* @param {Option} option
|
|
43673
|
+
* @private
|
|
43674
|
+
*/
|
|
43675
|
+
_initOptionGroup(option) {
|
|
43676
|
+
if (this._defaultOptionGroup && !option.helpGroupHeading)
|
|
43677
|
+
option.helpGroup(this._defaultOptionGroup);
|
|
43678
|
+
}
|
|
43679
|
+
/**
|
|
43680
|
+
* @param {Command} cmd
|
|
43681
|
+
* @private
|
|
43682
|
+
*/
|
|
43683
|
+
_initCommandGroup(cmd) {
|
|
43684
|
+
if (this._defaultCommandGroup && !cmd.helpGroup())
|
|
43685
|
+
cmd.helpGroup(this._defaultCommandGroup);
|
|
43686
|
+
}
|
|
43687
|
+
/**
|
|
43688
|
+
* Set the name of the command from script filename, such as process.argv[1],
|
|
43689
|
+
* or require.main.filename, or __filename.
|
|
43690
|
+
*
|
|
43691
|
+
* (Used internally and public although not documented in README.)
|
|
43692
|
+
*
|
|
43693
|
+
* @example
|
|
43694
|
+
* program.nameFromFilename(require.main.filename);
|
|
43695
|
+
*
|
|
43696
|
+
* @param {string} filename
|
|
43697
|
+
* @return {Command}
|
|
43698
|
+
*/
|
|
43699
|
+
nameFromFilename(filename) {
|
|
43700
|
+
this._name = path19.basename(filename, path19.extname(filename));
|
|
43701
|
+
return this;
|
|
43702
|
+
}
|
|
43703
|
+
/**
|
|
43704
|
+
* Get or set the directory for searching for executable subcommands of this command.
|
|
43705
|
+
*
|
|
43706
|
+
* @example
|
|
43707
|
+
* program.executableDir(__dirname);
|
|
43708
|
+
* // or
|
|
43709
|
+
* program.executableDir('subcommands');
|
|
43710
|
+
*
|
|
43711
|
+
* @param {string} [path]
|
|
43712
|
+
* @return {(string|null|Command)}
|
|
43713
|
+
*/
|
|
43714
|
+
executableDir(path20) {
|
|
43715
|
+
if (path20 === void 0) return this._executableDir;
|
|
43716
|
+
this._executableDir = path20;
|
|
43717
|
+
return this;
|
|
43718
|
+
}
|
|
43719
|
+
/**
|
|
43720
|
+
* Return program help documentation.
|
|
43721
|
+
*
|
|
43722
|
+
* @param {{ error: boolean }} [contextOptions] - pass {error:true} to wrap for stderr instead of stdout
|
|
43723
|
+
* @return {string}
|
|
43724
|
+
*/
|
|
43725
|
+
helpInformation(contextOptions) {
|
|
43726
|
+
const helper = this.createHelp();
|
|
43727
|
+
const context = this._getOutputContext(contextOptions);
|
|
43728
|
+
helper.prepareContext({
|
|
43729
|
+
error: context.error,
|
|
43730
|
+
helpWidth: context.helpWidth,
|
|
43731
|
+
outputHasColors: context.hasColors
|
|
43732
|
+
});
|
|
43733
|
+
const text = helper.formatHelp(this, helper);
|
|
43734
|
+
if (context.hasColors) return text;
|
|
43735
|
+
return this._outputConfiguration.stripColor(text);
|
|
43736
|
+
}
|
|
43737
|
+
/**
|
|
43738
|
+
* @typedef HelpContext
|
|
43739
|
+
* @type {object}
|
|
43740
|
+
* @property {boolean} error
|
|
43741
|
+
* @property {number} helpWidth
|
|
43742
|
+
* @property {boolean} hasColors
|
|
43743
|
+
* @property {function} write - includes stripColor if needed
|
|
43744
|
+
*
|
|
43745
|
+
* @returns {HelpContext}
|
|
43746
|
+
* @private
|
|
43747
|
+
*/
|
|
43748
|
+
_getOutputContext(contextOptions) {
|
|
43749
|
+
contextOptions = contextOptions || {};
|
|
43750
|
+
const error50 = !!contextOptions.error;
|
|
43751
|
+
let baseWrite;
|
|
43752
|
+
let hasColors;
|
|
43753
|
+
let helpWidth;
|
|
43754
|
+
if (error50) {
|
|
43755
|
+
baseWrite = (str3) => this._outputConfiguration.writeErr(str3);
|
|
43756
|
+
hasColors = this._outputConfiguration.getErrHasColors();
|
|
43757
|
+
helpWidth = this._outputConfiguration.getErrHelpWidth();
|
|
43758
|
+
} else {
|
|
43759
|
+
baseWrite = (str3) => this._outputConfiguration.writeOut(str3);
|
|
43760
|
+
hasColors = this._outputConfiguration.getOutHasColors();
|
|
43761
|
+
helpWidth = this._outputConfiguration.getOutHelpWidth();
|
|
43762
|
+
}
|
|
43763
|
+
const write = (str3) => {
|
|
43764
|
+
if (!hasColors) str3 = this._outputConfiguration.stripColor(str3);
|
|
43765
|
+
return baseWrite(str3);
|
|
43766
|
+
};
|
|
43767
|
+
return { error: error50, write, hasColors, helpWidth };
|
|
43768
|
+
}
|
|
43769
|
+
/**
|
|
43770
|
+
* Output help information for this command.
|
|
43771
|
+
*
|
|
43772
|
+
* Outputs built-in help, and custom text added using `.addHelpText()`.
|
|
43773
|
+
*
|
|
43774
|
+
* @param {{ error: boolean } | Function} [contextOptions] - pass {error:true} to write to stderr instead of stdout
|
|
43775
|
+
*/
|
|
43776
|
+
outputHelp(contextOptions) {
|
|
43777
|
+
let deprecatedCallback;
|
|
43778
|
+
if (typeof contextOptions === "function") {
|
|
43779
|
+
deprecatedCallback = contextOptions;
|
|
43780
|
+
contextOptions = void 0;
|
|
43781
|
+
}
|
|
43782
|
+
const outputContext = this._getOutputContext(contextOptions);
|
|
43783
|
+
const eventContext = {
|
|
43784
|
+
error: outputContext.error,
|
|
43785
|
+
write: outputContext.write,
|
|
43786
|
+
command: this
|
|
43787
|
+
};
|
|
43788
|
+
this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", eventContext));
|
|
43789
|
+
this.emit("beforeHelp", eventContext);
|
|
43790
|
+
let helpInformation = this.helpInformation({ error: outputContext.error });
|
|
43791
|
+
if (deprecatedCallback) {
|
|
43792
|
+
helpInformation = deprecatedCallback(helpInformation);
|
|
43793
|
+
if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
|
|
43794
|
+
throw new Error("outputHelp callback must return a string or a Buffer");
|
|
43795
|
+
}
|
|
43796
|
+
}
|
|
43797
|
+
outputContext.write(helpInformation);
|
|
43798
|
+
if (this._getHelpOption()?.long) {
|
|
43799
|
+
this.emit(this._getHelpOption().long);
|
|
43800
|
+
}
|
|
43801
|
+
this.emit("afterHelp", eventContext);
|
|
43802
|
+
this._getCommandAndAncestors().forEach(
|
|
43803
|
+
(command) => command.emit("afterAllHelp", eventContext)
|
|
43804
|
+
);
|
|
43805
|
+
}
|
|
43806
|
+
/**
|
|
43807
|
+
* You can pass in flags and a description to customise the built-in help option.
|
|
43808
|
+
* Pass in false to disable the built-in help option.
|
|
43809
|
+
*
|
|
43810
|
+
* @example
|
|
43811
|
+
* program.helpOption('-?, --help' 'show help'); // customise
|
|
43812
|
+
* program.helpOption(false); // disable
|
|
43813
|
+
*
|
|
43814
|
+
* @param {(string | boolean)} flags
|
|
43815
|
+
* @param {string} [description]
|
|
43816
|
+
* @return {Command} `this` command for chaining
|
|
43817
|
+
*/
|
|
43818
|
+
helpOption(flags, description) {
|
|
43819
|
+
if (typeof flags === "boolean") {
|
|
43820
|
+
if (flags) {
|
|
43821
|
+
if (this._helpOption === null) this._helpOption = void 0;
|
|
43822
|
+
if (this._defaultOptionGroup) {
|
|
43823
|
+
this._initOptionGroup(this._getHelpOption());
|
|
43824
|
+
}
|
|
43825
|
+
} else {
|
|
43826
|
+
this._helpOption = null;
|
|
43827
|
+
}
|
|
43828
|
+
return this;
|
|
43829
|
+
}
|
|
43830
|
+
this._helpOption = this.createOption(
|
|
43831
|
+
flags ?? "-h, --help",
|
|
43832
|
+
description ?? "display help for command"
|
|
43833
|
+
);
|
|
43834
|
+
if (flags || description) this._initOptionGroup(this._helpOption);
|
|
43835
|
+
return this;
|
|
43836
|
+
}
|
|
43837
|
+
/**
|
|
43838
|
+
* Lazy create help option.
|
|
43839
|
+
* Returns null if has been disabled with .helpOption(false).
|
|
43840
|
+
*
|
|
43841
|
+
* @returns {(Option | null)} the help option
|
|
43842
|
+
* @package
|
|
43843
|
+
*/
|
|
43844
|
+
_getHelpOption() {
|
|
43845
|
+
if (this._helpOption === void 0) {
|
|
43846
|
+
this.helpOption(void 0, void 0);
|
|
43847
|
+
}
|
|
43848
|
+
return this._helpOption;
|
|
43849
|
+
}
|
|
43850
|
+
/**
|
|
43851
|
+
* Supply your own option to use for the built-in help option.
|
|
43852
|
+
* This is an alternative to using helpOption() to customise the flags and description etc.
|
|
43853
|
+
*
|
|
43854
|
+
* @param {Option} option
|
|
43855
|
+
* @return {Command} `this` command for chaining
|
|
43856
|
+
*/
|
|
43857
|
+
addHelpOption(option) {
|
|
43858
|
+
this._helpOption = option;
|
|
43859
|
+
this._initOptionGroup(option);
|
|
43860
|
+
return this;
|
|
43861
|
+
}
|
|
43862
|
+
/**
|
|
43863
|
+
* Output help information and exit.
|
|
43864
|
+
*
|
|
43865
|
+
* Outputs built-in help, and custom text added using `.addHelpText()`.
|
|
43866
|
+
*
|
|
43867
|
+
* @param {{ error: boolean }} [contextOptions] - pass {error:true} to write to stderr instead of stdout
|
|
43868
|
+
*/
|
|
43869
|
+
help(contextOptions) {
|
|
43870
|
+
this.outputHelp(contextOptions);
|
|
43871
|
+
let exitCode3 = Number(process4.exitCode ?? 0);
|
|
43872
|
+
if (exitCode3 === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
|
|
43873
|
+
exitCode3 = 1;
|
|
43874
|
+
}
|
|
43875
|
+
this._exit(exitCode3, "commander.help", "(outputHelp)");
|
|
43876
|
+
}
|
|
43877
|
+
/**
|
|
43878
|
+
* // Do a little typing to coordinate emit and listener for the help text events.
|
|
43879
|
+
* @typedef HelpTextEventContext
|
|
43880
|
+
* @type {object}
|
|
43881
|
+
* @property {boolean} error
|
|
43882
|
+
* @property {Command} command
|
|
43883
|
+
* @property {function} write
|
|
43884
|
+
*/
|
|
43885
|
+
/**
|
|
43886
|
+
* Add additional text to be displayed with the built-in help.
|
|
43887
|
+
*
|
|
43888
|
+
* Position is 'before' or 'after' to affect just this command,
|
|
43889
|
+
* and 'beforeAll' or 'afterAll' to affect this command and all its subcommands.
|
|
43890
|
+
*
|
|
43891
|
+
* @param {string} position - before or after built-in help
|
|
43892
|
+
* @param {(string | Function)} text - string to add, or a function returning a string
|
|
43893
|
+
* @return {Command} `this` command for chaining
|
|
43894
|
+
*/
|
|
43895
|
+
addHelpText(position, text) {
|
|
43896
|
+
const allowedValues = ["beforeAll", "before", "after", "afterAll"];
|
|
43897
|
+
if (!allowedValues.includes(position)) {
|
|
43898
|
+
throw new Error(`Unexpected value for position to addHelpText.
|
|
43899
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
43900
|
+
}
|
|
43901
|
+
const helpEvent = `${position}Help`;
|
|
43902
|
+
this.on(helpEvent, (context) => {
|
|
43903
|
+
let helpStr;
|
|
43904
|
+
if (typeof text === "function") {
|
|
43905
|
+
helpStr = text({ error: context.error, command: context.command });
|
|
43906
|
+
} else {
|
|
43907
|
+
helpStr = text;
|
|
43908
|
+
}
|
|
43909
|
+
if (helpStr) {
|
|
43910
|
+
context.write(`${helpStr}
|
|
43911
|
+
`);
|
|
43912
|
+
}
|
|
43913
|
+
});
|
|
43914
|
+
return this;
|
|
43915
|
+
}
|
|
43916
|
+
/**
|
|
43917
|
+
* Output help information if help flags specified
|
|
43918
|
+
*
|
|
43919
|
+
* @param {Array} args - array of options to search for help flags
|
|
43920
|
+
* @private
|
|
43921
|
+
*/
|
|
43922
|
+
_outputHelpIfRequested(args) {
|
|
43923
|
+
const helpOption = this._getHelpOption();
|
|
43924
|
+
const helpRequested = helpOption && args.find((arg) => helpOption.is(arg));
|
|
43925
|
+
if (helpRequested) {
|
|
43926
|
+
this.outputHelp();
|
|
43927
|
+
this._exit(0, "commander.helpDisplayed", "(outputHelp)");
|
|
43928
|
+
}
|
|
43929
|
+
}
|
|
43930
|
+
};
|
|
43931
|
+
function incrementNodeInspectorPort(args) {
|
|
43932
|
+
return args.map((arg) => {
|
|
43933
|
+
if (!arg.startsWith("--inspect")) {
|
|
43934
|
+
return arg;
|
|
43935
|
+
}
|
|
43936
|
+
let debugOption;
|
|
43937
|
+
let debugHost = "127.0.0.1";
|
|
43938
|
+
let debugPort = "9229";
|
|
43939
|
+
let match2;
|
|
43940
|
+
if ((match2 = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
|
|
43941
|
+
debugOption = match2[1];
|
|
43942
|
+
} else if ((match2 = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
|
|
43943
|
+
debugOption = match2[1];
|
|
43944
|
+
if (/^\d+$/.test(match2[3])) {
|
|
43945
|
+
debugPort = match2[3];
|
|
43946
|
+
} else {
|
|
43947
|
+
debugHost = match2[3];
|
|
43948
|
+
}
|
|
43949
|
+
} else if ((match2 = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
|
|
43950
|
+
debugOption = match2[1];
|
|
43951
|
+
debugHost = match2[3];
|
|
43952
|
+
debugPort = match2[4];
|
|
43953
|
+
}
|
|
43954
|
+
if (debugOption && debugPort !== "0") {
|
|
43955
|
+
return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
|
|
43956
|
+
}
|
|
43957
|
+
return arg;
|
|
43958
|
+
});
|
|
43959
|
+
}
|
|
43960
|
+
function useColor() {
|
|
43961
|
+
if (process4.env.NO_COLOR || process4.env.FORCE_COLOR === "0" || process4.env.FORCE_COLOR === "false")
|
|
43962
|
+
return false;
|
|
43963
|
+
if (process4.env.FORCE_COLOR || process4.env.CLICOLOR_FORCE !== void 0)
|
|
43964
|
+
return true;
|
|
43965
|
+
return void 0;
|
|
43966
|
+
}
|
|
43967
|
+
exports2.Command = Command2;
|
|
43968
|
+
exports2.useColor = useColor;
|
|
43969
|
+
}
|
|
43970
|
+
});
|
|
43971
|
+
|
|
43972
|
+
// ../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/index.js
|
|
43973
|
+
var require_commander = __commonJS({
|
|
43974
|
+
"../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/index.js"(exports2) {
|
|
43975
|
+
"use strict";
|
|
43976
|
+
var { Argument: Argument2 } = require_argument();
|
|
43977
|
+
var { Command: Command2 } = require_command();
|
|
43978
|
+
var { CommanderError: CommanderError2, InvalidArgumentError: InvalidArgumentError2 } = require_error();
|
|
43979
|
+
var { Help: Help2 } = require_help();
|
|
43980
|
+
var { Option: Option2 } = require_option();
|
|
43981
|
+
exports2.program = new Command2();
|
|
43982
|
+
exports2.createCommand = (name) => new Command2(name);
|
|
43983
|
+
exports2.createOption = (flags, description) => new Option2(flags, description);
|
|
43984
|
+
exports2.createArgument = (name, description) => new Argument2(name, description);
|
|
43985
|
+
exports2.Command = Command2;
|
|
43986
|
+
exports2.Option = Option2;
|
|
43987
|
+
exports2.Argument = Argument2;
|
|
43988
|
+
exports2.Help = Help2;
|
|
43989
|
+
exports2.CommanderError = CommanderError2;
|
|
43990
|
+
exports2.InvalidArgumentError = InvalidArgumentError2;
|
|
43991
|
+
exports2.InvalidOptionArgumentError = InvalidArgumentError2;
|
|
43992
|
+
}
|
|
43993
|
+
});
|
|
43994
|
+
|
|
43995
|
+
// ../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/esm.mjs
|
|
43996
|
+
var import_index, program, createCommand, createArgument, createOption, CommanderError, InvalidArgumentError, InvalidOptionArgumentError, Command, Argument, Option, Help;
|
|
43997
|
+
var init_esm = __esm({
|
|
43998
|
+
"../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/esm.mjs"() {
|
|
43999
|
+
"use strict";
|
|
44000
|
+
import_index = __toESM(require_commander(), 1);
|
|
44001
|
+
({
|
|
44002
|
+
program,
|
|
44003
|
+
createCommand,
|
|
44004
|
+
createArgument,
|
|
44005
|
+
createOption,
|
|
44006
|
+
CommanderError,
|
|
44007
|
+
InvalidArgumentError,
|
|
44008
|
+
InvalidOptionArgumentError,
|
|
44009
|
+
Command: (
|
|
44010
|
+
// deprecated old name
|
|
44011
|
+
Command
|
|
44012
|
+
),
|
|
44013
|
+
Argument,
|
|
44014
|
+
Option,
|
|
44015
|
+
Help
|
|
44016
|
+
} = import_index.default);
|
|
44017
|
+
}
|
|
44018
|
+
});
|
|
44019
|
+
|
|
40562
44020
|
// ../notes/dist/chunk-F7MUVHZ2.js
|
|
40563
44021
|
import * as fs5 from "fs";
|
|
40564
44022
|
import * as path6 from "path";
|
|
@@ -40745,7 +44203,6 @@ import * as fs8 from "fs";
|
|
|
40745
44203
|
import * as path62 from "path";
|
|
40746
44204
|
import * as fs10 from "fs";
|
|
40747
44205
|
import * as readline from "readline";
|
|
40748
|
-
import { Command } from "commander";
|
|
40749
44206
|
function parseJsonc(content) {
|
|
40750
44207
|
if (content.length > MAX_JSONC_LENGTH) {
|
|
40751
44208
|
throw new Error(`JSONC content too long: ${content.length} characters (max ${MAX_JSONC_LENGTH})`);
|
|
@@ -42069,6 +45526,7 @@ var init_chunk_Y4S5UWCL = __esm({
|
|
|
42069
45526
|
init_ejs();
|
|
42070
45527
|
import_handlebars = __toESM(require_lib(), 1);
|
|
42071
45528
|
init_liquid_node();
|
|
45529
|
+
init_esm();
|
|
42072
45530
|
ConfigError = class extends ReleaseKitError2 {
|
|
42073
45531
|
code = "CONFIG_ERROR";
|
|
42074
45532
|
suggestions;
|
|
@@ -44682,7 +48140,6 @@ import * as path72 from "path";
|
|
|
44682
48140
|
import * as fs92 from "fs";
|
|
44683
48141
|
import * as path9 from "path";
|
|
44684
48142
|
import * as fs102 from "fs";
|
|
44685
|
-
import { Command as Command2 } from "commander";
|
|
44686
48143
|
function setLogLevel3(level) {
|
|
44687
48144
|
currentLevel3 = level;
|
|
44688
48145
|
}
|
|
@@ -46140,7 +49597,7 @@ async function readStdin2() {
|
|
|
46140
49597
|
return chunks.join("");
|
|
46141
49598
|
}
|
|
46142
49599
|
function createPublishCommand() {
|
|
46143
|
-
return new
|
|
49600
|
+
return new Command("publish").description("Publish packages to registries with git tagging and GitHub releases").option("--input <path>", "Path to version output JSON (default: stdin)").option("--config <path>", "Path to releasekit config").option("--registry <type>", "Registry to publish to (npm, cargo, all)", "all").option("--npm-auth <method>", "NPM auth method (oidc, token, auto)", "auto").option("--dry-run", "Simulate all operations", false).option("--skip-git", "Skip git commit/tag/push", false).option("--skip-publish", "Skip registry publishing", false).option("--skip-github-release", "Skip GitHub Release creation", false).option("--skip-verification", "Skip post-publish verification", false).option("--json", "Output results as JSON", false).option("--verbose", "Verbose logging", false).action(async (options) => {
|
|
46144
49601
|
if (options.verbose) setLogLevel3("debug");
|
|
46145
49602
|
if (options.json) setJsonMode2(true);
|
|
46146
49603
|
try {
|
|
@@ -46201,6 +49658,7 @@ var init_chunk_OZHNJUFW = __esm({
|
|
|
46201
49658
|
init_dist();
|
|
46202
49659
|
import_semver = __toESM(require_semver2(), 1);
|
|
46203
49660
|
init_zod();
|
|
49661
|
+
init_esm();
|
|
46204
49662
|
LOG_LEVELS3 = {
|
|
46205
49663
|
error: 0,
|
|
46206
49664
|
warn: 1,
|
|
@@ -50105,7 +53563,7 @@ var init_node_figlet = __esm({
|
|
|
50105
53563
|
|
|
50106
53564
|
// ../../node_modules/.pnpm/balanced-match@4.0.4/node_modules/balanced-match/dist/esm/index.js
|
|
50107
53565
|
var balanced, maybeMatch, range2;
|
|
50108
|
-
var
|
|
53566
|
+
var init_esm2 = __esm({
|
|
50109
53567
|
"../../node_modules/.pnpm/balanced-match@4.0.4/node_modules/balanced-match/dist/esm/index.js"() {
|
|
50110
53568
|
"use strict";
|
|
50111
53569
|
balanced = (a, b, str3) => {
|
|
@@ -50306,10 +53764,10 @@ function expand_(str3, max, isTop) {
|
|
|
50306
53764
|
return expansions;
|
|
50307
53765
|
}
|
|
50308
53766
|
var escSlash, escOpen, escClose, escComma, escPeriod, escSlashPattern, escOpenPattern, escClosePattern, escCommaPattern, escPeriodPattern, slashPattern, openPattern, closePattern, commaPattern, periodPattern, EXPANSION_MAX;
|
|
50309
|
-
var
|
|
53767
|
+
var init_esm3 = __esm({
|
|
50310
53768
|
"../../node_modules/.pnpm/brace-expansion@5.0.5/node_modules/brace-expansion/dist/esm/index.js"() {
|
|
50311
53769
|
"use strict";
|
|
50312
|
-
|
|
53770
|
+
init_esm2();
|
|
50313
53771
|
escSlash = "\0SLASH" + Math.random() + "\0";
|
|
50314
53772
|
escOpen = "\0OPEN" + Math.random() + "\0";
|
|
50315
53773
|
escClose = "\0CLOSE" + Math.random() + "\0";
|
|
@@ -51142,10 +54600,10 @@ var init_escape = __esm({
|
|
|
51142
54600
|
|
|
51143
54601
|
// ../../node_modules/.pnpm/minimatch@10.2.5/node_modules/minimatch/dist/esm/index.js
|
|
51144
54602
|
var minimatch, starDotExtRE, starDotExtTest, starDotExtTestDot, starDotExtTestNocase, starDotExtTestNocaseDot, starDotStarRE, starDotStarTest, starDotStarTestDot, dotStarRE, dotStarTest, starRE, starTest, starTestDot, qmarksRE, qmarksTestNocase, qmarksTestNocaseDot, qmarksTestDot, qmarksTest, qmarksTestNoExt, qmarksTestNoExtDot, defaultPlatform, path12, sep2, GLOBSTAR, qmark2, star2, twoStarDot, twoStarNoDot, filter2, ext, defaults2, braceExpand, makeRe, match, globMagic, regExpEscape2, Minimatch;
|
|
51145
|
-
var
|
|
54603
|
+
var init_esm4 = __esm({
|
|
51146
54604
|
"../../node_modules/.pnpm/minimatch@10.2.5/node_modules/minimatch/dist/esm/index.js"() {
|
|
51147
54605
|
"use strict";
|
|
51148
|
-
|
|
54606
|
+
init_esm3();
|
|
51149
54607
|
init_assert_valid_pattern();
|
|
51150
54608
|
init_ast();
|
|
51151
54609
|
init_escape();
|
|
@@ -59223,7 +62681,6 @@ import fs103 from "fs";
|
|
|
59223
62681
|
import * as path83 from "path";
|
|
59224
62682
|
import { cwd as cwd2 } from "process";
|
|
59225
62683
|
import path92 from "path";
|
|
59226
|
-
import { Command as Command3 } from "commander";
|
|
59227
62684
|
function parseCargoToml2(cargoPath) {
|
|
59228
62685
|
const content = fs15.readFileSync(cargoPath, "utf-8");
|
|
59229
62686
|
return parse(content);
|
|
@@ -60915,7 +64372,7 @@ function matchesPackageNamePattern(packageName, pattern) {
|
|
|
60915
64372
|
}
|
|
60916
64373
|
}
|
|
60917
64374
|
function createVersionCommand() {
|
|
60918
|
-
return new
|
|
64375
|
+
return new Command("version").description("Version a package or packages based on configuration").option("-c, --config <path>", "Path to config file (defaults to releasekit.config.json in current directory)").option("-d, --dry-run", "Dry run (no changes made)", false).option("-b, --bump <type>", "Specify bump type (patch|minor|major)").option("-p, --prerelease [identifier]", "Create prerelease version").option("-s, --sync", "Use synchronized versioning across all packages").option("-j, --json", "Output results as JSON", false).option("-t, --target <packages>", "Comma-delimited list of package names to target").option("--project-dir <path>", "Project directory to run commands in", process.cwd()).action(async (options) => {
|
|
60919
64376
|
if (options.json) {
|
|
60920
64377
|
enableJsonOutput(options.dryRun);
|
|
60921
64378
|
}
|
|
@@ -61002,9 +64459,10 @@ var init_chunk_UBCKZYTO = __esm({
|
|
|
61002
64459
|
init_node_figlet();
|
|
61003
64460
|
init_dist();
|
|
61004
64461
|
import_semver6 = __toESM(require_semver2(), 1);
|
|
61005
|
-
|
|
64462
|
+
init_esm4();
|
|
61006
64463
|
init_manypkg_get_packages();
|
|
61007
|
-
|
|
64464
|
+
init_esm4();
|
|
64465
|
+
init_esm();
|
|
61008
64466
|
ConfigError4 = class extends ReleaseKitError4 {
|
|
61009
64467
|
code = "CONFIG_ERROR";
|
|
61010
64468
|
suggestions;
|
|
@@ -61846,14 +65304,14 @@ var EXIT_CODES = {
|
|
|
61846
65304
|
init_dist2();
|
|
61847
65305
|
init_dist3();
|
|
61848
65306
|
init_dist16();
|
|
61849
|
-
|
|
65307
|
+
init_esm();
|
|
61850
65308
|
|
|
61851
65309
|
// src/init-command.ts
|
|
61852
65310
|
import * as fs16 from "fs";
|
|
61853
65311
|
init_dist2();
|
|
61854
|
-
|
|
65312
|
+
init_esm();
|
|
61855
65313
|
function createInitCommand() {
|
|
61856
|
-
return new
|
|
65314
|
+
return new Command("init").description("Create a default releasekit.config.json").option("-f, --force", "Overwrite existing config").action((options) => {
|
|
61857
65315
|
const configPath = "releasekit.config.json";
|
|
61858
65316
|
if (fs16.existsSync(configPath) && !options.force) {
|
|
61859
65317
|
error(`Config file already exists at ${configPath}. Use --force to overwrite.`);
|
|
@@ -61898,7 +65356,7 @@ function createInitCommand() {
|
|
|
61898
65356
|
}
|
|
61899
65357
|
|
|
61900
65358
|
// src/preview-command.ts
|
|
61901
|
-
|
|
65359
|
+
init_esm();
|
|
61902
65360
|
|
|
61903
65361
|
// ../config/dist/index.js
|
|
61904
65362
|
init_dist();
|
|
@@ -62874,7 +66332,7 @@ async function applyLabelOverrides(options, ciConfig, context, existingOctokit)
|
|
|
62874
66332
|
|
|
62875
66333
|
// src/preview-command.ts
|
|
62876
66334
|
function createPreviewCommand() {
|
|
62877
|
-
return new
|
|
66335
|
+
return new Command("preview").description("Post a release preview comment on the current pull request").option("-c, --config <path>", "Path to config file").option("--project-dir <path>", "Project directory", process.cwd()).option("--pr <number>", "PR number (auto-detected from GitHub Actions)").option("--repo <owner/repo>", "Repository (auto-detected from GITHUB_REPOSITORY)").option("-p, --prerelease [identifier]", "Force prerelease preview (auto-detected by default)").option("--stable", "Force stable release preview (graduation from prerelease)", false).option(
|
|
62878
66336
|
"-d, --dry-run",
|
|
62879
66337
|
"Print the comment to stdout without posting (GitHub context not available in dry-run mode)",
|
|
62880
66338
|
false
|
|
@@ -62897,9 +66355,9 @@ function createPreviewCommand() {
|
|
|
62897
66355
|
}
|
|
62898
66356
|
|
|
62899
66357
|
// src/release-command.ts
|
|
62900
|
-
|
|
66358
|
+
init_esm();
|
|
62901
66359
|
function createReleaseCommand() {
|
|
62902
|
-
return new
|
|
66360
|
+
return new Command("release").description("Run the full release pipeline").option("-c, --config <path>", "Path to config file").option("-d, --dry-run", "Preview all steps without side effects", false).option("-b, --bump <type>", "Force bump type (patch|minor|major)").option("-p, --prerelease [identifier]", "Create prerelease version").option("-s, --sync", "Use synchronized versioning across all packages", false).option("-t, --target <packages>", "Target specific packages (comma-separated)").option("--branch <name>", "Override the git branch used for push").addOption(new Option("--npm-auth <method>", "NPM auth method").choices(["auto", "oidc", "token"]).default("auto")).option("--skip-notes", "Skip changelog generation", false).option("--skip-publish", "Skip registry publishing and git operations", false).option("--skip-git", "Skip git commit/tag/push", false).option("--skip-github-release", "Skip GitHub release creation", false).option("--skip-verification", "Skip post-publish verification", false).option("-j, --json", "Output results as JSON", false).option("-v, --verbose", "Verbose logging", false).option("-q, --quiet", "Suppress non-error output", false).option("--project-dir <path>", "Project directory", process.cwd()).action(async (opts) => {
|
|
62903
66361
|
const options = {
|
|
62904
66362
|
config: opts.config,
|
|
62905
66363
|
dryRun: opts.dryRun,
|
|
@@ -62936,14 +66394,14 @@ function createReleaseCommand() {
|
|
|
62936
66394
|
|
|
62937
66395
|
// src/dispatcher.ts
|
|
62938
66396
|
function createDispatcherProgram() {
|
|
62939
|
-
const
|
|
62940
|
-
|
|
62941
|
-
|
|
62942
|
-
|
|
62943
|
-
|
|
62944
|
-
|
|
62945
|
-
|
|
62946
|
-
return
|
|
66397
|
+
const program2 = new Command().name("releasekit").description("Unified release pipeline: version, changelog, and publish").version(readPackageVersion(import.meta.url));
|
|
66398
|
+
program2.addCommand(createReleaseCommand(), { isDefault: true });
|
|
66399
|
+
program2.addCommand(createPreviewCommand());
|
|
66400
|
+
program2.addCommand(createInitCommand());
|
|
66401
|
+
program2.addCommand(createVersionCommand());
|
|
66402
|
+
program2.addCommand(createNotesCommand());
|
|
66403
|
+
program2.addCommand(createPublishCommand());
|
|
66404
|
+
return program2;
|
|
62947
66405
|
}
|
|
62948
66406
|
var isMain = (() => {
|
|
62949
66407
|
try {
|