@releasekit/release 0.7.15 → 0.7.16
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 +79 -3537
- package/dist/dispatcher.js +88 -3546
- package/package.json +6 -6
package/dist/dispatcher.js
CHANGED
|
@@ -15108,7 +15108,7 @@ var require_runtime = __commonJS({
|
|
|
15108
15108
|
return ret2;
|
|
15109
15109
|
},
|
|
15110
15110
|
programs: [],
|
|
15111
|
-
program: function
|
|
15111
|
+
program: function program(i, data, declaredBlockParams, blockParams, depths) {
|
|
15112
15112
|
var programWrapper = this.programs[i], fn = this.fn(i);
|
|
15113
15113
|
if (data || depths || blockParams || declaredBlockParams) {
|
|
15114
15114
|
programWrapper = wrapProgram(this, i, fn, data, declaredBlockParams, blockParams, depths);
|
|
@@ -15484,9 +15484,9 @@ var require_parser = __commonJS({
|
|
|
15484
15484
|
this.$ = { strip: yy.stripFlags($$[$0 - 1], $$[$0 - 1]), program: $$[$0] };
|
|
15485
15485
|
break;
|
|
15486
15486
|
case 19:
|
|
15487
|
-
var inverse = yy.prepareBlock($$[$0 - 2], $$[$0 - 1], $$[$0], $$[$0], false, this._$),
|
|
15488
|
-
|
|
15489
|
-
this.$ = { strip: $$[$0 - 2].strip, program
|
|
15487
|
+
var inverse = yy.prepareBlock($$[$0 - 2], $$[$0 - 1], $$[$0], $$[$0], false, this._$), program = yy.prepareProgram([inverse], $$[$0 - 1].loc);
|
|
15488
|
+
program.chained = true;
|
|
15489
|
+
this.$ = { strip: $$[$0 - 2].strip, program, chain: true };
|
|
15490
15490
|
break;
|
|
15491
15491
|
case 20:
|
|
15492
15492
|
this.$ = $$[$0];
|
|
@@ -16178,8 +16178,8 @@ var require_visitor = __commonJS({
|
|
|
16178
16178
|
return object;
|
|
16179
16179
|
}
|
|
16180
16180
|
},
|
|
16181
|
-
Program: function Program(
|
|
16182
|
-
this.acceptArray(
|
|
16181
|
+
Program: function Program(program) {
|
|
16182
|
+
this.acceptArray(program.body);
|
|
16183
16183
|
},
|
|
16184
16184
|
MustacheStatement: visitSubExpression,
|
|
16185
16185
|
Decorator: visitSubExpression,
|
|
@@ -16249,11 +16249,11 @@ var require_whitespace_control = __commonJS({
|
|
|
16249
16249
|
this.options = options;
|
|
16250
16250
|
}
|
|
16251
16251
|
WhitespaceControl.prototype = new _visitor2["default"]();
|
|
16252
|
-
WhitespaceControl.prototype.Program = function(
|
|
16252
|
+
WhitespaceControl.prototype.Program = function(program) {
|
|
16253
16253
|
var doStandalone = !this.options.ignoreStandalone;
|
|
16254
16254
|
var isRoot2 = !this.isRootSeen;
|
|
16255
16255
|
this.isRootSeen = true;
|
|
16256
|
-
var body =
|
|
16256
|
+
var body = program.body;
|
|
16257
16257
|
for (var i = 0, l = body.length; i < l; i++) {
|
|
16258
16258
|
var current = body[i], strip3 = this.accept(current);
|
|
16259
16259
|
if (!strip3) {
|
|
@@ -16283,12 +16283,12 @@ var require_whitespace_control = __commonJS({
|
|
|
16283
16283
|
omitLeft((current.inverse || current.program).body);
|
|
16284
16284
|
}
|
|
16285
16285
|
}
|
|
16286
|
-
return
|
|
16286
|
+
return program;
|
|
16287
16287
|
};
|
|
16288
16288
|
WhitespaceControl.prototype.BlockStatement = WhitespaceControl.prototype.DecoratorBlock = WhitespaceControl.prototype.PartialBlockStatement = function(block) {
|
|
16289
16289
|
this.accept(block.program);
|
|
16290
16290
|
this.accept(block.inverse);
|
|
16291
|
-
var
|
|
16291
|
+
var program = block.program || block.inverse, inverse = block.program && block.inverse, firstInverse = inverse, lastInverse = inverse;
|
|
16292
16292
|
if (inverse && inverse.chained) {
|
|
16293
16293
|
firstInverse = inverse.body[0].program;
|
|
16294
16294
|
while (lastInverse.chained) {
|
|
@@ -16300,16 +16300,16 @@ var require_whitespace_control = __commonJS({
|
|
|
16300
16300
|
close: block.closeStrip.close,
|
|
16301
16301
|
// Determine the standalone candiacy. Basically flag our content as being possibly standalone
|
|
16302
16302
|
// so our parent can determine if we actually are standalone
|
|
16303
|
-
openStandalone: isNextWhitespace(
|
|
16304
|
-
closeStandalone: isPrevWhitespace((firstInverse ||
|
|
16303
|
+
openStandalone: isNextWhitespace(program.body),
|
|
16304
|
+
closeStandalone: isPrevWhitespace((firstInverse || program).body)
|
|
16305
16305
|
};
|
|
16306
16306
|
if (block.openStrip.close) {
|
|
16307
|
-
omitRight(
|
|
16307
|
+
omitRight(program.body, null, true);
|
|
16308
16308
|
}
|
|
16309
16309
|
if (inverse) {
|
|
16310
16310
|
var inverseStrip = block.inverseStrip;
|
|
16311
16311
|
if (inverseStrip.open) {
|
|
16312
|
-
omitLeft(
|
|
16312
|
+
omitLeft(program.body, null, true);
|
|
16313
16313
|
}
|
|
16314
16314
|
if (inverseStrip.close) {
|
|
16315
16315
|
omitRight(firstInverse.body, null, true);
|
|
@@ -16317,12 +16317,12 @@ var require_whitespace_control = __commonJS({
|
|
|
16317
16317
|
if (block.closeStrip.open) {
|
|
16318
16318
|
omitLeft(lastInverse.body, null, true);
|
|
16319
16319
|
}
|
|
16320
|
-
if (!this.options.ignoreStandalone && isPrevWhitespace(
|
|
16321
|
-
omitLeft(
|
|
16320
|
+
if (!this.options.ignoreStandalone && isPrevWhitespace(program.body) && isNextWhitespace(firstInverse.body)) {
|
|
16321
|
+
omitLeft(program.body);
|
|
16322
16322
|
omitRight(firstInverse.body);
|
|
16323
16323
|
}
|
|
16324
16324
|
} else if (block.closeStrip.open) {
|
|
16325
|
-
omitLeft(
|
|
16325
|
+
omitLeft(program.body, null, true);
|
|
16326
16326
|
}
|
|
16327
16327
|
return strip3;
|
|
16328
16328
|
};
|
|
@@ -16480,7 +16480,7 @@ var require_helpers2 = __commonJS({
|
|
|
16480
16480
|
function prepareRawBlock(openRawBlock, contents, close, locInfo) {
|
|
16481
16481
|
validateClose(openRawBlock, close);
|
|
16482
16482
|
locInfo = this.locInfo(locInfo);
|
|
16483
|
-
var
|
|
16483
|
+
var program = {
|
|
16484
16484
|
type: "Program",
|
|
16485
16485
|
body: contents,
|
|
16486
16486
|
strip: {},
|
|
@@ -16491,19 +16491,19 @@ var require_helpers2 = __commonJS({
|
|
|
16491
16491
|
path: openRawBlock.path,
|
|
16492
16492
|
params: openRawBlock.params,
|
|
16493
16493
|
hash: openRawBlock.hash,
|
|
16494
|
-
program
|
|
16494
|
+
program,
|
|
16495
16495
|
openStrip: {},
|
|
16496
16496
|
inverseStrip: {},
|
|
16497
16497
|
closeStrip: {},
|
|
16498
16498
|
loc: locInfo
|
|
16499
16499
|
};
|
|
16500
16500
|
}
|
|
16501
|
-
function prepareBlock(openBlock,
|
|
16501
|
+
function prepareBlock(openBlock, program, inverseAndProgram, close, inverted, locInfo) {
|
|
16502
16502
|
if (close && close.path) {
|
|
16503
16503
|
validateClose(openBlock, close);
|
|
16504
16504
|
}
|
|
16505
16505
|
var decorator = /\*/.test(openBlock.open);
|
|
16506
|
-
|
|
16506
|
+
program.blockParams = openBlock.blockParams;
|
|
16507
16507
|
var inverse = void 0, inverseStrip = void 0;
|
|
16508
16508
|
if (inverseAndProgram) {
|
|
16509
16509
|
if (decorator) {
|
|
@@ -16517,15 +16517,15 @@ var require_helpers2 = __commonJS({
|
|
|
16517
16517
|
}
|
|
16518
16518
|
if (inverted) {
|
|
16519
16519
|
inverted = inverse;
|
|
16520
|
-
inverse =
|
|
16521
|
-
|
|
16520
|
+
inverse = program;
|
|
16521
|
+
program = inverted;
|
|
16522
16522
|
}
|
|
16523
16523
|
return {
|
|
16524
16524
|
type: decorator ? "DecoratorBlock" : "BlockStatement",
|
|
16525
16525
|
path: openBlock.path,
|
|
16526
16526
|
params: openBlock.params,
|
|
16527
16527
|
hash: openBlock.hash,
|
|
16528
|
-
program
|
|
16528
|
+
program,
|
|
16529
16529
|
inverse,
|
|
16530
16530
|
openStrip: openBlock.strip,
|
|
16531
16531
|
inverseStrip,
|
|
@@ -16557,14 +16557,14 @@ var require_helpers2 = __commonJS({
|
|
|
16557
16557
|
loc
|
|
16558
16558
|
};
|
|
16559
16559
|
}
|
|
16560
|
-
function preparePartialBlock(open,
|
|
16560
|
+
function preparePartialBlock(open, program, close, locInfo) {
|
|
16561
16561
|
validateClose(open, close);
|
|
16562
16562
|
return {
|
|
16563
16563
|
type: "PartialBlockStatement",
|
|
16564
16564
|
name: open.path,
|
|
16565
16565
|
params: open.params,
|
|
16566
16566
|
hash: open.hash,
|
|
16567
|
-
program
|
|
16567
|
+
program,
|
|
16568
16568
|
openStrip: open.strip,
|
|
16569
16569
|
closeStrip: close && close.strip,
|
|
16570
16570
|
loc: this.locInfo(locInfo)
|
|
@@ -16715,7 +16715,7 @@ var require_compiler = __commonJS({
|
|
|
16715
16715
|
return true;
|
|
16716
16716
|
},
|
|
16717
16717
|
guid: 0,
|
|
16718
|
-
compile: function compile3(
|
|
16718
|
+
compile: function compile3(program, options) {
|
|
16719
16719
|
this.sourceNode = [];
|
|
16720
16720
|
this.opcodes = [];
|
|
16721
16721
|
this.children = [];
|
|
@@ -16733,10 +16733,10 @@ var require_compiler = __commonJS({
|
|
|
16733
16733
|
log: true,
|
|
16734
16734
|
lookup: true
|
|
16735
16735
|
}, options.knownHelpers);
|
|
16736
|
-
return this.accept(
|
|
16736
|
+
return this.accept(program);
|
|
16737
16737
|
},
|
|
16738
|
-
compileProgram: function compileProgram(
|
|
16739
|
-
var childCompiler = new this.compiler(), result = childCompiler.compile(
|
|
16738
|
+
compileProgram: function compileProgram(program) {
|
|
16739
|
+
var childCompiler = new this.compiler(), result = childCompiler.compile(program, this.options), guid = this.guid++;
|
|
16740
16740
|
this.usePartial = this.usePartial || result.usePartial;
|
|
16741
16741
|
this.children[guid] = result;
|
|
16742
16742
|
this.useDepths = this.useDepths || result.useDepths;
|
|
@@ -16751,34 +16751,34 @@ var require_compiler = __commonJS({
|
|
|
16751
16751
|
this.sourceNode.shift();
|
|
16752
16752
|
return ret;
|
|
16753
16753
|
},
|
|
16754
|
-
Program: function Program(
|
|
16755
|
-
this.options.blockParams.unshift(
|
|
16756
|
-
var body =
|
|
16754
|
+
Program: function Program(program) {
|
|
16755
|
+
this.options.blockParams.unshift(program.blockParams);
|
|
16756
|
+
var body = program.body, bodyLength = body.length;
|
|
16757
16757
|
for (var i = 0; i < bodyLength; i++) {
|
|
16758
16758
|
this.accept(body[i]);
|
|
16759
16759
|
}
|
|
16760
16760
|
this.options.blockParams.shift();
|
|
16761
16761
|
this.isSimple = bodyLength === 1;
|
|
16762
|
-
this.blockParams =
|
|
16762
|
+
this.blockParams = program.blockParams ? program.blockParams.length : 0;
|
|
16763
16763
|
return this;
|
|
16764
16764
|
},
|
|
16765
16765
|
BlockStatement: function BlockStatement(block) {
|
|
16766
16766
|
transformLiteralToPath(block);
|
|
16767
|
-
var
|
|
16768
|
-
|
|
16767
|
+
var program = block.program, inverse = block.inverse;
|
|
16768
|
+
program = program && this.compileProgram(program);
|
|
16769
16769
|
inverse = inverse && this.compileProgram(inverse);
|
|
16770
16770
|
var type2 = this.classifySexpr(block);
|
|
16771
16771
|
if (type2 === "helper") {
|
|
16772
|
-
this.helperSexpr(block,
|
|
16772
|
+
this.helperSexpr(block, program, inverse);
|
|
16773
16773
|
} else if (type2 === "simple") {
|
|
16774
16774
|
this.simpleSexpr(block);
|
|
16775
|
-
this.opcode("pushProgram",
|
|
16775
|
+
this.opcode("pushProgram", program);
|
|
16776
16776
|
this.opcode("pushProgram", inverse);
|
|
16777
16777
|
this.opcode("emptyHash");
|
|
16778
16778
|
this.opcode("blockValue", block.path.original);
|
|
16779
16779
|
} else {
|
|
16780
|
-
this.ambiguousSexpr(block,
|
|
16781
|
-
this.opcode("pushProgram",
|
|
16780
|
+
this.ambiguousSexpr(block, program, inverse);
|
|
16781
|
+
this.opcode("pushProgram", program);
|
|
16782
16782
|
this.opcode("pushProgram", inverse);
|
|
16783
16783
|
this.opcode("emptyHash");
|
|
16784
16784
|
this.opcode("ambiguousBlockValue");
|
|
@@ -16786,16 +16786,16 @@ var require_compiler = __commonJS({
|
|
|
16786
16786
|
this.opcode("append");
|
|
16787
16787
|
},
|
|
16788
16788
|
DecoratorBlock: function DecoratorBlock(decorator) {
|
|
16789
|
-
var
|
|
16790
|
-
var params = this.setupFullMustacheParams(decorator,
|
|
16789
|
+
var program = decorator.program && this.compileProgram(decorator.program);
|
|
16790
|
+
var params = this.setupFullMustacheParams(decorator, program, void 0), path19 = decorator.path;
|
|
16791
16791
|
this.useDecorators = true;
|
|
16792
16792
|
this.opcode("registerDecorator", params.length, path19.original);
|
|
16793
16793
|
},
|
|
16794
16794
|
PartialStatement: function PartialStatement(partial) {
|
|
16795
16795
|
this.usePartial = true;
|
|
16796
|
-
var
|
|
16797
|
-
if (
|
|
16798
|
-
|
|
16796
|
+
var program = partial.program;
|
|
16797
|
+
if (program) {
|
|
16798
|
+
program = this.compileProgram(partial.program);
|
|
16799
16799
|
}
|
|
16800
16800
|
var params = partial.params;
|
|
16801
16801
|
if (params.length > 1) {
|
|
@@ -16811,7 +16811,7 @@ var require_compiler = __commonJS({
|
|
|
16811
16811
|
if (isDynamic) {
|
|
16812
16812
|
this.accept(partial.name);
|
|
16813
16813
|
}
|
|
16814
|
-
this.setupFullMustacheParams(partial,
|
|
16814
|
+
this.setupFullMustacheParams(partial, program, void 0, true);
|
|
16815
16815
|
var indent = partial.indent || "";
|
|
16816
16816
|
if (this.options.preventIndent && indent) {
|
|
16817
16817
|
this.opcode("appendContent", indent);
|
|
@@ -16852,10 +16852,10 @@ var require_compiler = __commonJS({
|
|
|
16852
16852
|
this.ambiguousSexpr(sexpr);
|
|
16853
16853
|
}
|
|
16854
16854
|
},
|
|
16855
|
-
ambiguousSexpr: function ambiguousSexpr(sexpr,
|
|
16856
|
-
var path19 = sexpr.path, name = path19.parts[0], isBlock =
|
|
16855
|
+
ambiguousSexpr: function ambiguousSexpr(sexpr, program, inverse) {
|
|
16856
|
+
var path19 = sexpr.path, name = path19.parts[0], isBlock = program != null || inverse != null;
|
|
16857
16857
|
this.opcode("getContext", path19.depth);
|
|
16858
|
-
this.opcode("pushProgram",
|
|
16858
|
+
this.opcode("pushProgram", program);
|
|
16859
16859
|
this.opcode("pushProgram", inverse);
|
|
16860
16860
|
path19.strict = true;
|
|
16861
16861
|
this.accept(path19);
|
|
@@ -16867,8 +16867,8 @@ var require_compiler = __commonJS({
|
|
|
16867
16867
|
this.accept(path19);
|
|
16868
16868
|
this.opcode("resolvePossibleLambda");
|
|
16869
16869
|
},
|
|
16870
|
-
helperSexpr: function helperSexpr(sexpr,
|
|
16871
|
-
var params = this.setupFullMustacheParams(sexpr,
|
|
16870
|
+
helperSexpr: function helperSexpr(sexpr, program, inverse) {
|
|
16871
|
+
var params = this.setupFullMustacheParams(sexpr, program, inverse), path19 = sexpr.path, name = path19.parts[0];
|
|
16872
16872
|
if (this.options.knownHelpers[name]) {
|
|
16873
16873
|
this.opcode("invokeKnownHelper", params.length, name);
|
|
16874
16874
|
} else if (this.options.knownHelpersOnly) {
|
|
@@ -16995,10 +16995,10 @@ var require_compiler = __commonJS({
|
|
|
16995
16995
|
this.accept(val);
|
|
16996
16996
|
}
|
|
16997
16997
|
},
|
|
16998
|
-
setupFullMustacheParams: function setupFullMustacheParams(sexpr,
|
|
16998
|
+
setupFullMustacheParams: function setupFullMustacheParams(sexpr, program, inverse, omitEmpty) {
|
|
16999
16999
|
var params = sexpr.params;
|
|
17000
17000
|
this.pushParams(params);
|
|
17001
|
-
this.opcode("pushProgram",
|
|
17001
|
+
this.opcode("pushProgram", program);
|
|
17002
17002
|
this.opcode("pushProgram", inverse);
|
|
17003
17003
|
if (sexpr.hash) {
|
|
17004
17004
|
this.accept(sexpr.hash);
|
|
@@ -19828,9 +19828,9 @@ var require_javascript_compiler = __commonJS({
|
|
|
19828
19828
|
options.hashTypes = this.popStack();
|
|
19829
19829
|
options.hashContexts = this.popStack();
|
|
19830
19830
|
}
|
|
19831
|
-
var inverse = this.popStack(),
|
|
19832
|
-
if (
|
|
19833
|
-
options.fn =
|
|
19831
|
+
var inverse = this.popStack(), program = this.popStack();
|
|
19832
|
+
if (program || inverse) {
|
|
19833
|
+
options.fn = program || "container.noop";
|
|
19834
19834
|
options.inverse = inverse || "container.noop";
|
|
19835
19835
|
}
|
|
19836
19836
|
var i = paramSize;
|
|
@@ -19982,12 +19982,12 @@ var require_printer = __commonJS({
|
|
|
19982
19982
|
out += string + "\n";
|
|
19983
19983
|
return out;
|
|
19984
19984
|
};
|
|
19985
|
-
PrintVisitor.prototype.Program = function(
|
|
19986
|
-
var out = "", body =
|
|
19987
|
-
if (
|
|
19985
|
+
PrintVisitor.prototype.Program = function(program) {
|
|
19986
|
+
var out = "", body = program.body, i = void 0, l = void 0;
|
|
19987
|
+
if (program.blockParams) {
|
|
19988
19988
|
var blockParams = "BLOCK PARAMS: [";
|
|
19989
|
-
for (i = 0, l =
|
|
19990
|
-
blockParams += " " +
|
|
19989
|
+
for (i = 0, l = program.blockParams.length; i < l; i++) {
|
|
19990
|
+
blockParams += " " + program.blockParams[i];
|
|
19991
19991
|
}
|
|
19992
19992
|
blockParams += " ]";
|
|
19993
19993
|
out += this.pad(blockParams);
|
|
@@ -24745,3464 +24745,6 @@ var init_liquid_node = __esm({
|
|
|
24745
24745
|
}
|
|
24746
24746
|
});
|
|
24747
24747
|
|
|
24748
|
-
// ../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/error.js
|
|
24749
|
-
var require_error = __commonJS({
|
|
24750
|
-
"../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/error.js"(exports2) {
|
|
24751
|
-
"use strict";
|
|
24752
|
-
var CommanderError2 = class extends Error {
|
|
24753
|
-
/**
|
|
24754
|
-
* Constructs the CommanderError class
|
|
24755
|
-
* @param {number} exitCode suggested exit code which could be used with process.exit
|
|
24756
|
-
* @param {string} code an id string representing the error
|
|
24757
|
-
* @param {string} message human-readable description of the error
|
|
24758
|
-
*/
|
|
24759
|
-
constructor(exitCode3, code, message) {
|
|
24760
|
-
super(message);
|
|
24761
|
-
Error.captureStackTrace(this, this.constructor);
|
|
24762
|
-
this.name = this.constructor.name;
|
|
24763
|
-
this.code = code;
|
|
24764
|
-
this.exitCode = exitCode3;
|
|
24765
|
-
this.nestedError = void 0;
|
|
24766
|
-
}
|
|
24767
|
-
};
|
|
24768
|
-
var InvalidArgumentError2 = class extends CommanderError2 {
|
|
24769
|
-
/**
|
|
24770
|
-
* Constructs the InvalidArgumentError class
|
|
24771
|
-
* @param {string} [message] explanation of why argument is invalid
|
|
24772
|
-
*/
|
|
24773
|
-
constructor(message) {
|
|
24774
|
-
super(1, "commander.invalidArgument", message);
|
|
24775
|
-
Error.captureStackTrace(this, this.constructor);
|
|
24776
|
-
this.name = this.constructor.name;
|
|
24777
|
-
}
|
|
24778
|
-
};
|
|
24779
|
-
exports2.CommanderError = CommanderError2;
|
|
24780
|
-
exports2.InvalidArgumentError = InvalidArgumentError2;
|
|
24781
|
-
}
|
|
24782
|
-
});
|
|
24783
|
-
|
|
24784
|
-
// ../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/argument.js
|
|
24785
|
-
var require_argument = __commonJS({
|
|
24786
|
-
"../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/argument.js"(exports2) {
|
|
24787
|
-
"use strict";
|
|
24788
|
-
var { InvalidArgumentError: InvalidArgumentError2 } = require_error();
|
|
24789
|
-
var Argument2 = class {
|
|
24790
|
-
/**
|
|
24791
|
-
* Initialize a new command argument with the given name and description.
|
|
24792
|
-
* The default is that the argument is required, and you can explicitly
|
|
24793
|
-
* indicate this with <> around the name. Put [] around the name for an optional argument.
|
|
24794
|
-
*
|
|
24795
|
-
* @param {string} name
|
|
24796
|
-
* @param {string} [description]
|
|
24797
|
-
*/
|
|
24798
|
-
constructor(name, description) {
|
|
24799
|
-
this.description = description || "";
|
|
24800
|
-
this.variadic = false;
|
|
24801
|
-
this.parseArg = void 0;
|
|
24802
|
-
this.defaultValue = void 0;
|
|
24803
|
-
this.defaultValueDescription = void 0;
|
|
24804
|
-
this.argChoices = void 0;
|
|
24805
|
-
switch (name[0]) {
|
|
24806
|
-
case "<":
|
|
24807
|
-
this.required = true;
|
|
24808
|
-
this._name = name.slice(1, -1);
|
|
24809
|
-
break;
|
|
24810
|
-
case "[":
|
|
24811
|
-
this.required = false;
|
|
24812
|
-
this._name = name.slice(1, -1);
|
|
24813
|
-
break;
|
|
24814
|
-
default:
|
|
24815
|
-
this.required = true;
|
|
24816
|
-
this._name = name;
|
|
24817
|
-
break;
|
|
24818
|
-
}
|
|
24819
|
-
if (this._name.endsWith("...")) {
|
|
24820
|
-
this.variadic = true;
|
|
24821
|
-
this._name = this._name.slice(0, -3);
|
|
24822
|
-
}
|
|
24823
|
-
}
|
|
24824
|
-
/**
|
|
24825
|
-
* Return argument name.
|
|
24826
|
-
*
|
|
24827
|
-
* @return {string}
|
|
24828
|
-
*/
|
|
24829
|
-
name() {
|
|
24830
|
-
return this._name;
|
|
24831
|
-
}
|
|
24832
|
-
/**
|
|
24833
|
-
* @package
|
|
24834
|
-
*/
|
|
24835
|
-
_collectValue(value, previous) {
|
|
24836
|
-
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
24837
|
-
return [value];
|
|
24838
|
-
}
|
|
24839
|
-
previous.push(value);
|
|
24840
|
-
return previous;
|
|
24841
|
-
}
|
|
24842
|
-
/**
|
|
24843
|
-
* Set the default value, and optionally supply the description to be displayed in the help.
|
|
24844
|
-
*
|
|
24845
|
-
* @param {*} value
|
|
24846
|
-
* @param {string} [description]
|
|
24847
|
-
* @return {Argument}
|
|
24848
|
-
*/
|
|
24849
|
-
default(value, description) {
|
|
24850
|
-
this.defaultValue = value;
|
|
24851
|
-
this.defaultValueDescription = description;
|
|
24852
|
-
return this;
|
|
24853
|
-
}
|
|
24854
|
-
/**
|
|
24855
|
-
* Set the custom handler for processing CLI command arguments into argument values.
|
|
24856
|
-
*
|
|
24857
|
-
* @param {Function} [fn]
|
|
24858
|
-
* @return {Argument}
|
|
24859
|
-
*/
|
|
24860
|
-
argParser(fn) {
|
|
24861
|
-
this.parseArg = fn;
|
|
24862
|
-
return this;
|
|
24863
|
-
}
|
|
24864
|
-
/**
|
|
24865
|
-
* Only allow argument value to be one of choices.
|
|
24866
|
-
*
|
|
24867
|
-
* @param {string[]} values
|
|
24868
|
-
* @return {Argument}
|
|
24869
|
-
*/
|
|
24870
|
-
choices(values) {
|
|
24871
|
-
this.argChoices = values.slice();
|
|
24872
|
-
this.parseArg = (arg, previous) => {
|
|
24873
|
-
if (!this.argChoices.includes(arg)) {
|
|
24874
|
-
throw new InvalidArgumentError2(
|
|
24875
|
-
`Allowed choices are ${this.argChoices.join(", ")}.`
|
|
24876
|
-
);
|
|
24877
|
-
}
|
|
24878
|
-
if (this.variadic) {
|
|
24879
|
-
return this._collectValue(arg, previous);
|
|
24880
|
-
}
|
|
24881
|
-
return arg;
|
|
24882
|
-
};
|
|
24883
|
-
return this;
|
|
24884
|
-
}
|
|
24885
|
-
/**
|
|
24886
|
-
* Make argument required.
|
|
24887
|
-
*
|
|
24888
|
-
* @returns {Argument}
|
|
24889
|
-
*/
|
|
24890
|
-
argRequired() {
|
|
24891
|
-
this.required = true;
|
|
24892
|
-
return this;
|
|
24893
|
-
}
|
|
24894
|
-
/**
|
|
24895
|
-
* Make argument optional.
|
|
24896
|
-
*
|
|
24897
|
-
* @returns {Argument}
|
|
24898
|
-
*/
|
|
24899
|
-
argOptional() {
|
|
24900
|
-
this.required = false;
|
|
24901
|
-
return this;
|
|
24902
|
-
}
|
|
24903
|
-
};
|
|
24904
|
-
function humanReadableArgName(arg) {
|
|
24905
|
-
const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
|
|
24906
|
-
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
|
|
24907
|
-
}
|
|
24908
|
-
exports2.Argument = Argument2;
|
|
24909
|
-
exports2.humanReadableArgName = humanReadableArgName;
|
|
24910
|
-
}
|
|
24911
|
-
});
|
|
24912
|
-
|
|
24913
|
-
// ../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/help.js
|
|
24914
|
-
var require_help = __commonJS({
|
|
24915
|
-
"../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/help.js"(exports2) {
|
|
24916
|
-
"use strict";
|
|
24917
|
-
var { humanReadableArgName } = require_argument();
|
|
24918
|
-
var Help2 = class {
|
|
24919
|
-
constructor() {
|
|
24920
|
-
this.helpWidth = void 0;
|
|
24921
|
-
this.minWidthToWrap = 40;
|
|
24922
|
-
this.sortSubcommands = false;
|
|
24923
|
-
this.sortOptions = false;
|
|
24924
|
-
this.showGlobalOptions = false;
|
|
24925
|
-
}
|
|
24926
|
-
/**
|
|
24927
|
-
* prepareContext is called by Commander after applying overrides from `Command.configureHelp()`
|
|
24928
|
-
* and just before calling `formatHelp()`.
|
|
24929
|
-
*
|
|
24930
|
-
* Commander just uses the helpWidth and the rest is provided for optional use by more complex subclasses.
|
|
24931
|
-
*
|
|
24932
|
-
* @param {{ error?: boolean, helpWidth?: number, outputHasColors?: boolean }} contextOptions
|
|
24933
|
-
*/
|
|
24934
|
-
prepareContext(contextOptions) {
|
|
24935
|
-
this.helpWidth = this.helpWidth ?? contextOptions.helpWidth ?? 80;
|
|
24936
|
-
}
|
|
24937
|
-
/**
|
|
24938
|
-
* Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one.
|
|
24939
|
-
*
|
|
24940
|
-
* @param {Command} cmd
|
|
24941
|
-
* @returns {Command[]}
|
|
24942
|
-
*/
|
|
24943
|
-
visibleCommands(cmd) {
|
|
24944
|
-
const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
|
|
24945
|
-
const helpCommand = cmd._getHelpCommand();
|
|
24946
|
-
if (helpCommand && !helpCommand._hidden) {
|
|
24947
|
-
visibleCommands.push(helpCommand);
|
|
24948
|
-
}
|
|
24949
|
-
if (this.sortSubcommands) {
|
|
24950
|
-
visibleCommands.sort((a, b) => {
|
|
24951
|
-
return a.name().localeCompare(b.name());
|
|
24952
|
-
});
|
|
24953
|
-
}
|
|
24954
|
-
return visibleCommands;
|
|
24955
|
-
}
|
|
24956
|
-
/**
|
|
24957
|
-
* Compare options for sort.
|
|
24958
|
-
*
|
|
24959
|
-
* @param {Option} a
|
|
24960
|
-
* @param {Option} b
|
|
24961
|
-
* @returns {number}
|
|
24962
|
-
*/
|
|
24963
|
-
compareOptions(a, b) {
|
|
24964
|
-
const getSortKey = (option) => {
|
|
24965
|
-
return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
|
|
24966
|
-
};
|
|
24967
|
-
return getSortKey(a).localeCompare(getSortKey(b));
|
|
24968
|
-
}
|
|
24969
|
-
/**
|
|
24970
|
-
* Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one.
|
|
24971
|
-
*
|
|
24972
|
-
* @param {Command} cmd
|
|
24973
|
-
* @returns {Option[]}
|
|
24974
|
-
*/
|
|
24975
|
-
visibleOptions(cmd) {
|
|
24976
|
-
const visibleOptions = cmd.options.filter((option) => !option.hidden);
|
|
24977
|
-
const helpOption = cmd._getHelpOption();
|
|
24978
|
-
if (helpOption && !helpOption.hidden) {
|
|
24979
|
-
const removeShort = helpOption.short && cmd._findOption(helpOption.short);
|
|
24980
|
-
const removeLong = helpOption.long && cmd._findOption(helpOption.long);
|
|
24981
|
-
if (!removeShort && !removeLong) {
|
|
24982
|
-
visibleOptions.push(helpOption);
|
|
24983
|
-
} else if (helpOption.long && !removeLong) {
|
|
24984
|
-
visibleOptions.push(
|
|
24985
|
-
cmd.createOption(helpOption.long, helpOption.description)
|
|
24986
|
-
);
|
|
24987
|
-
} else if (helpOption.short && !removeShort) {
|
|
24988
|
-
visibleOptions.push(
|
|
24989
|
-
cmd.createOption(helpOption.short, helpOption.description)
|
|
24990
|
-
);
|
|
24991
|
-
}
|
|
24992
|
-
}
|
|
24993
|
-
if (this.sortOptions) {
|
|
24994
|
-
visibleOptions.sort(this.compareOptions);
|
|
24995
|
-
}
|
|
24996
|
-
return visibleOptions;
|
|
24997
|
-
}
|
|
24998
|
-
/**
|
|
24999
|
-
* Get an array of the visible global options. (Not including help.)
|
|
25000
|
-
*
|
|
25001
|
-
* @param {Command} cmd
|
|
25002
|
-
* @returns {Option[]}
|
|
25003
|
-
*/
|
|
25004
|
-
visibleGlobalOptions(cmd) {
|
|
25005
|
-
if (!this.showGlobalOptions) return [];
|
|
25006
|
-
const globalOptions = [];
|
|
25007
|
-
for (let ancestorCmd = cmd.parent; ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
25008
|
-
const visibleOptions = ancestorCmd.options.filter(
|
|
25009
|
-
(option) => !option.hidden
|
|
25010
|
-
);
|
|
25011
|
-
globalOptions.push(...visibleOptions);
|
|
25012
|
-
}
|
|
25013
|
-
if (this.sortOptions) {
|
|
25014
|
-
globalOptions.sort(this.compareOptions);
|
|
25015
|
-
}
|
|
25016
|
-
return globalOptions;
|
|
25017
|
-
}
|
|
25018
|
-
/**
|
|
25019
|
-
* Get an array of the arguments if any have a description.
|
|
25020
|
-
*
|
|
25021
|
-
* @param {Command} cmd
|
|
25022
|
-
* @returns {Argument[]}
|
|
25023
|
-
*/
|
|
25024
|
-
visibleArguments(cmd) {
|
|
25025
|
-
if (cmd._argsDescription) {
|
|
25026
|
-
cmd.registeredArguments.forEach((argument) => {
|
|
25027
|
-
argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
|
|
25028
|
-
});
|
|
25029
|
-
}
|
|
25030
|
-
if (cmd.registeredArguments.find((argument) => argument.description)) {
|
|
25031
|
-
return cmd.registeredArguments;
|
|
25032
|
-
}
|
|
25033
|
-
return [];
|
|
25034
|
-
}
|
|
25035
|
-
/**
|
|
25036
|
-
* Get the command term to show in the list of subcommands.
|
|
25037
|
-
*
|
|
25038
|
-
* @param {Command} cmd
|
|
25039
|
-
* @returns {string}
|
|
25040
|
-
*/
|
|
25041
|
-
subcommandTerm(cmd) {
|
|
25042
|
-
const args = cmd.registeredArguments.map((arg) => humanReadableArgName(arg)).join(" ");
|
|
25043
|
-
return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + // simplistic check for non-help option
|
|
25044
|
-
(args ? " " + args : "");
|
|
25045
|
-
}
|
|
25046
|
-
/**
|
|
25047
|
-
* Get the option term to show in the list of options.
|
|
25048
|
-
*
|
|
25049
|
-
* @param {Option} option
|
|
25050
|
-
* @returns {string}
|
|
25051
|
-
*/
|
|
25052
|
-
optionTerm(option) {
|
|
25053
|
-
return option.flags;
|
|
25054
|
-
}
|
|
25055
|
-
/**
|
|
25056
|
-
* Get the argument term to show in the list of arguments.
|
|
25057
|
-
*
|
|
25058
|
-
* @param {Argument} argument
|
|
25059
|
-
* @returns {string}
|
|
25060
|
-
*/
|
|
25061
|
-
argumentTerm(argument) {
|
|
25062
|
-
return argument.name();
|
|
25063
|
-
}
|
|
25064
|
-
/**
|
|
25065
|
-
* Get the longest command term length.
|
|
25066
|
-
*
|
|
25067
|
-
* @param {Command} cmd
|
|
25068
|
-
* @param {Help} helper
|
|
25069
|
-
* @returns {number}
|
|
25070
|
-
*/
|
|
25071
|
-
longestSubcommandTermLength(cmd, helper) {
|
|
25072
|
-
return helper.visibleCommands(cmd).reduce((max, command) => {
|
|
25073
|
-
return Math.max(
|
|
25074
|
-
max,
|
|
25075
|
-
this.displayWidth(
|
|
25076
|
-
helper.styleSubcommandTerm(helper.subcommandTerm(command))
|
|
25077
|
-
)
|
|
25078
|
-
);
|
|
25079
|
-
}, 0);
|
|
25080
|
-
}
|
|
25081
|
-
/**
|
|
25082
|
-
* Get the longest option term length.
|
|
25083
|
-
*
|
|
25084
|
-
* @param {Command} cmd
|
|
25085
|
-
* @param {Help} helper
|
|
25086
|
-
* @returns {number}
|
|
25087
|
-
*/
|
|
25088
|
-
longestOptionTermLength(cmd, helper) {
|
|
25089
|
-
return helper.visibleOptions(cmd).reduce((max, option) => {
|
|
25090
|
-
return Math.max(
|
|
25091
|
-
max,
|
|
25092
|
-
this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option)))
|
|
25093
|
-
);
|
|
25094
|
-
}, 0);
|
|
25095
|
-
}
|
|
25096
|
-
/**
|
|
25097
|
-
* Get the longest global option term length.
|
|
25098
|
-
*
|
|
25099
|
-
* @param {Command} cmd
|
|
25100
|
-
* @param {Help} helper
|
|
25101
|
-
* @returns {number}
|
|
25102
|
-
*/
|
|
25103
|
-
longestGlobalOptionTermLength(cmd, helper) {
|
|
25104
|
-
return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
|
|
25105
|
-
return Math.max(
|
|
25106
|
-
max,
|
|
25107
|
-
this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option)))
|
|
25108
|
-
);
|
|
25109
|
-
}, 0);
|
|
25110
|
-
}
|
|
25111
|
-
/**
|
|
25112
|
-
* Get the longest argument term length.
|
|
25113
|
-
*
|
|
25114
|
-
* @param {Command} cmd
|
|
25115
|
-
* @param {Help} helper
|
|
25116
|
-
* @returns {number}
|
|
25117
|
-
*/
|
|
25118
|
-
longestArgumentTermLength(cmd, helper) {
|
|
25119
|
-
return helper.visibleArguments(cmd).reduce((max, argument) => {
|
|
25120
|
-
return Math.max(
|
|
25121
|
-
max,
|
|
25122
|
-
this.displayWidth(
|
|
25123
|
-
helper.styleArgumentTerm(helper.argumentTerm(argument))
|
|
25124
|
-
)
|
|
25125
|
-
);
|
|
25126
|
-
}, 0);
|
|
25127
|
-
}
|
|
25128
|
-
/**
|
|
25129
|
-
* Get the command usage to be displayed at the top of the built-in help.
|
|
25130
|
-
*
|
|
25131
|
-
* @param {Command} cmd
|
|
25132
|
-
* @returns {string}
|
|
25133
|
-
*/
|
|
25134
|
-
commandUsage(cmd) {
|
|
25135
|
-
let cmdName = cmd._name;
|
|
25136
|
-
if (cmd._aliases[0]) {
|
|
25137
|
-
cmdName = cmdName + "|" + cmd._aliases[0];
|
|
25138
|
-
}
|
|
25139
|
-
let ancestorCmdNames = "";
|
|
25140
|
-
for (let ancestorCmd = cmd.parent; ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
25141
|
-
ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
|
|
25142
|
-
}
|
|
25143
|
-
return ancestorCmdNames + cmdName + " " + cmd.usage();
|
|
25144
|
-
}
|
|
25145
|
-
/**
|
|
25146
|
-
* Get the description for the command.
|
|
25147
|
-
*
|
|
25148
|
-
* @param {Command} cmd
|
|
25149
|
-
* @returns {string}
|
|
25150
|
-
*/
|
|
25151
|
-
commandDescription(cmd) {
|
|
25152
|
-
return cmd.description();
|
|
25153
|
-
}
|
|
25154
|
-
/**
|
|
25155
|
-
* Get the subcommand summary to show in the list of subcommands.
|
|
25156
|
-
* (Fallback to description for backwards compatibility.)
|
|
25157
|
-
*
|
|
25158
|
-
* @param {Command} cmd
|
|
25159
|
-
* @returns {string}
|
|
25160
|
-
*/
|
|
25161
|
-
subcommandDescription(cmd) {
|
|
25162
|
-
return cmd.summary() || cmd.description();
|
|
25163
|
-
}
|
|
25164
|
-
/**
|
|
25165
|
-
* Get the option description to show in the list of options.
|
|
25166
|
-
*
|
|
25167
|
-
* @param {Option} option
|
|
25168
|
-
* @return {string}
|
|
25169
|
-
*/
|
|
25170
|
-
optionDescription(option) {
|
|
25171
|
-
const extraInfo = [];
|
|
25172
|
-
if (option.argChoices) {
|
|
25173
|
-
extraInfo.push(
|
|
25174
|
-
// use stringify to match the display of the default value
|
|
25175
|
-
`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`
|
|
25176
|
-
);
|
|
25177
|
-
}
|
|
25178
|
-
if (option.defaultValue !== void 0) {
|
|
25179
|
-
const showDefault = option.required || option.optional || option.isBoolean() && typeof option.defaultValue === "boolean";
|
|
25180
|
-
if (showDefault) {
|
|
25181
|
-
extraInfo.push(
|
|
25182
|
-
`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`
|
|
25183
|
-
);
|
|
25184
|
-
}
|
|
25185
|
-
}
|
|
25186
|
-
if (option.presetArg !== void 0 && option.optional) {
|
|
25187
|
-
extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
|
|
25188
|
-
}
|
|
25189
|
-
if (option.envVar !== void 0) {
|
|
25190
|
-
extraInfo.push(`env: ${option.envVar}`);
|
|
25191
|
-
}
|
|
25192
|
-
if (extraInfo.length > 0) {
|
|
25193
|
-
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
25194
|
-
if (option.description) {
|
|
25195
|
-
return `${option.description} ${extraDescription}`;
|
|
25196
|
-
}
|
|
25197
|
-
return extraDescription;
|
|
25198
|
-
}
|
|
25199
|
-
return option.description;
|
|
25200
|
-
}
|
|
25201
|
-
/**
|
|
25202
|
-
* Get the argument description to show in the list of arguments.
|
|
25203
|
-
*
|
|
25204
|
-
* @param {Argument} argument
|
|
25205
|
-
* @return {string}
|
|
25206
|
-
*/
|
|
25207
|
-
argumentDescription(argument) {
|
|
25208
|
-
const extraInfo = [];
|
|
25209
|
-
if (argument.argChoices) {
|
|
25210
|
-
extraInfo.push(
|
|
25211
|
-
// use stringify to match the display of the default value
|
|
25212
|
-
`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`
|
|
25213
|
-
);
|
|
25214
|
-
}
|
|
25215
|
-
if (argument.defaultValue !== void 0) {
|
|
25216
|
-
extraInfo.push(
|
|
25217
|
-
`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`
|
|
25218
|
-
);
|
|
25219
|
-
}
|
|
25220
|
-
if (extraInfo.length > 0) {
|
|
25221
|
-
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
25222
|
-
if (argument.description) {
|
|
25223
|
-
return `${argument.description} ${extraDescription}`;
|
|
25224
|
-
}
|
|
25225
|
-
return extraDescription;
|
|
25226
|
-
}
|
|
25227
|
-
return argument.description;
|
|
25228
|
-
}
|
|
25229
|
-
/**
|
|
25230
|
-
* Format a list of items, given a heading and an array of formatted items.
|
|
25231
|
-
*
|
|
25232
|
-
* @param {string} heading
|
|
25233
|
-
* @param {string[]} items
|
|
25234
|
-
* @param {Help} helper
|
|
25235
|
-
* @returns string[]
|
|
25236
|
-
*/
|
|
25237
|
-
formatItemList(heading, items, helper) {
|
|
25238
|
-
if (items.length === 0) return [];
|
|
25239
|
-
return [helper.styleTitle(heading), ...items, ""];
|
|
25240
|
-
}
|
|
25241
|
-
/**
|
|
25242
|
-
* Group items by their help group heading.
|
|
25243
|
-
*
|
|
25244
|
-
* @param {Command[] | Option[]} unsortedItems
|
|
25245
|
-
* @param {Command[] | Option[]} visibleItems
|
|
25246
|
-
* @param {Function} getGroup
|
|
25247
|
-
* @returns {Map<string, Command[] | Option[]>}
|
|
25248
|
-
*/
|
|
25249
|
-
groupItems(unsortedItems, visibleItems, getGroup) {
|
|
25250
|
-
const result = /* @__PURE__ */ new Map();
|
|
25251
|
-
unsortedItems.forEach((item) => {
|
|
25252
|
-
const group = getGroup(item);
|
|
25253
|
-
if (!result.has(group)) result.set(group, []);
|
|
25254
|
-
});
|
|
25255
|
-
visibleItems.forEach((item) => {
|
|
25256
|
-
const group = getGroup(item);
|
|
25257
|
-
if (!result.has(group)) {
|
|
25258
|
-
result.set(group, []);
|
|
25259
|
-
}
|
|
25260
|
-
result.get(group).push(item);
|
|
25261
|
-
});
|
|
25262
|
-
return result;
|
|
25263
|
-
}
|
|
25264
|
-
/**
|
|
25265
|
-
* Generate the built-in help text.
|
|
25266
|
-
*
|
|
25267
|
-
* @param {Command} cmd
|
|
25268
|
-
* @param {Help} helper
|
|
25269
|
-
* @returns {string}
|
|
25270
|
-
*/
|
|
25271
|
-
formatHelp(cmd, helper) {
|
|
25272
|
-
const termWidth = helper.padWidth(cmd, helper);
|
|
25273
|
-
const helpWidth = helper.helpWidth ?? 80;
|
|
25274
|
-
function callFormatItem(term, description) {
|
|
25275
|
-
return helper.formatItem(term, termWidth, description, helper);
|
|
25276
|
-
}
|
|
25277
|
-
let output3 = [
|
|
25278
|
-
`${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`,
|
|
25279
|
-
""
|
|
25280
|
-
];
|
|
25281
|
-
const commandDescription = helper.commandDescription(cmd);
|
|
25282
|
-
if (commandDescription.length > 0) {
|
|
25283
|
-
output3 = output3.concat([
|
|
25284
|
-
helper.boxWrap(
|
|
25285
|
-
helper.styleCommandDescription(commandDescription),
|
|
25286
|
-
helpWidth
|
|
25287
|
-
),
|
|
25288
|
-
""
|
|
25289
|
-
]);
|
|
25290
|
-
}
|
|
25291
|
-
const argumentList = helper.visibleArguments(cmd).map((argument) => {
|
|
25292
|
-
return callFormatItem(
|
|
25293
|
-
helper.styleArgumentTerm(helper.argumentTerm(argument)),
|
|
25294
|
-
helper.styleArgumentDescription(helper.argumentDescription(argument))
|
|
25295
|
-
);
|
|
25296
|
-
});
|
|
25297
|
-
output3 = output3.concat(
|
|
25298
|
-
this.formatItemList("Arguments:", argumentList, helper)
|
|
25299
|
-
);
|
|
25300
|
-
const optionGroups = this.groupItems(
|
|
25301
|
-
cmd.options,
|
|
25302
|
-
helper.visibleOptions(cmd),
|
|
25303
|
-
(option) => option.helpGroupHeading ?? "Options:"
|
|
25304
|
-
);
|
|
25305
|
-
optionGroups.forEach((options, group) => {
|
|
25306
|
-
const optionList = options.map((option) => {
|
|
25307
|
-
return callFormatItem(
|
|
25308
|
-
helper.styleOptionTerm(helper.optionTerm(option)),
|
|
25309
|
-
helper.styleOptionDescription(helper.optionDescription(option))
|
|
25310
|
-
);
|
|
25311
|
-
});
|
|
25312
|
-
output3 = output3.concat(this.formatItemList(group, optionList, helper));
|
|
25313
|
-
});
|
|
25314
|
-
if (helper.showGlobalOptions) {
|
|
25315
|
-
const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
|
|
25316
|
-
return callFormatItem(
|
|
25317
|
-
helper.styleOptionTerm(helper.optionTerm(option)),
|
|
25318
|
-
helper.styleOptionDescription(helper.optionDescription(option))
|
|
25319
|
-
);
|
|
25320
|
-
});
|
|
25321
|
-
output3 = output3.concat(
|
|
25322
|
-
this.formatItemList("Global Options:", globalOptionList, helper)
|
|
25323
|
-
);
|
|
25324
|
-
}
|
|
25325
|
-
const commandGroups = this.groupItems(
|
|
25326
|
-
cmd.commands,
|
|
25327
|
-
helper.visibleCommands(cmd),
|
|
25328
|
-
(sub) => sub.helpGroup() || "Commands:"
|
|
25329
|
-
);
|
|
25330
|
-
commandGroups.forEach((commands, group) => {
|
|
25331
|
-
const commandList = commands.map((sub) => {
|
|
25332
|
-
return callFormatItem(
|
|
25333
|
-
helper.styleSubcommandTerm(helper.subcommandTerm(sub)),
|
|
25334
|
-
helper.styleSubcommandDescription(helper.subcommandDescription(sub))
|
|
25335
|
-
);
|
|
25336
|
-
});
|
|
25337
|
-
output3 = output3.concat(this.formatItemList(group, commandList, helper));
|
|
25338
|
-
});
|
|
25339
|
-
return output3.join("\n");
|
|
25340
|
-
}
|
|
25341
|
-
/**
|
|
25342
|
-
* Return display width of string, ignoring ANSI escape sequences. Used in padding and wrapping calculations.
|
|
25343
|
-
*
|
|
25344
|
-
* @param {string} str
|
|
25345
|
-
* @returns {number}
|
|
25346
|
-
*/
|
|
25347
|
-
displayWidth(str3) {
|
|
25348
|
-
return stripColor(str3).length;
|
|
25349
|
-
}
|
|
25350
|
-
/**
|
|
25351
|
-
* Style the title for displaying in the help. Called with 'Usage:', 'Options:', etc.
|
|
25352
|
-
*
|
|
25353
|
-
* @param {string} str
|
|
25354
|
-
* @returns {string}
|
|
25355
|
-
*/
|
|
25356
|
-
styleTitle(str3) {
|
|
25357
|
-
return str3;
|
|
25358
|
-
}
|
|
25359
|
-
styleUsage(str3) {
|
|
25360
|
-
return str3.split(" ").map((word) => {
|
|
25361
|
-
if (word === "[options]") return this.styleOptionText(word);
|
|
25362
|
-
if (word === "[command]") return this.styleSubcommandText(word);
|
|
25363
|
-
if (word[0] === "[" || word[0] === "<")
|
|
25364
|
-
return this.styleArgumentText(word);
|
|
25365
|
-
return this.styleCommandText(word);
|
|
25366
|
-
}).join(" ");
|
|
25367
|
-
}
|
|
25368
|
-
styleCommandDescription(str3) {
|
|
25369
|
-
return this.styleDescriptionText(str3);
|
|
25370
|
-
}
|
|
25371
|
-
styleOptionDescription(str3) {
|
|
25372
|
-
return this.styleDescriptionText(str3);
|
|
25373
|
-
}
|
|
25374
|
-
styleSubcommandDescription(str3) {
|
|
25375
|
-
return this.styleDescriptionText(str3);
|
|
25376
|
-
}
|
|
25377
|
-
styleArgumentDescription(str3) {
|
|
25378
|
-
return this.styleDescriptionText(str3);
|
|
25379
|
-
}
|
|
25380
|
-
styleDescriptionText(str3) {
|
|
25381
|
-
return str3;
|
|
25382
|
-
}
|
|
25383
|
-
styleOptionTerm(str3) {
|
|
25384
|
-
return this.styleOptionText(str3);
|
|
25385
|
-
}
|
|
25386
|
-
styleSubcommandTerm(str3) {
|
|
25387
|
-
return str3.split(" ").map((word) => {
|
|
25388
|
-
if (word === "[options]") return this.styleOptionText(word);
|
|
25389
|
-
if (word[0] === "[" || word[0] === "<")
|
|
25390
|
-
return this.styleArgumentText(word);
|
|
25391
|
-
return this.styleSubcommandText(word);
|
|
25392
|
-
}).join(" ");
|
|
25393
|
-
}
|
|
25394
|
-
styleArgumentTerm(str3) {
|
|
25395
|
-
return this.styleArgumentText(str3);
|
|
25396
|
-
}
|
|
25397
|
-
styleOptionText(str3) {
|
|
25398
|
-
return str3;
|
|
25399
|
-
}
|
|
25400
|
-
styleArgumentText(str3) {
|
|
25401
|
-
return str3;
|
|
25402
|
-
}
|
|
25403
|
-
styleSubcommandText(str3) {
|
|
25404
|
-
return str3;
|
|
25405
|
-
}
|
|
25406
|
-
styleCommandText(str3) {
|
|
25407
|
-
return str3;
|
|
25408
|
-
}
|
|
25409
|
-
/**
|
|
25410
|
-
* Calculate the pad width from the maximum term length.
|
|
25411
|
-
*
|
|
25412
|
-
* @param {Command} cmd
|
|
25413
|
-
* @param {Help} helper
|
|
25414
|
-
* @returns {number}
|
|
25415
|
-
*/
|
|
25416
|
-
padWidth(cmd, helper) {
|
|
25417
|
-
return Math.max(
|
|
25418
|
-
helper.longestOptionTermLength(cmd, helper),
|
|
25419
|
-
helper.longestGlobalOptionTermLength(cmd, helper),
|
|
25420
|
-
helper.longestSubcommandTermLength(cmd, helper),
|
|
25421
|
-
helper.longestArgumentTermLength(cmd, helper)
|
|
25422
|
-
);
|
|
25423
|
-
}
|
|
25424
|
-
/**
|
|
25425
|
-
* Detect manually wrapped and indented strings by checking for line break followed by whitespace.
|
|
25426
|
-
*
|
|
25427
|
-
* @param {string} str
|
|
25428
|
-
* @returns {boolean}
|
|
25429
|
-
*/
|
|
25430
|
-
preformatted(str3) {
|
|
25431
|
-
return /\n[^\S\r\n]/.test(str3);
|
|
25432
|
-
}
|
|
25433
|
-
/**
|
|
25434
|
-
* Format the "item", which consists of a term and description. Pad the term and wrap the description, indenting the following lines.
|
|
25435
|
-
*
|
|
25436
|
-
* So "TTT", 5, "DDD DDDD DD DDD" might be formatted for this.helpWidth=17 like so:
|
|
25437
|
-
* TTT DDD DDDD
|
|
25438
|
-
* DD DDD
|
|
25439
|
-
*
|
|
25440
|
-
* @param {string} term
|
|
25441
|
-
* @param {number} termWidth
|
|
25442
|
-
* @param {string} description
|
|
25443
|
-
* @param {Help} helper
|
|
25444
|
-
* @returns {string}
|
|
25445
|
-
*/
|
|
25446
|
-
formatItem(term, termWidth, description, helper) {
|
|
25447
|
-
const itemIndent = 2;
|
|
25448
|
-
const itemIndentStr = " ".repeat(itemIndent);
|
|
25449
|
-
if (!description) return itemIndentStr + term;
|
|
25450
|
-
const paddedTerm = term.padEnd(
|
|
25451
|
-
termWidth + term.length - helper.displayWidth(term)
|
|
25452
|
-
);
|
|
25453
|
-
const spacerWidth = 2;
|
|
25454
|
-
const helpWidth = this.helpWidth ?? 80;
|
|
25455
|
-
const remainingWidth = helpWidth - termWidth - spacerWidth - itemIndent;
|
|
25456
|
-
let formattedDescription;
|
|
25457
|
-
if (remainingWidth < this.minWidthToWrap || helper.preformatted(description)) {
|
|
25458
|
-
formattedDescription = description;
|
|
25459
|
-
} else {
|
|
25460
|
-
const wrappedDescription = helper.boxWrap(description, remainingWidth);
|
|
25461
|
-
formattedDescription = wrappedDescription.replace(
|
|
25462
|
-
/\n/g,
|
|
25463
|
-
"\n" + " ".repeat(termWidth + spacerWidth)
|
|
25464
|
-
);
|
|
25465
|
-
}
|
|
25466
|
-
return itemIndentStr + paddedTerm + " ".repeat(spacerWidth) + formattedDescription.replace(/\n/g, `
|
|
25467
|
-
${itemIndentStr}`);
|
|
25468
|
-
}
|
|
25469
|
-
/**
|
|
25470
|
-
* Wrap a string at whitespace, preserving existing line breaks.
|
|
25471
|
-
* Wrapping is skipped if the width is less than `minWidthToWrap`.
|
|
25472
|
-
*
|
|
25473
|
-
* @param {string} str
|
|
25474
|
-
* @param {number} width
|
|
25475
|
-
* @returns {string}
|
|
25476
|
-
*/
|
|
25477
|
-
boxWrap(str3, width) {
|
|
25478
|
-
if (width < this.minWidthToWrap) return str3;
|
|
25479
|
-
const rawLines = str3.split(/\r\n|\n/);
|
|
25480
|
-
const chunkPattern = /[\s]*[^\s]+/g;
|
|
25481
|
-
const wrappedLines = [];
|
|
25482
|
-
rawLines.forEach((line) => {
|
|
25483
|
-
const chunks = line.match(chunkPattern);
|
|
25484
|
-
if (chunks === null) {
|
|
25485
|
-
wrappedLines.push("");
|
|
25486
|
-
return;
|
|
25487
|
-
}
|
|
25488
|
-
let sumChunks = [chunks.shift()];
|
|
25489
|
-
let sumWidth = this.displayWidth(sumChunks[0]);
|
|
25490
|
-
chunks.forEach((chunk) => {
|
|
25491
|
-
const visibleWidth = this.displayWidth(chunk);
|
|
25492
|
-
if (sumWidth + visibleWidth <= width) {
|
|
25493
|
-
sumChunks.push(chunk);
|
|
25494
|
-
sumWidth += visibleWidth;
|
|
25495
|
-
return;
|
|
25496
|
-
}
|
|
25497
|
-
wrappedLines.push(sumChunks.join(""));
|
|
25498
|
-
const nextChunk = chunk.trimStart();
|
|
25499
|
-
sumChunks = [nextChunk];
|
|
25500
|
-
sumWidth = this.displayWidth(nextChunk);
|
|
25501
|
-
});
|
|
25502
|
-
wrappedLines.push(sumChunks.join(""));
|
|
25503
|
-
});
|
|
25504
|
-
return wrappedLines.join("\n");
|
|
25505
|
-
}
|
|
25506
|
-
};
|
|
25507
|
-
function stripColor(str3) {
|
|
25508
|
-
const sgrPattern = /\x1b\[\d*(;\d*)*m/g;
|
|
25509
|
-
return str3.replace(sgrPattern, "");
|
|
25510
|
-
}
|
|
25511
|
-
exports2.Help = Help2;
|
|
25512
|
-
exports2.stripColor = stripColor;
|
|
25513
|
-
}
|
|
25514
|
-
});
|
|
25515
|
-
|
|
25516
|
-
// ../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/option.js
|
|
25517
|
-
var require_option = __commonJS({
|
|
25518
|
-
"../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/option.js"(exports2) {
|
|
25519
|
-
"use strict";
|
|
25520
|
-
var { InvalidArgumentError: InvalidArgumentError2 } = require_error();
|
|
25521
|
-
var Option2 = class {
|
|
25522
|
-
/**
|
|
25523
|
-
* Initialize a new `Option` with the given `flags` and `description`.
|
|
25524
|
-
*
|
|
25525
|
-
* @param {string} flags
|
|
25526
|
-
* @param {string} [description]
|
|
25527
|
-
*/
|
|
25528
|
-
constructor(flags, description) {
|
|
25529
|
-
this.flags = flags;
|
|
25530
|
-
this.description = description || "";
|
|
25531
|
-
this.required = flags.includes("<");
|
|
25532
|
-
this.optional = flags.includes("[");
|
|
25533
|
-
this.variadic = /\w\.\.\.[>\]]$/.test(flags);
|
|
25534
|
-
this.mandatory = false;
|
|
25535
|
-
const optionFlags = splitOptionFlags(flags);
|
|
25536
|
-
this.short = optionFlags.shortFlag;
|
|
25537
|
-
this.long = optionFlags.longFlag;
|
|
25538
|
-
this.negate = false;
|
|
25539
|
-
if (this.long) {
|
|
25540
|
-
this.negate = this.long.startsWith("--no-");
|
|
25541
|
-
}
|
|
25542
|
-
this.defaultValue = void 0;
|
|
25543
|
-
this.defaultValueDescription = void 0;
|
|
25544
|
-
this.presetArg = void 0;
|
|
25545
|
-
this.envVar = void 0;
|
|
25546
|
-
this.parseArg = void 0;
|
|
25547
|
-
this.hidden = false;
|
|
25548
|
-
this.argChoices = void 0;
|
|
25549
|
-
this.conflictsWith = [];
|
|
25550
|
-
this.implied = void 0;
|
|
25551
|
-
this.helpGroupHeading = void 0;
|
|
25552
|
-
}
|
|
25553
|
-
/**
|
|
25554
|
-
* Set the default value, and optionally supply the description to be displayed in the help.
|
|
25555
|
-
*
|
|
25556
|
-
* @param {*} value
|
|
25557
|
-
* @param {string} [description]
|
|
25558
|
-
* @return {Option}
|
|
25559
|
-
*/
|
|
25560
|
-
default(value, description) {
|
|
25561
|
-
this.defaultValue = value;
|
|
25562
|
-
this.defaultValueDescription = description;
|
|
25563
|
-
return this;
|
|
25564
|
-
}
|
|
25565
|
-
/**
|
|
25566
|
-
* Preset to use when option used without option-argument, especially optional but also boolean and negated.
|
|
25567
|
-
* The custom processing (parseArg) is called.
|
|
25568
|
-
*
|
|
25569
|
-
* @example
|
|
25570
|
-
* new Option('--color').default('GREYSCALE').preset('RGB');
|
|
25571
|
-
* new Option('--donate [amount]').preset('20').argParser(parseFloat);
|
|
25572
|
-
*
|
|
25573
|
-
* @param {*} arg
|
|
25574
|
-
* @return {Option}
|
|
25575
|
-
*/
|
|
25576
|
-
preset(arg) {
|
|
25577
|
-
this.presetArg = arg;
|
|
25578
|
-
return this;
|
|
25579
|
-
}
|
|
25580
|
-
/**
|
|
25581
|
-
* Add option name(s) that conflict with this option.
|
|
25582
|
-
* An error will be displayed if conflicting options are found during parsing.
|
|
25583
|
-
*
|
|
25584
|
-
* @example
|
|
25585
|
-
* new Option('--rgb').conflicts('cmyk');
|
|
25586
|
-
* new Option('--js').conflicts(['ts', 'jsx']);
|
|
25587
|
-
*
|
|
25588
|
-
* @param {(string | string[])} names
|
|
25589
|
-
* @return {Option}
|
|
25590
|
-
*/
|
|
25591
|
-
conflicts(names) {
|
|
25592
|
-
this.conflictsWith = this.conflictsWith.concat(names);
|
|
25593
|
-
return this;
|
|
25594
|
-
}
|
|
25595
|
-
/**
|
|
25596
|
-
* Specify implied option values for when this option is set and the implied options are not.
|
|
25597
|
-
*
|
|
25598
|
-
* The custom processing (parseArg) is not called on the implied values.
|
|
25599
|
-
*
|
|
25600
|
-
* @example
|
|
25601
|
-
* program
|
|
25602
|
-
* .addOption(new Option('--log', 'write logging information to file'))
|
|
25603
|
-
* .addOption(new Option('--trace', 'log extra details').implies({ log: 'trace.txt' }));
|
|
25604
|
-
*
|
|
25605
|
-
* @param {object} impliedOptionValues
|
|
25606
|
-
* @return {Option}
|
|
25607
|
-
*/
|
|
25608
|
-
implies(impliedOptionValues) {
|
|
25609
|
-
let newImplied = impliedOptionValues;
|
|
25610
|
-
if (typeof impliedOptionValues === "string") {
|
|
25611
|
-
newImplied = { [impliedOptionValues]: true };
|
|
25612
|
-
}
|
|
25613
|
-
this.implied = Object.assign(this.implied || {}, newImplied);
|
|
25614
|
-
return this;
|
|
25615
|
-
}
|
|
25616
|
-
/**
|
|
25617
|
-
* Set environment variable to check for option value.
|
|
25618
|
-
*
|
|
25619
|
-
* An environment variable is only used if when processed the current option value is
|
|
25620
|
-
* undefined, or the source of the current value is 'default' or 'config' or 'env'.
|
|
25621
|
-
*
|
|
25622
|
-
* @param {string} name
|
|
25623
|
-
* @return {Option}
|
|
25624
|
-
*/
|
|
25625
|
-
env(name) {
|
|
25626
|
-
this.envVar = name;
|
|
25627
|
-
return this;
|
|
25628
|
-
}
|
|
25629
|
-
/**
|
|
25630
|
-
* Set the custom handler for processing CLI option arguments into option values.
|
|
25631
|
-
*
|
|
25632
|
-
* @param {Function} [fn]
|
|
25633
|
-
* @return {Option}
|
|
25634
|
-
*/
|
|
25635
|
-
argParser(fn) {
|
|
25636
|
-
this.parseArg = fn;
|
|
25637
|
-
return this;
|
|
25638
|
-
}
|
|
25639
|
-
/**
|
|
25640
|
-
* Whether the option is mandatory and must have a value after parsing.
|
|
25641
|
-
*
|
|
25642
|
-
* @param {boolean} [mandatory=true]
|
|
25643
|
-
* @return {Option}
|
|
25644
|
-
*/
|
|
25645
|
-
makeOptionMandatory(mandatory = true) {
|
|
25646
|
-
this.mandatory = !!mandatory;
|
|
25647
|
-
return this;
|
|
25648
|
-
}
|
|
25649
|
-
/**
|
|
25650
|
-
* Hide option in help.
|
|
25651
|
-
*
|
|
25652
|
-
* @param {boolean} [hide=true]
|
|
25653
|
-
* @return {Option}
|
|
25654
|
-
*/
|
|
25655
|
-
hideHelp(hide = true) {
|
|
25656
|
-
this.hidden = !!hide;
|
|
25657
|
-
return this;
|
|
25658
|
-
}
|
|
25659
|
-
/**
|
|
25660
|
-
* @package
|
|
25661
|
-
*/
|
|
25662
|
-
_collectValue(value, previous) {
|
|
25663
|
-
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
25664
|
-
return [value];
|
|
25665
|
-
}
|
|
25666
|
-
previous.push(value);
|
|
25667
|
-
return previous;
|
|
25668
|
-
}
|
|
25669
|
-
/**
|
|
25670
|
-
* Only allow option value to be one of choices.
|
|
25671
|
-
*
|
|
25672
|
-
* @param {string[]} values
|
|
25673
|
-
* @return {Option}
|
|
25674
|
-
*/
|
|
25675
|
-
choices(values) {
|
|
25676
|
-
this.argChoices = values.slice();
|
|
25677
|
-
this.parseArg = (arg, previous) => {
|
|
25678
|
-
if (!this.argChoices.includes(arg)) {
|
|
25679
|
-
throw new InvalidArgumentError2(
|
|
25680
|
-
`Allowed choices are ${this.argChoices.join(", ")}.`
|
|
25681
|
-
);
|
|
25682
|
-
}
|
|
25683
|
-
if (this.variadic) {
|
|
25684
|
-
return this._collectValue(arg, previous);
|
|
25685
|
-
}
|
|
25686
|
-
return arg;
|
|
25687
|
-
};
|
|
25688
|
-
return this;
|
|
25689
|
-
}
|
|
25690
|
-
/**
|
|
25691
|
-
* Return option name.
|
|
25692
|
-
*
|
|
25693
|
-
* @return {string}
|
|
25694
|
-
*/
|
|
25695
|
-
name() {
|
|
25696
|
-
if (this.long) {
|
|
25697
|
-
return this.long.replace(/^--/, "");
|
|
25698
|
-
}
|
|
25699
|
-
return this.short.replace(/^-/, "");
|
|
25700
|
-
}
|
|
25701
|
-
/**
|
|
25702
|
-
* Return option name, in a camelcase format that can be used
|
|
25703
|
-
* as an object attribute key.
|
|
25704
|
-
*
|
|
25705
|
-
* @return {string}
|
|
25706
|
-
*/
|
|
25707
|
-
attributeName() {
|
|
25708
|
-
if (this.negate) {
|
|
25709
|
-
return camelcase(this.name().replace(/^no-/, ""));
|
|
25710
|
-
}
|
|
25711
|
-
return camelcase(this.name());
|
|
25712
|
-
}
|
|
25713
|
-
/**
|
|
25714
|
-
* Set the help group heading.
|
|
25715
|
-
*
|
|
25716
|
-
* @param {string} heading
|
|
25717
|
-
* @return {Option}
|
|
25718
|
-
*/
|
|
25719
|
-
helpGroup(heading) {
|
|
25720
|
-
this.helpGroupHeading = heading;
|
|
25721
|
-
return this;
|
|
25722
|
-
}
|
|
25723
|
-
/**
|
|
25724
|
-
* Check if `arg` matches the short or long flag.
|
|
25725
|
-
*
|
|
25726
|
-
* @param {string} arg
|
|
25727
|
-
* @return {boolean}
|
|
25728
|
-
* @package
|
|
25729
|
-
*/
|
|
25730
|
-
is(arg) {
|
|
25731
|
-
return this.short === arg || this.long === arg;
|
|
25732
|
-
}
|
|
25733
|
-
/**
|
|
25734
|
-
* Return whether a boolean option.
|
|
25735
|
-
*
|
|
25736
|
-
* Options are one of boolean, negated, required argument, or optional argument.
|
|
25737
|
-
*
|
|
25738
|
-
* @return {boolean}
|
|
25739
|
-
* @package
|
|
25740
|
-
*/
|
|
25741
|
-
isBoolean() {
|
|
25742
|
-
return !this.required && !this.optional && !this.negate;
|
|
25743
|
-
}
|
|
25744
|
-
};
|
|
25745
|
-
var DualOptions = class {
|
|
25746
|
-
/**
|
|
25747
|
-
* @param {Option[]} options
|
|
25748
|
-
*/
|
|
25749
|
-
constructor(options) {
|
|
25750
|
-
this.positiveOptions = /* @__PURE__ */ new Map();
|
|
25751
|
-
this.negativeOptions = /* @__PURE__ */ new Map();
|
|
25752
|
-
this.dualOptions = /* @__PURE__ */ new Set();
|
|
25753
|
-
options.forEach((option) => {
|
|
25754
|
-
if (option.negate) {
|
|
25755
|
-
this.negativeOptions.set(option.attributeName(), option);
|
|
25756
|
-
} else {
|
|
25757
|
-
this.positiveOptions.set(option.attributeName(), option);
|
|
25758
|
-
}
|
|
25759
|
-
});
|
|
25760
|
-
this.negativeOptions.forEach((value, key) => {
|
|
25761
|
-
if (this.positiveOptions.has(key)) {
|
|
25762
|
-
this.dualOptions.add(key);
|
|
25763
|
-
}
|
|
25764
|
-
});
|
|
25765
|
-
}
|
|
25766
|
-
/**
|
|
25767
|
-
* Did the value come from the option, and not from possible matching dual option?
|
|
25768
|
-
*
|
|
25769
|
-
* @param {*} value
|
|
25770
|
-
* @param {Option} option
|
|
25771
|
-
* @returns {boolean}
|
|
25772
|
-
*/
|
|
25773
|
-
valueFromOption(value, option) {
|
|
25774
|
-
const optionKey = option.attributeName();
|
|
25775
|
-
if (!this.dualOptions.has(optionKey)) return true;
|
|
25776
|
-
const preset = this.negativeOptions.get(optionKey).presetArg;
|
|
25777
|
-
const negativeValue = preset !== void 0 ? preset : false;
|
|
25778
|
-
return option.negate === (negativeValue === value);
|
|
25779
|
-
}
|
|
25780
|
-
};
|
|
25781
|
-
function camelcase(str3) {
|
|
25782
|
-
return str3.split("-").reduce((str4, word) => {
|
|
25783
|
-
return str4 + word[0].toUpperCase() + word.slice(1);
|
|
25784
|
-
});
|
|
25785
|
-
}
|
|
25786
|
-
function splitOptionFlags(flags) {
|
|
25787
|
-
let shortFlag;
|
|
25788
|
-
let longFlag;
|
|
25789
|
-
const shortFlagExp = /^-[^-]$/;
|
|
25790
|
-
const longFlagExp = /^--[^-]/;
|
|
25791
|
-
const flagParts = flags.split(/[ |,]+/).concat("guard");
|
|
25792
|
-
if (shortFlagExp.test(flagParts[0])) shortFlag = flagParts.shift();
|
|
25793
|
-
if (longFlagExp.test(flagParts[0])) longFlag = flagParts.shift();
|
|
25794
|
-
if (!shortFlag && shortFlagExp.test(flagParts[0]))
|
|
25795
|
-
shortFlag = flagParts.shift();
|
|
25796
|
-
if (!shortFlag && longFlagExp.test(flagParts[0])) {
|
|
25797
|
-
shortFlag = longFlag;
|
|
25798
|
-
longFlag = flagParts.shift();
|
|
25799
|
-
}
|
|
25800
|
-
if (flagParts[0].startsWith("-")) {
|
|
25801
|
-
const unsupportedFlag = flagParts[0];
|
|
25802
|
-
const baseError = `option creation failed due to '${unsupportedFlag}' in option flags '${flags}'`;
|
|
25803
|
-
if (/^-[^-][^-]/.test(unsupportedFlag))
|
|
25804
|
-
throw new Error(
|
|
25805
|
-
`${baseError}
|
|
25806
|
-
- a short flag is a single dash and a single character
|
|
25807
|
-
- either use a single dash and a single character (for a short flag)
|
|
25808
|
-
- or use a double dash for a long option (and can have two, like '--ws, --workspace')`
|
|
25809
|
-
);
|
|
25810
|
-
if (shortFlagExp.test(unsupportedFlag))
|
|
25811
|
-
throw new Error(`${baseError}
|
|
25812
|
-
- too many short flags`);
|
|
25813
|
-
if (longFlagExp.test(unsupportedFlag))
|
|
25814
|
-
throw new Error(`${baseError}
|
|
25815
|
-
- too many long flags`);
|
|
25816
|
-
throw new Error(`${baseError}
|
|
25817
|
-
- unrecognised flag format`);
|
|
25818
|
-
}
|
|
25819
|
-
if (shortFlag === void 0 && longFlag === void 0)
|
|
25820
|
-
throw new Error(
|
|
25821
|
-
`option creation failed due to no flags found in '${flags}'.`
|
|
25822
|
-
);
|
|
25823
|
-
return { shortFlag, longFlag };
|
|
25824
|
-
}
|
|
25825
|
-
exports2.Option = Option2;
|
|
25826
|
-
exports2.DualOptions = DualOptions;
|
|
25827
|
-
}
|
|
25828
|
-
});
|
|
25829
|
-
|
|
25830
|
-
// ../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/suggestSimilar.js
|
|
25831
|
-
var require_suggestSimilar = __commonJS({
|
|
25832
|
-
"../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/suggestSimilar.js"(exports2) {
|
|
25833
|
-
"use strict";
|
|
25834
|
-
var maxDistance = 3;
|
|
25835
|
-
function editDistance(a, b) {
|
|
25836
|
-
if (Math.abs(a.length - b.length) > maxDistance)
|
|
25837
|
-
return Math.max(a.length, b.length);
|
|
25838
|
-
const d = [];
|
|
25839
|
-
for (let i = 0; i <= a.length; i++) {
|
|
25840
|
-
d[i] = [i];
|
|
25841
|
-
}
|
|
25842
|
-
for (let j = 0; j <= b.length; j++) {
|
|
25843
|
-
d[0][j] = j;
|
|
25844
|
-
}
|
|
25845
|
-
for (let j = 1; j <= b.length; j++) {
|
|
25846
|
-
for (let i = 1; i <= a.length; i++) {
|
|
25847
|
-
let cost = 1;
|
|
25848
|
-
if (a[i - 1] === b[j - 1]) {
|
|
25849
|
-
cost = 0;
|
|
25850
|
-
} else {
|
|
25851
|
-
cost = 1;
|
|
25852
|
-
}
|
|
25853
|
-
d[i][j] = Math.min(
|
|
25854
|
-
d[i - 1][j] + 1,
|
|
25855
|
-
// deletion
|
|
25856
|
-
d[i][j - 1] + 1,
|
|
25857
|
-
// insertion
|
|
25858
|
-
d[i - 1][j - 1] + cost
|
|
25859
|
-
// substitution
|
|
25860
|
-
);
|
|
25861
|
-
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
|
|
25862
|
-
d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
|
|
25863
|
-
}
|
|
25864
|
-
}
|
|
25865
|
-
}
|
|
25866
|
-
return d[a.length][b.length];
|
|
25867
|
-
}
|
|
25868
|
-
function suggestSimilar(word, candidates) {
|
|
25869
|
-
if (!candidates || candidates.length === 0) return "";
|
|
25870
|
-
candidates = Array.from(new Set(candidates));
|
|
25871
|
-
const searchingOptions = word.startsWith("--");
|
|
25872
|
-
if (searchingOptions) {
|
|
25873
|
-
word = word.slice(2);
|
|
25874
|
-
candidates = candidates.map((candidate) => candidate.slice(2));
|
|
25875
|
-
}
|
|
25876
|
-
let similar = [];
|
|
25877
|
-
let bestDistance = maxDistance;
|
|
25878
|
-
const minSimilarity = 0.4;
|
|
25879
|
-
candidates.forEach((candidate) => {
|
|
25880
|
-
if (candidate.length <= 1) return;
|
|
25881
|
-
const distance = editDistance(word, candidate);
|
|
25882
|
-
const length = Math.max(word.length, candidate.length);
|
|
25883
|
-
const similarity = (length - distance) / length;
|
|
25884
|
-
if (similarity > minSimilarity) {
|
|
25885
|
-
if (distance < bestDistance) {
|
|
25886
|
-
bestDistance = distance;
|
|
25887
|
-
similar = [candidate];
|
|
25888
|
-
} else if (distance === bestDistance) {
|
|
25889
|
-
similar.push(candidate);
|
|
25890
|
-
}
|
|
25891
|
-
}
|
|
25892
|
-
});
|
|
25893
|
-
similar.sort((a, b) => a.localeCompare(b));
|
|
25894
|
-
if (searchingOptions) {
|
|
25895
|
-
similar = similar.map((candidate) => `--${candidate}`);
|
|
25896
|
-
}
|
|
25897
|
-
if (similar.length > 1) {
|
|
25898
|
-
return `
|
|
25899
|
-
(Did you mean one of ${similar.join(", ")}?)`;
|
|
25900
|
-
}
|
|
25901
|
-
if (similar.length === 1) {
|
|
25902
|
-
return `
|
|
25903
|
-
(Did you mean ${similar[0]}?)`;
|
|
25904
|
-
}
|
|
25905
|
-
return "";
|
|
25906
|
-
}
|
|
25907
|
-
exports2.suggestSimilar = suggestSimilar;
|
|
25908
|
-
}
|
|
25909
|
-
});
|
|
25910
|
-
|
|
25911
|
-
// ../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/command.js
|
|
25912
|
-
var require_command = __commonJS({
|
|
25913
|
-
"../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/command.js"(exports2) {
|
|
25914
|
-
"use strict";
|
|
25915
|
-
var EventEmitter = __require("events").EventEmitter;
|
|
25916
|
-
var childProcess = __require("child_process");
|
|
25917
|
-
var path19 = __require("path");
|
|
25918
|
-
var fs19 = __require("fs");
|
|
25919
|
-
var process2 = __require("process");
|
|
25920
|
-
var { Argument: Argument2, humanReadableArgName } = require_argument();
|
|
25921
|
-
var { CommanderError: CommanderError2 } = require_error();
|
|
25922
|
-
var { Help: Help2, stripColor } = require_help();
|
|
25923
|
-
var { Option: Option2, DualOptions } = require_option();
|
|
25924
|
-
var { suggestSimilar } = require_suggestSimilar();
|
|
25925
|
-
var Command2 = class _Command extends EventEmitter {
|
|
25926
|
-
/**
|
|
25927
|
-
* Initialize a new `Command`.
|
|
25928
|
-
*
|
|
25929
|
-
* @param {string} [name]
|
|
25930
|
-
*/
|
|
25931
|
-
constructor(name) {
|
|
25932
|
-
super();
|
|
25933
|
-
this.commands = [];
|
|
25934
|
-
this.options = [];
|
|
25935
|
-
this.parent = null;
|
|
25936
|
-
this._allowUnknownOption = false;
|
|
25937
|
-
this._allowExcessArguments = false;
|
|
25938
|
-
this.registeredArguments = [];
|
|
25939
|
-
this._args = this.registeredArguments;
|
|
25940
|
-
this.args = [];
|
|
25941
|
-
this.rawArgs = [];
|
|
25942
|
-
this.processedArgs = [];
|
|
25943
|
-
this._scriptPath = null;
|
|
25944
|
-
this._name = name || "";
|
|
25945
|
-
this._optionValues = {};
|
|
25946
|
-
this._optionValueSources = {};
|
|
25947
|
-
this._storeOptionsAsProperties = false;
|
|
25948
|
-
this._actionHandler = null;
|
|
25949
|
-
this._executableHandler = false;
|
|
25950
|
-
this._executableFile = null;
|
|
25951
|
-
this._executableDir = null;
|
|
25952
|
-
this._defaultCommandName = null;
|
|
25953
|
-
this._exitCallback = null;
|
|
25954
|
-
this._aliases = [];
|
|
25955
|
-
this._combineFlagAndOptionalValue = true;
|
|
25956
|
-
this._description = "";
|
|
25957
|
-
this._summary = "";
|
|
25958
|
-
this._argsDescription = void 0;
|
|
25959
|
-
this._enablePositionalOptions = false;
|
|
25960
|
-
this._passThroughOptions = false;
|
|
25961
|
-
this._lifeCycleHooks = {};
|
|
25962
|
-
this._showHelpAfterError = false;
|
|
25963
|
-
this._showSuggestionAfterError = true;
|
|
25964
|
-
this._savedState = null;
|
|
25965
|
-
this._outputConfiguration = {
|
|
25966
|
-
writeOut: (str3) => process2.stdout.write(str3),
|
|
25967
|
-
writeErr: (str3) => process2.stderr.write(str3),
|
|
25968
|
-
outputError: (str3, write) => write(str3),
|
|
25969
|
-
getOutHelpWidth: () => process2.stdout.isTTY ? process2.stdout.columns : void 0,
|
|
25970
|
-
getErrHelpWidth: () => process2.stderr.isTTY ? process2.stderr.columns : void 0,
|
|
25971
|
-
getOutHasColors: () => useColor() ?? (process2.stdout.isTTY && process2.stdout.hasColors?.()),
|
|
25972
|
-
getErrHasColors: () => useColor() ?? (process2.stderr.isTTY && process2.stderr.hasColors?.()),
|
|
25973
|
-
stripColor: (str3) => stripColor(str3)
|
|
25974
|
-
};
|
|
25975
|
-
this._hidden = false;
|
|
25976
|
-
this._helpOption = void 0;
|
|
25977
|
-
this._addImplicitHelpCommand = void 0;
|
|
25978
|
-
this._helpCommand = void 0;
|
|
25979
|
-
this._helpConfiguration = {};
|
|
25980
|
-
this._helpGroupHeading = void 0;
|
|
25981
|
-
this._defaultCommandGroup = void 0;
|
|
25982
|
-
this._defaultOptionGroup = void 0;
|
|
25983
|
-
}
|
|
25984
|
-
/**
|
|
25985
|
-
* Copy settings that are useful to have in common across root command and subcommands.
|
|
25986
|
-
*
|
|
25987
|
-
* (Used internally when adding a command using `.command()` so subcommands inherit parent settings.)
|
|
25988
|
-
*
|
|
25989
|
-
* @param {Command} sourceCommand
|
|
25990
|
-
* @return {Command} `this` command for chaining
|
|
25991
|
-
*/
|
|
25992
|
-
copyInheritedSettings(sourceCommand) {
|
|
25993
|
-
this._outputConfiguration = sourceCommand._outputConfiguration;
|
|
25994
|
-
this._helpOption = sourceCommand._helpOption;
|
|
25995
|
-
this._helpCommand = sourceCommand._helpCommand;
|
|
25996
|
-
this._helpConfiguration = sourceCommand._helpConfiguration;
|
|
25997
|
-
this._exitCallback = sourceCommand._exitCallback;
|
|
25998
|
-
this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
|
|
25999
|
-
this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
|
|
26000
|
-
this._allowExcessArguments = sourceCommand._allowExcessArguments;
|
|
26001
|
-
this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
|
|
26002
|
-
this._showHelpAfterError = sourceCommand._showHelpAfterError;
|
|
26003
|
-
this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
|
|
26004
|
-
return this;
|
|
26005
|
-
}
|
|
26006
|
-
/**
|
|
26007
|
-
* @returns {Command[]}
|
|
26008
|
-
* @private
|
|
26009
|
-
*/
|
|
26010
|
-
_getCommandAndAncestors() {
|
|
26011
|
-
const result = [];
|
|
26012
|
-
for (let command = this; command; command = command.parent) {
|
|
26013
|
-
result.push(command);
|
|
26014
|
-
}
|
|
26015
|
-
return result;
|
|
26016
|
-
}
|
|
26017
|
-
/**
|
|
26018
|
-
* Define a command.
|
|
26019
|
-
*
|
|
26020
|
-
* There are two styles of command: pay attention to where to put the description.
|
|
26021
|
-
*
|
|
26022
|
-
* @example
|
|
26023
|
-
* // Command implemented using action handler (description is supplied separately to `.command`)
|
|
26024
|
-
* program
|
|
26025
|
-
* .command('clone <source> [destination]')
|
|
26026
|
-
* .description('clone a repository into a newly created directory')
|
|
26027
|
-
* .action((source, destination) => {
|
|
26028
|
-
* console.log('clone command called');
|
|
26029
|
-
* });
|
|
26030
|
-
*
|
|
26031
|
-
* // Command implemented using separate executable file (description is second parameter to `.command`)
|
|
26032
|
-
* program
|
|
26033
|
-
* .command('start <service>', 'start named service')
|
|
26034
|
-
* .command('stop [service]', 'stop named service, or all if no name supplied');
|
|
26035
|
-
*
|
|
26036
|
-
* @param {string} nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
|
|
26037
|
-
* @param {(object | string)} [actionOptsOrExecDesc] - configuration options (for action), or description (for executable)
|
|
26038
|
-
* @param {object} [execOpts] - configuration options (for executable)
|
|
26039
|
-
* @return {Command} returns new command for action handler, or `this` for executable command
|
|
26040
|
-
*/
|
|
26041
|
-
command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
|
|
26042
|
-
let desc = actionOptsOrExecDesc;
|
|
26043
|
-
let opts = execOpts;
|
|
26044
|
-
if (typeof desc === "object" && desc !== null) {
|
|
26045
|
-
opts = desc;
|
|
26046
|
-
desc = null;
|
|
26047
|
-
}
|
|
26048
|
-
opts = opts || {};
|
|
26049
|
-
const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
26050
|
-
const cmd = this.createCommand(name);
|
|
26051
|
-
if (desc) {
|
|
26052
|
-
cmd.description(desc);
|
|
26053
|
-
cmd._executableHandler = true;
|
|
26054
|
-
}
|
|
26055
|
-
if (opts.isDefault) this._defaultCommandName = cmd._name;
|
|
26056
|
-
cmd._hidden = !!(opts.noHelp || opts.hidden);
|
|
26057
|
-
cmd._executableFile = opts.executableFile || null;
|
|
26058
|
-
if (args) cmd.arguments(args);
|
|
26059
|
-
this._registerCommand(cmd);
|
|
26060
|
-
cmd.parent = this;
|
|
26061
|
-
cmd.copyInheritedSettings(this);
|
|
26062
|
-
if (desc) return this;
|
|
26063
|
-
return cmd;
|
|
26064
|
-
}
|
|
26065
|
-
/**
|
|
26066
|
-
* Factory routine to create a new unattached command.
|
|
26067
|
-
*
|
|
26068
|
-
* See .command() for creating an attached subcommand, which uses this routine to
|
|
26069
|
-
* create the command. You can override createCommand to customise subcommands.
|
|
26070
|
-
*
|
|
26071
|
-
* @param {string} [name]
|
|
26072
|
-
* @return {Command} new command
|
|
26073
|
-
*/
|
|
26074
|
-
createCommand(name) {
|
|
26075
|
-
return new _Command(name);
|
|
26076
|
-
}
|
|
26077
|
-
/**
|
|
26078
|
-
* You can customise the help with a subclass of Help by overriding createHelp,
|
|
26079
|
-
* or by overriding Help properties using configureHelp().
|
|
26080
|
-
*
|
|
26081
|
-
* @return {Help}
|
|
26082
|
-
*/
|
|
26083
|
-
createHelp() {
|
|
26084
|
-
return Object.assign(new Help2(), this.configureHelp());
|
|
26085
|
-
}
|
|
26086
|
-
/**
|
|
26087
|
-
* You can customise the help by overriding Help properties using configureHelp(),
|
|
26088
|
-
* or with a subclass of Help by overriding createHelp().
|
|
26089
|
-
*
|
|
26090
|
-
* @param {object} [configuration] - configuration options
|
|
26091
|
-
* @return {(Command | object)} `this` command for chaining, or stored configuration
|
|
26092
|
-
*/
|
|
26093
|
-
configureHelp(configuration) {
|
|
26094
|
-
if (configuration === void 0) return this._helpConfiguration;
|
|
26095
|
-
this._helpConfiguration = configuration;
|
|
26096
|
-
return this;
|
|
26097
|
-
}
|
|
26098
|
-
/**
|
|
26099
|
-
* The default output goes to stdout and stderr. You can customise this for special
|
|
26100
|
-
* applications. You can also customise the display of errors by overriding outputError.
|
|
26101
|
-
*
|
|
26102
|
-
* The configuration properties are all functions:
|
|
26103
|
-
*
|
|
26104
|
-
* // change how output being written, defaults to stdout and stderr
|
|
26105
|
-
* writeOut(str)
|
|
26106
|
-
* writeErr(str)
|
|
26107
|
-
* // change how output being written for errors, defaults to writeErr
|
|
26108
|
-
* outputError(str, write) // used for displaying errors and not used for displaying help
|
|
26109
|
-
* // specify width for wrapping help
|
|
26110
|
-
* getOutHelpWidth()
|
|
26111
|
-
* getErrHelpWidth()
|
|
26112
|
-
* // color support, currently only used with Help
|
|
26113
|
-
* getOutHasColors()
|
|
26114
|
-
* getErrHasColors()
|
|
26115
|
-
* stripColor() // used to remove ANSI escape codes if output does not have colors
|
|
26116
|
-
*
|
|
26117
|
-
* @param {object} [configuration] - configuration options
|
|
26118
|
-
* @return {(Command | object)} `this` command for chaining, or stored configuration
|
|
26119
|
-
*/
|
|
26120
|
-
configureOutput(configuration) {
|
|
26121
|
-
if (configuration === void 0) return this._outputConfiguration;
|
|
26122
|
-
this._outputConfiguration = {
|
|
26123
|
-
...this._outputConfiguration,
|
|
26124
|
-
...configuration
|
|
26125
|
-
};
|
|
26126
|
-
return this;
|
|
26127
|
-
}
|
|
26128
|
-
/**
|
|
26129
|
-
* Display the help or a custom message after an error occurs.
|
|
26130
|
-
*
|
|
26131
|
-
* @param {(boolean|string)} [displayHelp]
|
|
26132
|
-
* @return {Command} `this` command for chaining
|
|
26133
|
-
*/
|
|
26134
|
-
showHelpAfterError(displayHelp = true) {
|
|
26135
|
-
if (typeof displayHelp !== "string") displayHelp = !!displayHelp;
|
|
26136
|
-
this._showHelpAfterError = displayHelp;
|
|
26137
|
-
return this;
|
|
26138
|
-
}
|
|
26139
|
-
/**
|
|
26140
|
-
* Display suggestion of similar commands for unknown commands, or options for unknown options.
|
|
26141
|
-
*
|
|
26142
|
-
* @param {boolean} [displaySuggestion]
|
|
26143
|
-
* @return {Command} `this` command for chaining
|
|
26144
|
-
*/
|
|
26145
|
-
showSuggestionAfterError(displaySuggestion = true) {
|
|
26146
|
-
this._showSuggestionAfterError = !!displaySuggestion;
|
|
26147
|
-
return this;
|
|
26148
|
-
}
|
|
26149
|
-
/**
|
|
26150
|
-
* Add a prepared subcommand.
|
|
26151
|
-
*
|
|
26152
|
-
* See .command() for creating an attached subcommand which inherits settings from its parent.
|
|
26153
|
-
*
|
|
26154
|
-
* @param {Command} cmd - new subcommand
|
|
26155
|
-
* @param {object} [opts] - configuration options
|
|
26156
|
-
* @return {Command} `this` command for chaining
|
|
26157
|
-
*/
|
|
26158
|
-
addCommand(cmd, opts) {
|
|
26159
|
-
if (!cmd._name) {
|
|
26160
|
-
throw new Error(`Command passed to .addCommand() must have a name
|
|
26161
|
-
- specify the name in Command constructor or using .name()`);
|
|
26162
|
-
}
|
|
26163
|
-
opts = opts || {};
|
|
26164
|
-
if (opts.isDefault) this._defaultCommandName = cmd._name;
|
|
26165
|
-
if (opts.noHelp || opts.hidden) cmd._hidden = true;
|
|
26166
|
-
this._registerCommand(cmd);
|
|
26167
|
-
cmd.parent = this;
|
|
26168
|
-
cmd._checkForBrokenPassThrough();
|
|
26169
|
-
return this;
|
|
26170
|
-
}
|
|
26171
|
-
/**
|
|
26172
|
-
* Factory routine to create a new unattached argument.
|
|
26173
|
-
*
|
|
26174
|
-
* See .argument() for creating an attached argument, which uses this routine to
|
|
26175
|
-
* create the argument. You can override createArgument to return a custom argument.
|
|
26176
|
-
*
|
|
26177
|
-
* @param {string} name
|
|
26178
|
-
* @param {string} [description]
|
|
26179
|
-
* @return {Argument} new argument
|
|
26180
|
-
*/
|
|
26181
|
-
createArgument(name, description) {
|
|
26182
|
-
return new Argument2(name, description);
|
|
26183
|
-
}
|
|
26184
|
-
/**
|
|
26185
|
-
* Define argument syntax for command.
|
|
26186
|
-
*
|
|
26187
|
-
* The default is that the argument is required, and you can explicitly
|
|
26188
|
-
* indicate this with <> around the name. Put [] around the name for an optional argument.
|
|
26189
|
-
*
|
|
26190
|
-
* @example
|
|
26191
|
-
* program.argument('<input-file>');
|
|
26192
|
-
* program.argument('[output-file]');
|
|
26193
|
-
*
|
|
26194
|
-
* @param {string} name
|
|
26195
|
-
* @param {string} [description]
|
|
26196
|
-
* @param {(Function|*)} [parseArg] - custom argument processing function or default value
|
|
26197
|
-
* @param {*} [defaultValue]
|
|
26198
|
-
* @return {Command} `this` command for chaining
|
|
26199
|
-
*/
|
|
26200
|
-
argument(name, description, parseArg, defaultValue) {
|
|
26201
|
-
const argument = this.createArgument(name, description);
|
|
26202
|
-
if (typeof parseArg === "function") {
|
|
26203
|
-
argument.default(defaultValue).argParser(parseArg);
|
|
26204
|
-
} else {
|
|
26205
|
-
argument.default(parseArg);
|
|
26206
|
-
}
|
|
26207
|
-
this.addArgument(argument);
|
|
26208
|
-
return this;
|
|
26209
|
-
}
|
|
26210
|
-
/**
|
|
26211
|
-
* Define argument syntax for command, adding multiple at once (without descriptions).
|
|
26212
|
-
*
|
|
26213
|
-
* See also .argument().
|
|
26214
|
-
*
|
|
26215
|
-
* @example
|
|
26216
|
-
* program.arguments('<cmd> [env]');
|
|
26217
|
-
*
|
|
26218
|
-
* @param {string} names
|
|
26219
|
-
* @return {Command} `this` command for chaining
|
|
26220
|
-
*/
|
|
26221
|
-
arguments(names) {
|
|
26222
|
-
names.trim().split(/ +/).forEach((detail) => {
|
|
26223
|
-
this.argument(detail);
|
|
26224
|
-
});
|
|
26225
|
-
return this;
|
|
26226
|
-
}
|
|
26227
|
-
/**
|
|
26228
|
-
* Define argument syntax for command, adding a prepared argument.
|
|
26229
|
-
*
|
|
26230
|
-
* @param {Argument} argument
|
|
26231
|
-
* @return {Command} `this` command for chaining
|
|
26232
|
-
*/
|
|
26233
|
-
addArgument(argument) {
|
|
26234
|
-
const previousArgument = this.registeredArguments.slice(-1)[0];
|
|
26235
|
-
if (previousArgument?.variadic) {
|
|
26236
|
-
throw new Error(
|
|
26237
|
-
`only the last argument can be variadic '${previousArgument.name()}'`
|
|
26238
|
-
);
|
|
26239
|
-
}
|
|
26240
|
-
if (argument.required && argument.defaultValue !== void 0 && argument.parseArg === void 0) {
|
|
26241
|
-
throw new Error(
|
|
26242
|
-
`a default value for a required argument is never used: '${argument.name()}'`
|
|
26243
|
-
);
|
|
26244
|
-
}
|
|
26245
|
-
this.registeredArguments.push(argument);
|
|
26246
|
-
return this;
|
|
26247
|
-
}
|
|
26248
|
-
/**
|
|
26249
|
-
* Customise or override default help command. By default a help command is automatically added if your command has subcommands.
|
|
26250
|
-
*
|
|
26251
|
-
* @example
|
|
26252
|
-
* program.helpCommand('help [cmd]');
|
|
26253
|
-
* program.helpCommand('help [cmd]', 'show help');
|
|
26254
|
-
* program.helpCommand(false); // suppress default help command
|
|
26255
|
-
* program.helpCommand(true); // add help command even if no subcommands
|
|
26256
|
-
*
|
|
26257
|
-
* @param {string|boolean} enableOrNameAndArgs - enable with custom name and/or arguments, or boolean to override whether added
|
|
26258
|
-
* @param {string} [description] - custom description
|
|
26259
|
-
* @return {Command} `this` command for chaining
|
|
26260
|
-
*/
|
|
26261
|
-
helpCommand(enableOrNameAndArgs, description) {
|
|
26262
|
-
if (typeof enableOrNameAndArgs === "boolean") {
|
|
26263
|
-
this._addImplicitHelpCommand = enableOrNameAndArgs;
|
|
26264
|
-
if (enableOrNameAndArgs && this._defaultCommandGroup) {
|
|
26265
|
-
this._initCommandGroup(this._getHelpCommand());
|
|
26266
|
-
}
|
|
26267
|
-
return this;
|
|
26268
|
-
}
|
|
26269
|
-
const nameAndArgs = enableOrNameAndArgs ?? "help [command]";
|
|
26270
|
-
const [, helpName, helpArgs] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
26271
|
-
const helpDescription = description ?? "display help for command";
|
|
26272
|
-
const helpCommand = this.createCommand(helpName);
|
|
26273
|
-
helpCommand.helpOption(false);
|
|
26274
|
-
if (helpArgs) helpCommand.arguments(helpArgs);
|
|
26275
|
-
if (helpDescription) helpCommand.description(helpDescription);
|
|
26276
|
-
this._addImplicitHelpCommand = true;
|
|
26277
|
-
this._helpCommand = helpCommand;
|
|
26278
|
-
if (enableOrNameAndArgs || description) this._initCommandGroup(helpCommand);
|
|
26279
|
-
return this;
|
|
26280
|
-
}
|
|
26281
|
-
/**
|
|
26282
|
-
* Add prepared custom help command.
|
|
26283
|
-
*
|
|
26284
|
-
* @param {(Command|string|boolean)} helpCommand - custom help command, or deprecated enableOrNameAndArgs as for `.helpCommand()`
|
|
26285
|
-
* @param {string} [deprecatedDescription] - deprecated custom description used with custom name only
|
|
26286
|
-
* @return {Command} `this` command for chaining
|
|
26287
|
-
*/
|
|
26288
|
-
addHelpCommand(helpCommand, deprecatedDescription) {
|
|
26289
|
-
if (typeof helpCommand !== "object") {
|
|
26290
|
-
this.helpCommand(helpCommand, deprecatedDescription);
|
|
26291
|
-
return this;
|
|
26292
|
-
}
|
|
26293
|
-
this._addImplicitHelpCommand = true;
|
|
26294
|
-
this._helpCommand = helpCommand;
|
|
26295
|
-
this._initCommandGroup(helpCommand);
|
|
26296
|
-
return this;
|
|
26297
|
-
}
|
|
26298
|
-
/**
|
|
26299
|
-
* Lazy create help command.
|
|
26300
|
-
*
|
|
26301
|
-
* @return {(Command|null)}
|
|
26302
|
-
* @package
|
|
26303
|
-
*/
|
|
26304
|
-
_getHelpCommand() {
|
|
26305
|
-
const hasImplicitHelpCommand = this._addImplicitHelpCommand ?? (this.commands.length && !this._actionHandler && !this._findCommand("help"));
|
|
26306
|
-
if (hasImplicitHelpCommand) {
|
|
26307
|
-
if (this._helpCommand === void 0) {
|
|
26308
|
-
this.helpCommand(void 0, void 0);
|
|
26309
|
-
}
|
|
26310
|
-
return this._helpCommand;
|
|
26311
|
-
}
|
|
26312
|
-
return null;
|
|
26313
|
-
}
|
|
26314
|
-
/**
|
|
26315
|
-
* Add hook for life cycle event.
|
|
26316
|
-
*
|
|
26317
|
-
* @param {string} event
|
|
26318
|
-
* @param {Function} listener
|
|
26319
|
-
* @return {Command} `this` command for chaining
|
|
26320
|
-
*/
|
|
26321
|
-
hook(event, listener) {
|
|
26322
|
-
const allowedValues = ["preSubcommand", "preAction", "postAction"];
|
|
26323
|
-
if (!allowedValues.includes(event)) {
|
|
26324
|
-
throw new Error(`Unexpected value for event passed to hook : '${event}'.
|
|
26325
|
-
Expecting one of '${allowedValues.join("', '")}'`);
|
|
26326
|
-
}
|
|
26327
|
-
if (this._lifeCycleHooks[event]) {
|
|
26328
|
-
this._lifeCycleHooks[event].push(listener);
|
|
26329
|
-
} else {
|
|
26330
|
-
this._lifeCycleHooks[event] = [listener];
|
|
26331
|
-
}
|
|
26332
|
-
return this;
|
|
26333
|
-
}
|
|
26334
|
-
/**
|
|
26335
|
-
* Register callback to use as replacement for calling process.exit.
|
|
26336
|
-
*
|
|
26337
|
-
* @param {Function} [fn] optional callback which will be passed a CommanderError, defaults to throwing
|
|
26338
|
-
* @return {Command} `this` command for chaining
|
|
26339
|
-
*/
|
|
26340
|
-
exitOverride(fn) {
|
|
26341
|
-
if (fn) {
|
|
26342
|
-
this._exitCallback = fn;
|
|
26343
|
-
} else {
|
|
26344
|
-
this._exitCallback = (err) => {
|
|
26345
|
-
if (err.code !== "commander.executeSubCommandAsync") {
|
|
26346
|
-
throw err;
|
|
26347
|
-
} else {
|
|
26348
|
-
}
|
|
26349
|
-
};
|
|
26350
|
-
}
|
|
26351
|
-
return this;
|
|
26352
|
-
}
|
|
26353
|
-
/**
|
|
26354
|
-
* Call process.exit, and _exitCallback if defined.
|
|
26355
|
-
*
|
|
26356
|
-
* @param {number} exitCode exit code for using with process.exit
|
|
26357
|
-
* @param {string} code an id string representing the error
|
|
26358
|
-
* @param {string} message human-readable description of the error
|
|
26359
|
-
* @return never
|
|
26360
|
-
* @private
|
|
26361
|
-
*/
|
|
26362
|
-
_exit(exitCode3, code, message) {
|
|
26363
|
-
if (this._exitCallback) {
|
|
26364
|
-
this._exitCallback(new CommanderError2(exitCode3, code, message));
|
|
26365
|
-
}
|
|
26366
|
-
process2.exit(exitCode3);
|
|
26367
|
-
}
|
|
26368
|
-
/**
|
|
26369
|
-
* Register callback `fn` for the command.
|
|
26370
|
-
*
|
|
26371
|
-
* @example
|
|
26372
|
-
* program
|
|
26373
|
-
* .command('serve')
|
|
26374
|
-
* .description('start service')
|
|
26375
|
-
* .action(function() {
|
|
26376
|
-
* // do work here
|
|
26377
|
-
* });
|
|
26378
|
-
*
|
|
26379
|
-
* @param {Function} fn
|
|
26380
|
-
* @return {Command} `this` command for chaining
|
|
26381
|
-
*/
|
|
26382
|
-
action(fn) {
|
|
26383
|
-
const listener = (args) => {
|
|
26384
|
-
const expectedArgsCount = this.registeredArguments.length;
|
|
26385
|
-
const actionArgs = args.slice(0, expectedArgsCount);
|
|
26386
|
-
if (this._storeOptionsAsProperties) {
|
|
26387
|
-
actionArgs[expectedArgsCount] = this;
|
|
26388
|
-
} else {
|
|
26389
|
-
actionArgs[expectedArgsCount] = this.opts();
|
|
26390
|
-
}
|
|
26391
|
-
actionArgs.push(this);
|
|
26392
|
-
return fn.apply(this, actionArgs);
|
|
26393
|
-
};
|
|
26394
|
-
this._actionHandler = listener;
|
|
26395
|
-
return this;
|
|
26396
|
-
}
|
|
26397
|
-
/**
|
|
26398
|
-
* Factory routine to create a new unattached option.
|
|
26399
|
-
*
|
|
26400
|
-
* See .option() for creating an attached option, which uses this routine to
|
|
26401
|
-
* create the option. You can override createOption to return a custom option.
|
|
26402
|
-
*
|
|
26403
|
-
* @param {string} flags
|
|
26404
|
-
* @param {string} [description]
|
|
26405
|
-
* @return {Option} new option
|
|
26406
|
-
*/
|
|
26407
|
-
createOption(flags, description) {
|
|
26408
|
-
return new Option2(flags, description);
|
|
26409
|
-
}
|
|
26410
|
-
/**
|
|
26411
|
-
* Wrap parseArgs to catch 'commander.invalidArgument'.
|
|
26412
|
-
*
|
|
26413
|
-
* @param {(Option | Argument)} target
|
|
26414
|
-
* @param {string} value
|
|
26415
|
-
* @param {*} previous
|
|
26416
|
-
* @param {string} invalidArgumentMessage
|
|
26417
|
-
* @private
|
|
26418
|
-
*/
|
|
26419
|
-
_callParseArg(target, value, previous, invalidArgumentMessage) {
|
|
26420
|
-
try {
|
|
26421
|
-
return target.parseArg(value, previous);
|
|
26422
|
-
} catch (err) {
|
|
26423
|
-
if (err.code === "commander.invalidArgument") {
|
|
26424
|
-
const message = `${invalidArgumentMessage} ${err.message}`;
|
|
26425
|
-
this.error(message, { exitCode: err.exitCode, code: err.code });
|
|
26426
|
-
}
|
|
26427
|
-
throw err;
|
|
26428
|
-
}
|
|
26429
|
-
}
|
|
26430
|
-
/**
|
|
26431
|
-
* Check for option flag conflicts.
|
|
26432
|
-
* Register option if no conflicts found, or throw on conflict.
|
|
26433
|
-
*
|
|
26434
|
-
* @param {Option} option
|
|
26435
|
-
* @private
|
|
26436
|
-
*/
|
|
26437
|
-
_registerOption(option) {
|
|
26438
|
-
const matchingOption = option.short && this._findOption(option.short) || option.long && this._findOption(option.long);
|
|
26439
|
-
if (matchingOption) {
|
|
26440
|
-
const matchingFlag = option.long && this._findOption(option.long) ? option.long : option.short;
|
|
26441
|
-
throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
|
|
26442
|
-
- already used by option '${matchingOption.flags}'`);
|
|
26443
|
-
}
|
|
26444
|
-
this._initOptionGroup(option);
|
|
26445
|
-
this.options.push(option);
|
|
26446
|
-
}
|
|
26447
|
-
/**
|
|
26448
|
-
* Check for command name and alias conflicts with existing commands.
|
|
26449
|
-
* Register command if no conflicts found, or throw on conflict.
|
|
26450
|
-
*
|
|
26451
|
-
* @param {Command} command
|
|
26452
|
-
* @private
|
|
26453
|
-
*/
|
|
26454
|
-
_registerCommand(command) {
|
|
26455
|
-
const knownBy = (cmd) => {
|
|
26456
|
-
return [cmd.name()].concat(cmd.aliases());
|
|
26457
|
-
};
|
|
26458
|
-
const alreadyUsed = knownBy(command).find(
|
|
26459
|
-
(name) => this._findCommand(name)
|
|
26460
|
-
);
|
|
26461
|
-
if (alreadyUsed) {
|
|
26462
|
-
const existingCmd = knownBy(this._findCommand(alreadyUsed)).join("|");
|
|
26463
|
-
const newCmd = knownBy(command).join("|");
|
|
26464
|
-
throw new Error(
|
|
26465
|
-
`cannot add command '${newCmd}' as already have command '${existingCmd}'`
|
|
26466
|
-
);
|
|
26467
|
-
}
|
|
26468
|
-
this._initCommandGroup(command);
|
|
26469
|
-
this.commands.push(command);
|
|
26470
|
-
}
|
|
26471
|
-
/**
|
|
26472
|
-
* Add an option.
|
|
26473
|
-
*
|
|
26474
|
-
* @param {Option} option
|
|
26475
|
-
* @return {Command} `this` command for chaining
|
|
26476
|
-
*/
|
|
26477
|
-
addOption(option) {
|
|
26478
|
-
this._registerOption(option);
|
|
26479
|
-
const oname = option.name();
|
|
26480
|
-
const name = option.attributeName();
|
|
26481
|
-
if (option.negate) {
|
|
26482
|
-
const positiveLongFlag = option.long.replace(/^--no-/, "--");
|
|
26483
|
-
if (!this._findOption(positiveLongFlag)) {
|
|
26484
|
-
this.setOptionValueWithSource(
|
|
26485
|
-
name,
|
|
26486
|
-
option.defaultValue === void 0 ? true : option.defaultValue,
|
|
26487
|
-
"default"
|
|
26488
|
-
);
|
|
26489
|
-
}
|
|
26490
|
-
} else if (option.defaultValue !== void 0) {
|
|
26491
|
-
this.setOptionValueWithSource(name, option.defaultValue, "default");
|
|
26492
|
-
}
|
|
26493
|
-
const handleOptionValue = (val, invalidValueMessage, valueSource) => {
|
|
26494
|
-
if (val == null && option.presetArg !== void 0) {
|
|
26495
|
-
val = option.presetArg;
|
|
26496
|
-
}
|
|
26497
|
-
const oldValue = this.getOptionValue(name);
|
|
26498
|
-
if (val !== null && option.parseArg) {
|
|
26499
|
-
val = this._callParseArg(option, val, oldValue, invalidValueMessage);
|
|
26500
|
-
} else if (val !== null && option.variadic) {
|
|
26501
|
-
val = option._collectValue(val, oldValue);
|
|
26502
|
-
}
|
|
26503
|
-
if (val == null) {
|
|
26504
|
-
if (option.negate) {
|
|
26505
|
-
val = false;
|
|
26506
|
-
} else if (option.isBoolean() || option.optional) {
|
|
26507
|
-
val = true;
|
|
26508
|
-
} else {
|
|
26509
|
-
val = "";
|
|
26510
|
-
}
|
|
26511
|
-
}
|
|
26512
|
-
this.setOptionValueWithSource(name, val, valueSource);
|
|
26513
|
-
};
|
|
26514
|
-
this.on("option:" + oname, (val) => {
|
|
26515
|
-
const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
|
|
26516
|
-
handleOptionValue(val, invalidValueMessage, "cli");
|
|
26517
|
-
});
|
|
26518
|
-
if (option.envVar) {
|
|
26519
|
-
this.on("optionEnv:" + oname, (val) => {
|
|
26520
|
-
const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
|
|
26521
|
-
handleOptionValue(val, invalidValueMessage, "env");
|
|
26522
|
-
});
|
|
26523
|
-
}
|
|
26524
|
-
return this;
|
|
26525
|
-
}
|
|
26526
|
-
/**
|
|
26527
|
-
* Internal implementation shared by .option() and .requiredOption()
|
|
26528
|
-
*
|
|
26529
|
-
* @return {Command} `this` command for chaining
|
|
26530
|
-
* @private
|
|
26531
|
-
*/
|
|
26532
|
-
_optionEx(config, flags, description, fn, defaultValue) {
|
|
26533
|
-
if (typeof flags === "object" && flags instanceof Option2) {
|
|
26534
|
-
throw new Error(
|
|
26535
|
-
"To add an Option object use addOption() instead of option() or requiredOption()"
|
|
26536
|
-
);
|
|
26537
|
-
}
|
|
26538
|
-
const option = this.createOption(flags, description);
|
|
26539
|
-
option.makeOptionMandatory(!!config.mandatory);
|
|
26540
|
-
if (typeof fn === "function") {
|
|
26541
|
-
option.default(defaultValue).argParser(fn);
|
|
26542
|
-
} else if (fn instanceof RegExp) {
|
|
26543
|
-
const regex = fn;
|
|
26544
|
-
fn = (val, def) => {
|
|
26545
|
-
const m = regex.exec(val);
|
|
26546
|
-
return m ? m[0] : def;
|
|
26547
|
-
};
|
|
26548
|
-
option.default(defaultValue).argParser(fn);
|
|
26549
|
-
} else {
|
|
26550
|
-
option.default(fn);
|
|
26551
|
-
}
|
|
26552
|
-
return this.addOption(option);
|
|
26553
|
-
}
|
|
26554
|
-
/**
|
|
26555
|
-
* Define option with `flags`, `description`, and optional argument parsing function or `defaultValue` or both.
|
|
26556
|
-
*
|
|
26557
|
-
* The `flags` string contains the short and/or long flags, separated by comma, a pipe or space. A required
|
|
26558
|
-
* option-argument is indicated by `<>` and an optional option-argument by `[]`.
|
|
26559
|
-
*
|
|
26560
|
-
* See the README for more details, and see also addOption() and requiredOption().
|
|
26561
|
-
*
|
|
26562
|
-
* @example
|
|
26563
|
-
* program
|
|
26564
|
-
* .option('-p, --pepper', 'add pepper')
|
|
26565
|
-
* .option('--pt, --pizza-type <TYPE>', 'type of pizza') // required option-argument
|
|
26566
|
-
* .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default
|
|
26567
|
-
* .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function
|
|
26568
|
-
*
|
|
26569
|
-
* @param {string} flags
|
|
26570
|
-
* @param {string} [description]
|
|
26571
|
-
* @param {(Function|*)} [parseArg] - custom option processing function or default value
|
|
26572
|
-
* @param {*} [defaultValue]
|
|
26573
|
-
* @return {Command} `this` command for chaining
|
|
26574
|
-
*/
|
|
26575
|
-
option(flags, description, parseArg, defaultValue) {
|
|
26576
|
-
return this._optionEx({}, flags, description, parseArg, defaultValue);
|
|
26577
|
-
}
|
|
26578
|
-
/**
|
|
26579
|
-
* Add a required option which must have a value after parsing. This usually means
|
|
26580
|
-
* the option must be specified on the command line. (Otherwise the same as .option().)
|
|
26581
|
-
*
|
|
26582
|
-
* The `flags` string contains the short and/or long flags, separated by comma, a pipe or space.
|
|
26583
|
-
*
|
|
26584
|
-
* @param {string} flags
|
|
26585
|
-
* @param {string} [description]
|
|
26586
|
-
* @param {(Function|*)} [parseArg] - custom option processing function or default value
|
|
26587
|
-
* @param {*} [defaultValue]
|
|
26588
|
-
* @return {Command} `this` command for chaining
|
|
26589
|
-
*/
|
|
26590
|
-
requiredOption(flags, description, parseArg, defaultValue) {
|
|
26591
|
-
return this._optionEx(
|
|
26592
|
-
{ mandatory: true },
|
|
26593
|
-
flags,
|
|
26594
|
-
description,
|
|
26595
|
-
parseArg,
|
|
26596
|
-
defaultValue
|
|
26597
|
-
);
|
|
26598
|
-
}
|
|
26599
|
-
/**
|
|
26600
|
-
* Alter parsing of short flags with optional values.
|
|
26601
|
-
*
|
|
26602
|
-
* @example
|
|
26603
|
-
* // for `.option('-f,--flag [value]'):
|
|
26604
|
-
* program.combineFlagAndOptionalValue(true); // `-f80` is treated like `--flag=80`, this is the default behaviour
|
|
26605
|
-
* program.combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
|
|
26606
|
-
*
|
|
26607
|
-
* @param {boolean} [combine] - if `true` or omitted, an optional value can be specified directly after the flag.
|
|
26608
|
-
* @return {Command} `this` command for chaining
|
|
26609
|
-
*/
|
|
26610
|
-
combineFlagAndOptionalValue(combine = true) {
|
|
26611
|
-
this._combineFlagAndOptionalValue = !!combine;
|
|
26612
|
-
return this;
|
|
26613
|
-
}
|
|
26614
|
-
/**
|
|
26615
|
-
* Allow unknown options on the command line.
|
|
26616
|
-
*
|
|
26617
|
-
* @param {boolean} [allowUnknown] - if `true` or omitted, no error will be thrown for unknown options.
|
|
26618
|
-
* @return {Command} `this` command for chaining
|
|
26619
|
-
*/
|
|
26620
|
-
allowUnknownOption(allowUnknown = true) {
|
|
26621
|
-
this._allowUnknownOption = !!allowUnknown;
|
|
26622
|
-
return this;
|
|
26623
|
-
}
|
|
26624
|
-
/**
|
|
26625
|
-
* Allow excess command-arguments on the command line. Pass false to make excess arguments an error.
|
|
26626
|
-
*
|
|
26627
|
-
* @param {boolean} [allowExcess] - if `true` or omitted, no error will be thrown for excess arguments.
|
|
26628
|
-
* @return {Command} `this` command for chaining
|
|
26629
|
-
*/
|
|
26630
|
-
allowExcessArguments(allowExcess = true) {
|
|
26631
|
-
this._allowExcessArguments = !!allowExcess;
|
|
26632
|
-
return this;
|
|
26633
|
-
}
|
|
26634
|
-
/**
|
|
26635
|
-
* Enable positional options. Positional means global options are specified before subcommands which lets
|
|
26636
|
-
* subcommands reuse the same option names, and also enables subcommands to turn on passThroughOptions.
|
|
26637
|
-
* The default behaviour is non-positional and global options may appear anywhere on the command line.
|
|
26638
|
-
*
|
|
26639
|
-
* @param {boolean} [positional]
|
|
26640
|
-
* @return {Command} `this` command for chaining
|
|
26641
|
-
*/
|
|
26642
|
-
enablePositionalOptions(positional = true) {
|
|
26643
|
-
this._enablePositionalOptions = !!positional;
|
|
26644
|
-
return this;
|
|
26645
|
-
}
|
|
26646
|
-
/**
|
|
26647
|
-
* Pass through options that come after command-arguments rather than treat them as command-options,
|
|
26648
|
-
* so actual command-options come before command-arguments. Turning this on for a subcommand requires
|
|
26649
|
-
* positional options to have been enabled on the program (parent commands).
|
|
26650
|
-
* The default behaviour is non-positional and options may appear before or after command-arguments.
|
|
26651
|
-
*
|
|
26652
|
-
* @param {boolean} [passThrough] for unknown options.
|
|
26653
|
-
* @return {Command} `this` command for chaining
|
|
26654
|
-
*/
|
|
26655
|
-
passThroughOptions(passThrough = true) {
|
|
26656
|
-
this._passThroughOptions = !!passThrough;
|
|
26657
|
-
this._checkForBrokenPassThrough();
|
|
26658
|
-
return this;
|
|
26659
|
-
}
|
|
26660
|
-
/**
|
|
26661
|
-
* @private
|
|
26662
|
-
*/
|
|
26663
|
-
_checkForBrokenPassThrough() {
|
|
26664
|
-
if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
|
|
26665
|
-
throw new Error(
|
|
26666
|
-
`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`
|
|
26667
|
-
);
|
|
26668
|
-
}
|
|
26669
|
-
}
|
|
26670
|
-
/**
|
|
26671
|
-
* Whether to store option values as properties on command object,
|
|
26672
|
-
* or store separately (specify false). In both cases the option values can be accessed using .opts().
|
|
26673
|
-
*
|
|
26674
|
-
* @param {boolean} [storeAsProperties=true]
|
|
26675
|
-
* @return {Command} `this` command for chaining
|
|
26676
|
-
*/
|
|
26677
|
-
storeOptionsAsProperties(storeAsProperties = true) {
|
|
26678
|
-
if (this.options.length) {
|
|
26679
|
-
throw new Error("call .storeOptionsAsProperties() before adding options");
|
|
26680
|
-
}
|
|
26681
|
-
if (Object.keys(this._optionValues).length) {
|
|
26682
|
-
throw new Error(
|
|
26683
|
-
"call .storeOptionsAsProperties() before setting option values"
|
|
26684
|
-
);
|
|
26685
|
-
}
|
|
26686
|
-
this._storeOptionsAsProperties = !!storeAsProperties;
|
|
26687
|
-
return this;
|
|
26688
|
-
}
|
|
26689
|
-
/**
|
|
26690
|
-
* Retrieve option value.
|
|
26691
|
-
*
|
|
26692
|
-
* @param {string} key
|
|
26693
|
-
* @return {object} value
|
|
26694
|
-
*/
|
|
26695
|
-
getOptionValue(key) {
|
|
26696
|
-
if (this._storeOptionsAsProperties) {
|
|
26697
|
-
return this[key];
|
|
26698
|
-
}
|
|
26699
|
-
return this._optionValues[key];
|
|
26700
|
-
}
|
|
26701
|
-
/**
|
|
26702
|
-
* Store option value.
|
|
26703
|
-
*
|
|
26704
|
-
* @param {string} key
|
|
26705
|
-
* @param {object} value
|
|
26706
|
-
* @return {Command} `this` command for chaining
|
|
26707
|
-
*/
|
|
26708
|
-
setOptionValue(key, value) {
|
|
26709
|
-
return this.setOptionValueWithSource(key, value, void 0);
|
|
26710
|
-
}
|
|
26711
|
-
/**
|
|
26712
|
-
* Store option value and where the value came from.
|
|
26713
|
-
*
|
|
26714
|
-
* @param {string} key
|
|
26715
|
-
* @param {object} value
|
|
26716
|
-
* @param {string} source - expected values are default/config/env/cli/implied
|
|
26717
|
-
* @return {Command} `this` command for chaining
|
|
26718
|
-
*/
|
|
26719
|
-
setOptionValueWithSource(key, value, source) {
|
|
26720
|
-
if (this._storeOptionsAsProperties) {
|
|
26721
|
-
this[key] = value;
|
|
26722
|
-
} else {
|
|
26723
|
-
this._optionValues[key] = value;
|
|
26724
|
-
}
|
|
26725
|
-
this._optionValueSources[key] = source;
|
|
26726
|
-
return this;
|
|
26727
|
-
}
|
|
26728
|
-
/**
|
|
26729
|
-
* Get source of option value.
|
|
26730
|
-
* Expected values are default | config | env | cli | implied
|
|
26731
|
-
*
|
|
26732
|
-
* @param {string} key
|
|
26733
|
-
* @return {string}
|
|
26734
|
-
*/
|
|
26735
|
-
getOptionValueSource(key) {
|
|
26736
|
-
return this._optionValueSources[key];
|
|
26737
|
-
}
|
|
26738
|
-
/**
|
|
26739
|
-
* Get source of option value. See also .optsWithGlobals().
|
|
26740
|
-
* Expected values are default | config | env | cli | implied
|
|
26741
|
-
*
|
|
26742
|
-
* @param {string} key
|
|
26743
|
-
* @return {string}
|
|
26744
|
-
*/
|
|
26745
|
-
getOptionValueSourceWithGlobals(key) {
|
|
26746
|
-
let source;
|
|
26747
|
-
this._getCommandAndAncestors().forEach((cmd) => {
|
|
26748
|
-
if (cmd.getOptionValueSource(key) !== void 0) {
|
|
26749
|
-
source = cmd.getOptionValueSource(key);
|
|
26750
|
-
}
|
|
26751
|
-
});
|
|
26752
|
-
return source;
|
|
26753
|
-
}
|
|
26754
|
-
/**
|
|
26755
|
-
* Get user arguments from implied or explicit arguments.
|
|
26756
|
-
* Side-effects: set _scriptPath if args included script. Used for default program name, and subcommand searches.
|
|
26757
|
-
*
|
|
26758
|
-
* @private
|
|
26759
|
-
*/
|
|
26760
|
-
_prepareUserArgs(argv, parseOptions) {
|
|
26761
|
-
if (argv !== void 0 && !Array.isArray(argv)) {
|
|
26762
|
-
throw new Error("first parameter to parse must be array or undefined");
|
|
26763
|
-
}
|
|
26764
|
-
parseOptions = parseOptions || {};
|
|
26765
|
-
if (argv === void 0 && parseOptions.from === void 0) {
|
|
26766
|
-
if (process2.versions?.electron) {
|
|
26767
|
-
parseOptions.from = "electron";
|
|
26768
|
-
}
|
|
26769
|
-
const execArgv = process2.execArgv ?? [];
|
|
26770
|
-
if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
|
|
26771
|
-
parseOptions.from = "eval";
|
|
26772
|
-
}
|
|
26773
|
-
}
|
|
26774
|
-
if (argv === void 0) {
|
|
26775
|
-
argv = process2.argv;
|
|
26776
|
-
}
|
|
26777
|
-
this.rawArgs = argv.slice();
|
|
26778
|
-
let userArgs;
|
|
26779
|
-
switch (parseOptions.from) {
|
|
26780
|
-
case void 0:
|
|
26781
|
-
case "node":
|
|
26782
|
-
this._scriptPath = argv[1];
|
|
26783
|
-
userArgs = argv.slice(2);
|
|
26784
|
-
break;
|
|
26785
|
-
case "electron":
|
|
26786
|
-
if (process2.defaultApp) {
|
|
26787
|
-
this._scriptPath = argv[1];
|
|
26788
|
-
userArgs = argv.slice(2);
|
|
26789
|
-
} else {
|
|
26790
|
-
userArgs = argv.slice(1);
|
|
26791
|
-
}
|
|
26792
|
-
break;
|
|
26793
|
-
case "user":
|
|
26794
|
-
userArgs = argv.slice(0);
|
|
26795
|
-
break;
|
|
26796
|
-
case "eval":
|
|
26797
|
-
userArgs = argv.slice(1);
|
|
26798
|
-
break;
|
|
26799
|
-
default:
|
|
26800
|
-
throw new Error(
|
|
26801
|
-
`unexpected parse option { from: '${parseOptions.from}' }`
|
|
26802
|
-
);
|
|
26803
|
-
}
|
|
26804
|
-
if (!this._name && this._scriptPath)
|
|
26805
|
-
this.nameFromFilename(this._scriptPath);
|
|
26806
|
-
this._name = this._name || "program";
|
|
26807
|
-
return userArgs;
|
|
26808
|
-
}
|
|
26809
|
-
/**
|
|
26810
|
-
* Parse `argv`, setting options and invoking commands when defined.
|
|
26811
|
-
*
|
|
26812
|
-
* Use parseAsync instead of parse if any of your action handlers are async.
|
|
26813
|
-
*
|
|
26814
|
-
* Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
|
|
26815
|
-
*
|
|
26816
|
-
* Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
|
|
26817
|
-
* - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
|
|
26818
|
-
* - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
|
|
26819
|
-
* - `'user'`: just user arguments
|
|
26820
|
-
*
|
|
26821
|
-
* @example
|
|
26822
|
-
* program.parse(); // parse process.argv and auto-detect electron and special node flags
|
|
26823
|
-
* program.parse(process.argv); // assume argv[0] is app and argv[1] is script
|
|
26824
|
-
* program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
|
26825
|
-
*
|
|
26826
|
-
* @param {string[]} [argv] - optional, defaults to process.argv
|
|
26827
|
-
* @param {object} [parseOptions] - optionally specify style of options with from: node/user/electron
|
|
26828
|
-
* @param {string} [parseOptions.from] - where the args are from: 'node', 'user', 'electron'
|
|
26829
|
-
* @return {Command} `this` command for chaining
|
|
26830
|
-
*/
|
|
26831
|
-
parse(argv, parseOptions) {
|
|
26832
|
-
this._prepareForParse();
|
|
26833
|
-
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
26834
|
-
this._parseCommand([], userArgs);
|
|
26835
|
-
return this;
|
|
26836
|
-
}
|
|
26837
|
-
/**
|
|
26838
|
-
* Parse `argv`, setting options and invoking commands when defined.
|
|
26839
|
-
*
|
|
26840
|
-
* Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
|
|
26841
|
-
*
|
|
26842
|
-
* Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
|
|
26843
|
-
* - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
|
|
26844
|
-
* - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
|
|
26845
|
-
* - `'user'`: just user arguments
|
|
26846
|
-
*
|
|
26847
|
-
* @example
|
|
26848
|
-
* await program.parseAsync(); // parse process.argv and auto-detect electron and special node flags
|
|
26849
|
-
* await program.parseAsync(process.argv); // assume argv[0] is app and argv[1] is script
|
|
26850
|
-
* await program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
|
26851
|
-
*
|
|
26852
|
-
* @param {string[]} [argv]
|
|
26853
|
-
* @param {object} [parseOptions]
|
|
26854
|
-
* @param {string} parseOptions.from - where the args are from: 'node', 'user', 'electron'
|
|
26855
|
-
* @return {Promise}
|
|
26856
|
-
*/
|
|
26857
|
-
async parseAsync(argv, parseOptions) {
|
|
26858
|
-
this._prepareForParse();
|
|
26859
|
-
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
26860
|
-
await this._parseCommand([], userArgs);
|
|
26861
|
-
return this;
|
|
26862
|
-
}
|
|
26863
|
-
_prepareForParse() {
|
|
26864
|
-
if (this._savedState === null) {
|
|
26865
|
-
this.saveStateBeforeParse();
|
|
26866
|
-
} else {
|
|
26867
|
-
this.restoreStateBeforeParse();
|
|
26868
|
-
}
|
|
26869
|
-
}
|
|
26870
|
-
/**
|
|
26871
|
-
* Called the first time parse is called to save state and allow a restore before subsequent calls to parse.
|
|
26872
|
-
* Not usually called directly, but available for subclasses to save their custom state.
|
|
26873
|
-
*
|
|
26874
|
-
* This is called in a lazy way. Only commands used in parsing chain will have state saved.
|
|
26875
|
-
*/
|
|
26876
|
-
saveStateBeforeParse() {
|
|
26877
|
-
this._savedState = {
|
|
26878
|
-
// name is stable if supplied by author, but may be unspecified for root command and deduced during parsing
|
|
26879
|
-
_name: this._name,
|
|
26880
|
-
// option values before parse have default values (including false for negated options)
|
|
26881
|
-
// shallow clones
|
|
26882
|
-
_optionValues: { ...this._optionValues },
|
|
26883
|
-
_optionValueSources: { ...this._optionValueSources }
|
|
26884
|
-
};
|
|
26885
|
-
}
|
|
26886
|
-
/**
|
|
26887
|
-
* Restore state before parse for calls after the first.
|
|
26888
|
-
* Not usually called directly, but available for subclasses to save their custom state.
|
|
26889
|
-
*
|
|
26890
|
-
* This is called in a lazy way. Only commands used in parsing chain will have state restored.
|
|
26891
|
-
*/
|
|
26892
|
-
restoreStateBeforeParse() {
|
|
26893
|
-
if (this._storeOptionsAsProperties)
|
|
26894
|
-
throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
|
|
26895
|
-
- either make a new Command for each call to parse, or stop storing options as properties`);
|
|
26896
|
-
this._name = this._savedState._name;
|
|
26897
|
-
this._scriptPath = null;
|
|
26898
|
-
this.rawArgs = [];
|
|
26899
|
-
this._optionValues = { ...this._savedState._optionValues };
|
|
26900
|
-
this._optionValueSources = { ...this._savedState._optionValueSources };
|
|
26901
|
-
this.args = [];
|
|
26902
|
-
this.processedArgs = [];
|
|
26903
|
-
}
|
|
26904
|
-
/**
|
|
26905
|
-
* Throw if expected executable is missing. Add lots of help for author.
|
|
26906
|
-
*
|
|
26907
|
-
* @param {string} executableFile
|
|
26908
|
-
* @param {string} executableDir
|
|
26909
|
-
* @param {string} subcommandName
|
|
26910
|
-
*/
|
|
26911
|
-
_checkForMissingExecutable(executableFile, executableDir, subcommandName) {
|
|
26912
|
-
if (fs19.existsSync(executableFile)) return;
|
|
26913
|
-
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";
|
|
26914
|
-
const executableMissing = `'${executableFile}' does not exist
|
|
26915
|
-
- if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
26916
|
-
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
26917
|
-
- ${executableDirMessage}`;
|
|
26918
|
-
throw new Error(executableMissing);
|
|
26919
|
-
}
|
|
26920
|
-
/**
|
|
26921
|
-
* Execute a sub-command executable.
|
|
26922
|
-
*
|
|
26923
|
-
* @private
|
|
26924
|
-
*/
|
|
26925
|
-
_executeSubCommand(subcommand, args) {
|
|
26926
|
-
args = args.slice();
|
|
26927
|
-
let launchWithNode = false;
|
|
26928
|
-
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
26929
|
-
function findFile(baseDir, baseName) {
|
|
26930
|
-
const localBin = path19.resolve(baseDir, baseName);
|
|
26931
|
-
if (fs19.existsSync(localBin)) return localBin;
|
|
26932
|
-
if (sourceExt.includes(path19.extname(baseName))) return void 0;
|
|
26933
|
-
const foundExt = sourceExt.find(
|
|
26934
|
-
(ext2) => fs19.existsSync(`${localBin}${ext2}`)
|
|
26935
|
-
);
|
|
26936
|
-
if (foundExt) return `${localBin}${foundExt}`;
|
|
26937
|
-
return void 0;
|
|
26938
|
-
}
|
|
26939
|
-
this._checkForMissingMandatoryOptions();
|
|
26940
|
-
this._checkForConflictingOptions();
|
|
26941
|
-
let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
|
|
26942
|
-
let executableDir = this._executableDir || "";
|
|
26943
|
-
if (this._scriptPath) {
|
|
26944
|
-
let resolvedScriptPath;
|
|
26945
|
-
try {
|
|
26946
|
-
resolvedScriptPath = fs19.realpathSync(this._scriptPath);
|
|
26947
|
-
} catch {
|
|
26948
|
-
resolvedScriptPath = this._scriptPath;
|
|
26949
|
-
}
|
|
26950
|
-
executableDir = path19.resolve(
|
|
26951
|
-
path19.dirname(resolvedScriptPath),
|
|
26952
|
-
executableDir
|
|
26953
|
-
);
|
|
26954
|
-
}
|
|
26955
|
-
if (executableDir) {
|
|
26956
|
-
let localFile = findFile(executableDir, executableFile);
|
|
26957
|
-
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
26958
|
-
const legacyName = path19.basename(
|
|
26959
|
-
this._scriptPath,
|
|
26960
|
-
path19.extname(this._scriptPath)
|
|
26961
|
-
);
|
|
26962
|
-
if (legacyName !== this._name) {
|
|
26963
|
-
localFile = findFile(
|
|
26964
|
-
executableDir,
|
|
26965
|
-
`${legacyName}-${subcommand._name}`
|
|
26966
|
-
);
|
|
26967
|
-
}
|
|
26968
|
-
}
|
|
26969
|
-
executableFile = localFile || executableFile;
|
|
26970
|
-
}
|
|
26971
|
-
launchWithNode = sourceExt.includes(path19.extname(executableFile));
|
|
26972
|
-
let proc;
|
|
26973
|
-
if (process2.platform !== "win32") {
|
|
26974
|
-
if (launchWithNode) {
|
|
26975
|
-
args.unshift(executableFile);
|
|
26976
|
-
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
26977
|
-
proc = childProcess.spawn(process2.argv[0], args, { stdio: "inherit" });
|
|
26978
|
-
} else {
|
|
26979
|
-
proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
|
|
26980
|
-
}
|
|
26981
|
-
} else {
|
|
26982
|
-
this._checkForMissingExecutable(
|
|
26983
|
-
executableFile,
|
|
26984
|
-
executableDir,
|
|
26985
|
-
subcommand._name
|
|
26986
|
-
);
|
|
26987
|
-
args.unshift(executableFile);
|
|
26988
|
-
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
26989
|
-
proc = childProcess.spawn(process2.execPath, args, { stdio: "inherit" });
|
|
26990
|
-
}
|
|
26991
|
-
if (!proc.killed) {
|
|
26992
|
-
const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
|
|
26993
|
-
signals.forEach((signal) => {
|
|
26994
|
-
process2.on(signal, () => {
|
|
26995
|
-
if (proc.killed === false && proc.exitCode === null) {
|
|
26996
|
-
proc.kill(signal);
|
|
26997
|
-
}
|
|
26998
|
-
});
|
|
26999
|
-
});
|
|
27000
|
-
}
|
|
27001
|
-
const exitCallback = this._exitCallback;
|
|
27002
|
-
proc.on("close", (code) => {
|
|
27003
|
-
code = code ?? 1;
|
|
27004
|
-
if (!exitCallback) {
|
|
27005
|
-
process2.exit(code);
|
|
27006
|
-
} else {
|
|
27007
|
-
exitCallback(
|
|
27008
|
-
new CommanderError2(
|
|
27009
|
-
code,
|
|
27010
|
-
"commander.executeSubCommandAsync",
|
|
27011
|
-
"(close)"
|
|
27012
|
-
)
|
|
27013
|
-
);
|
|
27014
|
-
}
|
|
27015
|
-
});
|
|
27016
|
-
proc.on("error", (err) => {
|
|
27017
|
-
if (err.code === "ENOENT") {
|
|
27018
|
-
this._checkForMissingExecutable(
|
|
27019
|
-
executableFile,
|
|
27020
|
-
executableDir,
|
|
27021
|
-
subcommand._name
|
|
27022
|
-
);
|
|
27023
|
-
} else if (err.code === "EACCES") {
|
|
27024
|
-
throw new Error(`'${executableFile}' not executable`);
|
|
27025
|
-
}
|
|
27026
|
-
if (!exitCallback) {
|
|
27027
|
-
process2.exit(1);
|
|
27028
|
-
} else {
|
|
27029
|
-
const wrappedError = new CommanderError2(
|
|
27030
|
-
1,
|
|
27031
|
-
"commander.executeSubCommandAsync",
|
|
27032
|
-
"(error)"
|
|
27033
|
-
);
|
|
27034
|
-
wrappedError.nestedError = err;
|
|
27035
|
-
exitCallback(wrappedError);
|
|
27036
|
-
}
|
|
27037
|
-
});
|
|
27038
|
-
this.runningCommand = proc;
|
|
27039
|
-
}
|
|
27040
|
-
/**
|
|
27041
|
-
* @private
|
|
27042
|
-
*/
|
|
27043
|
-
_dispatchSubcommand(commandName, operands, unknown) {
|
|
27044
|
-
const subCommand = this._findCommand(commandName);
|
|
27045
|
-
if (!subCommand) this.help({ error: true });
|
|
27046
|
-
subCommand._prepareForParse();
|
|
27047
|
-
let promiseChain;
|
|
27048
|
-
promiseChain = this._chainOrCallSubCommandHook(
|
|
27049
|
-
promiseChain,
|
|
27050
|
-
subCommand,
|
|
27051
|
-
"preSubcommand"
|
|
27052
|
-
);
|
|
27053
|
-
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
27054
|
-
if (subCommand._executableHandler) {
|
|
27055
|
-
this._executeSubCommand(subCommand, operands.concat(unknown));
|
|
27056
|
-
} else {
|
|
27057
|
-
return subCommand._parseCommand(operands, unknown);
|
|
27058
|
-
}
|
|
27059
|
-
});
|
|
27060
|
-
return promiseChain;
|
|
27061
|
-
}
|
|
27062
|
-
/**
|
|
27063
|
-
* Invoke help directly if possible, or dispatch if necessary.
|
|
27064
|
-
* e.g. help foo
|
|
27065
|
-
*
|
|
27066
|
-
* @private
|
|
27067
|
-
*/
|
|
27068
|
-
_dispatchHelpCommand(subcommandName) {
|
|
27069
|
-
if (!subcommandName) {
|
|
27070
|
-
this.help();
|
|
27071
|
-
}
|
|
27072
|
-
const subCommand = this._findCommand(subcommandName);
|
|
27073
|
-
if (subCommand && !subCommand._executableHandler) {
|
|
27074
|
-
subCommand.help();
|
|
27075
|
-
}
|
|
27076
|
-
return this._dispatchSubcommand(
|
|
27077
|
-
subcommandName,
|
|
27078
|
-
[],
|
|
27079
|
-
[this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? "--help"]
|
|
27080
|
-
);
|
|
27081
|
-
}
|
|
27082
|
-
/**
|
|
27083
|
-
* Check this.args against expected this.registeredArguments.
|
|
27084
|
-
*
|
|
27085
|
-
* @private
|
|
27086
|
-
*/
|
|
27087
|
-
_checkNumberOfArguments() {
|
|
27088
|
-
this.registeredArguments.forEach((arg, i) => {
|
|
27089
|
-
if (arg.required && this.args[i] == null) {
|
|
27090
|
-
this.missingArgument(arg.name());
|
|
27091
|
-
}
|
|
27092
|
-
});
|
|
27093
|
-
if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) {
|
|
27094
|
-
return;
|
|
27095
|
-
}
|
|
27096
|
-
if (this.args.length > this.registeredArguments.length) {
|
|
27097
|
-
this._excessArguments(this.args);
|
|
27098
|
-
}
|
|
27099
|
-
}
|
|
27100
|
-
/**
|
|
27101
|
-
* Process this.args using this.registeredArguments and save as this.processedArgs!
|
|
27102
|
-
*
|
|
27103
|
-
* @private
|
|
27104
|
-
*/
|
|
27105
|
-
_processArguments() {
|
|
27106
|
-
const myParseArg = (argument, value, previous) => {
|
|
27107
|
-
let parsedValue = value;
|
|
27108
|
-
if (value !== null && argument.parseArg) {
|
|
27109
|
-
const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
|
|
27110
|
-
parsedValue = this._callParseArg(
|
|
27111
|
-
argument,
|
|
27112
|
-
value,
|
|
27113
|
-
previous,
|
|
27114
|
-
invalidValueMessage
|
|
27115
|
-
);
|
|
27116
|
-
}
|
|
27117
|
-
return parsedValue;
|
|
27118
|
-
};
|
|
27119
|
-
this._checkNumberOfArguments();
|
|
27120
|
-
const processedArgs = [];
|
|
27121
|
-
this.registeredArguments.forEach((declaredArg, index) => {
|
|
27122
|
-
let value = declaredArg.defaultValue;
|
|
27123
|
-
if (declaredArg.variadic) {
|
|
27124
|
-
if (index < this.args.length) {
|
|
27125
|
-
value = this.args.slice(index);
|
|
27126
|
-
if (declaredArg.parseArg) {
|
|
27127
|
-
value = value.reduce((processed, v) => {
|
|
27128
|
-
return myParseArg(declaredArg, v, processed);
|
|
27129
|
-
}, declaredArg.defaultValue);
|
|
27130
|
-
}
|
|
27131
|
-
} else if (value === void 0) {
|
|
27132
|
-
value = [];
|
|
27133
|
-
}
|
|
27134
|
-
} else if (index < this.args.length) {
|
|
27135
|
-
value = this.args[index];
|
|
27136
|
-
if (declaredArg.parseArg) {
|
|
27137
|
-
value = myParseArg(declaredArg, value, declaredArg.defaultValue);
|
|
27138
|
-
}
|
|
27139
|
-
}
|
|
27140
|
-
processedArgs[index] = value;
|
|
27141
|
-
});
|
|
27142
|
-
this.processedArgs = processedArgs;
|
|
27143
|
-
}
|
|
27144
|
-
/**
|
|
27145
|
-
* Once we have a promise we chain, but call synchronously until then.
|
|
27146
|
-
*
|
|
27147
|
-
* @param {(Promise|undefined)} promise
|
|
27148
|
-
* @param {Function} fn
|
|
27149
|
-
* @return {(Promise|undefined)}
|
|
27150
|
-
* @private
|
|
27151
|
-
*/
|
|
27152
|
-
_chainOrCall(promise2, fn) {
|
|
27153
|
-
if (promise2?.then && typeof promise2.then === "function") {
|
|
27154
|
-
return promise2.then(() => fn());
|
|
27155
|
-
}
|
|
27156
|
-
return fn();
|
|
27157
|
-
}
|
|
27158
|
-
/**
|
|
27159
|
-
*
|
|
27160
|
-
* @param {(Promise|undefined)} promise
|
|
27161
|
-
* @param {string} event
|
|
27162
|
-
* @return {(Promise|undefined)}
|
|
27163
|
-
* @private
|
|
27164
|
-
*/
|
|
27165
|
-
_chainOrCallHooks(promise2, event) {
|
|
27166
|
-
let result = promise2;
|
|
27167
|
-
const hooks = [];
|
|
27168
|
-
this._getCommandAndAncestors().reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== void 0).forEach((hookedCommand) => {
|
|
27169
|
-
hookedCommand._lifeCycleHooks[event].forEach((callback2) => {
|
|
27170
|
-
hooks.push({ hookedCommand, callback: callback2 });
|
|
27171
|
-
});
|
|
27172
|
-
});
|
|
27173
|
-
if (event === "postAction") {
|
|
27174
|
-
hooks.reverse();
|
|
27175
|
-
}
|
|
27176
|
-
hooks.forEach((hookDetail) => {
|
|
27177
|
-
result = this._chainOrCall(result, () => {
|
|
27178
|
-
return hookDetail.callback(hookDetail.hookedCommand, this);
|
|
27179
|
-
});
|
|
27180
|
-
});
|
|
27181
|
-
return result;
|
|
27182
|
-
}
|
|
27183
|
-
/**
|
|
27184
|
-
*
|
|
27185
|
-
* @param {(Promise|undefined)} promise
|
|
27186
|
-
* @param {Command} subCommand
|
|
27187
|
-
* @param {string} event
|
|
27188
|
-
* @return {(Promise|undefined)}
|
|
27189
|
-
* @private
|
|
27190
|
-
*/
|
|
27191
|
-
_chainOrCallSubCommandHook(promise2, subCommand, event) {
|
|
27192
|
-
let result = promise2;
|
|
27193
|
-
if (this._lifeCycleHooks[event] !== void 0) {
|
|
27194
|
-
this._lifeCycleHooks[event].forEach((hook) => {
|
|
27195
|
-
result = this._chainOrCall(result, () => {
|
|
27196
|
-
return hook(this, subCommand);
|
|
27197
|
-
});
|
|
27198
|
-
});
|
|
27199
|
-
}
|
|
27200
|
-
return result;
|
|
27201
|
-
}
|
|
27202
|
-
/**
|
|
27203
|
-
* Process arguments in context of this command.
|
|
27204
|
-
* Returns action result, in case it is a promise.
|
|
27205
|
-
*
|
|
27206
|
-
* @private
|
|
27207
|
-
*/
|
|
27208
|
-
_parseCommand(operands, unknown) {
|
|
27209
|
-
const parsed = this.parseOptions(unknown);
|
|
27210
|
-
this._parseOptionsEnv();
|
|
27211
|
-
this._parseOptionsImplied();
|
|
27212
|
-
operands = operands.concat(parsed.operands);
|
|
27213
|
-
unknown = parsed.unknown;
|
|
27214
|
-
this.args = operands.concat(unknown);
|
|
27215
|
-
if (operands && this._findCommand(operands[0])) {
|
|
27216
|
-
return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
|
|
27217
|
-
}
|
|
27218
|
-
if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name()) {
|
|
27219
|
-
return this._dispatchHelpCommand(operands[1]);
|
|
27220
|
-
}
|
|
27221
|
-
if (this._defaultCommandName) {
|
|
27222
|
-
this._outputHelpIfRequested(unknown);
|
|
27223
|
-
return this._dispatchSubcommand(
|
|
27224
|
-
this._defaultCommandName,
|
|
27225
|
-
operands,
|
|
27226
|
-
unknown
|
|
27227
|
-
);
|
|
27228
|
-
}
|
|
27229
|
-
if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
|
|
27230
|
-
this.help({ error: true });
|
|
27231
|
-
}
|
|
27232
|
-
this._outputHelpIfRequested(parsed.unknown);
|
|
27233
|
-
this._checkForMissingMandatoryOptions();
|
|
27234
|
-
this._checkForConflictingOptions();
|
|
27235
|
-
const checkForUnknownOptions = () => {
|
|
27236
|
-
if (parsed.unknown.length > 0) {
|
|
27237
|
-
this.unknownOption(parsed.unknown[0]);
|
|
27238
|
-
}
|
|
27239
|
-
};
|
|
27240
|
-
const commandEvent = `command:${this.name()}`;
|
|
27241
|
-
if (this._actionHandler) {
|
|
27242
|
-
checkForUnknownOptions();
|
|
27243
|
-
this._processArguments();
|
|
27244
|
-
let promiseChain;
|
|
27245
|
-
promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
|
|
27246
|
-
promiseChain = this._chainOrCall(
|
|
27247
|
-
promiseChain,
|
|
27248
|
-
() => this._actionHandler(this.processedArgs)
|
|
27249
|
-
);
|
|
27250
|
-
if (this.parent) {
|
|
27251
|
-
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
27252
|
-
this.parent.emit(commandEvent, operands, unknown);
|
|
27253
|
-
});
|
|
27254
|
-
}
|
|
27255
|
-
promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
|
|
27256
|
-
return promiseChain;
|
|
27257
|
-
}
|
|
27258
|
-
if (this.parent?.listenerCount(commandEvent)) {
|
|
27259
|
-
checkForUnknownOptions();
|
|
27260
|
-
this._processArguments();
|
|
27261
|
-
this.parent.emit(commandEvent, operands, unknown);
|
|
27262
|
-
} else if (operands.length) {
|
|
27263
|
-
if (this._findCommand("*")) {
|
|
27264
|
-
return this._dispatchSubcommand("*", operands, unknown);
|
|
27265
|
-
}
|
|
27266
|
-
if (this.listenerCount("command:*")) {
|
|
27267
|
-
this.emit("command:*", operands, unknown);
|
|
27268
|
-
} else if (this.commands.length) {
|
|
27269
|
-
this.unknownCommand();
|
|
27270
|
-
} else {
|
|
27271
|
-
checkForUnknownOptions();
|
|
27272
|
-
this._processArguments();
|
|
27273
|
-
}
|
|
27274
|
-
} else if (this.commands.length) {
|
|
27275
|
-
checkForUnknownOptions();
|
|
27276
|
-
this.help({ error: true });
|
|
27277
|
-
} else {
|
|
27278
|
-
checkForUnknownOptions();
|
|
27279
|
-
this._processArguments();
|
|
27280
|
-
}
|
|
27281
|
-
}
|
|
27282
|
-
/**
|
|
27283
|
-
* Find matching command.
|
|
27284
|
-
*
|
|
27285
|
-
* @private
|
|
27286
|
-
* @return {Command | undefined}
|
|
27287
|
-
*/
|
|
27288
|
-
_findCommand(name) {
|
|
27289
|
-
if (!name) return void 0;
|
|
27290
|
-
return this.commands.find(
|
|
27291
|
-
(cmd) => cmd._name === name || cmd._aliases.includes(name)
|
|
27292
|
-
);
|
|
27293
|
-
}
|
|
27294
|
-
/**
|
|
27295
|
-
* Return an option matching `arg` if any.
|
|
27296
|
-
*
|
|
27297
|
-
* @param {string} arg
|
|
27298
|
-
* @return {Option}
|
|
27299
|
-
* @package
|
|
27300
|
-
*/
|
|
27301
|
-
_findOption(arg) {
|
|
27302
|
-
return this.options.find((option) => option.is(arg));
|
|
27303
|
-
}
|
|
27304
|
-
/**
|
|
27305
|
-
* Display an error message if a mandatory option does not have a value.
|
|
27306
|
-
* Called after checking for help flags in leaf subcommand.
|
|
27307
|
-
*
|
|
27308
|
-
* @private
|
|
27309
|
-
*/
|
|
27310
|
-
_checkForMissingMandatoryOptions() {
|
|
27311
|
-
this._getCommandAndAncestors().forEach((cmd) => {
|
|
27312
|
-
cmd.options.forEach((anOption) => {
|
|
27313
|
-
if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === void 0) {
|
|
27314
|
-
cmd.missingMandatoryOptionValue(anOption);
|
|
27315
|
-
}
|
|
27316
|
-
});
|
|
27317
|
-
});
|
|
27318
|
-
}
|
|
27319
|
-
/**
|
|
27320
|
-
* Display an error message if conflicting options are used together in this.
|
|
27321
|
-
*
|
|
27322
|
-
* @private
|
|
27323
|
-
*/
|
|
27324
|
-
_checkForConflictingLocalOptions() {
|
|
27325
|
-
const definedNonDefaultOptions = this.options.filter((option) => {
|
|
27326
|
-
const optionKey = option.attributeName();
|
|
27327
|
-
if (this.getOptionValue(optionKey) === void 0) {
|
|
27328
|
-
return false;
|
|
27329
|
-
}
|
|
27330
|
-
return this.getOptionValueSource(optionKey) !== "default";
|
|
27331
|
-
});
|
|
27332
|
-
const optionsWithConflicting = definedNonDefaultOptions.filter(
|
|
27333
|
-
(option) => option.conflictsWith.length > 0
|
|
27334
|
-
);
|
|
27335
|
-
optionsWithConflicting.forEach((option) => {
|
|
27336
|
-
const conflictingAndDefined = definedNonDefaultOptions.find(
|
|
27337
|
-
(defined) => option.conflictsWith.includes(defined.attributeName())
|
|
27338
|
-
);
|
|
27339
|
-
if (conflictingAndDefined) {
|
|
27340
|
-
this._conflictingOption(option, conflictingAndDefined);
|
|
27341
|
-
}
|
|
27342
|
-
});
|
|
27343
|
-
}
|
|
27344
|
-
/**
|
|
27345
|
-
* Display an error message if conflicting options are used together.
|
|
27346
|
-
* Called after checking for help flags in leaf subcommand.
|
|
27347
|
-
*
|
|
27348
|
-
* @private
|
|
27349
|
-
*/
|
|
27350
|
-
_checkForConflictingOptions() {
|
|
27351
|
-
this._getCommandAndAncestors().forEach((cmd) => {
|
|
27352
|
-
cmd._checkForConflictingLocalOptions();
|
|
27353
|
-
});
|
|
27354
|
-
}
|
|
27355
|
-
/**
|
|
27356
|
-
* Parse options from `argv` removing known options,
|
|
27357
|
-
* and return argv split into operands and unknown arguments.
|
|
27358
|
-
*
|
|
27359
|
-
* Side effects: modifies command by storing options. Does not reset state if called again.
|
|
27360
|
-
*
|
|
27361
|
-
* Examples:
|
|
27362
|
-
*
|
|
27363
|
-
* argv => operands, unknown
|
|
27364
|
-
* --known kkk op => [op], []
|
|
27365
|
-
* op --known kkk => [op], []
|
|
27366
|
-
* sub --unknown uuu op => [sub], [--unknown uuu op]
|
|
27367
|
-
* sub -- --unknown uuu op => [sub --unknown uuu op], []
|
|
27368
|
-
*
|
|
27369
|
-
* @param {string[]} args
|
|
27370
|
-
* @return {{operands: string[], unknown: string[]}}
|
|
27371
|
-
*/
|
|
27372
|
-
parseOptions(args) {
|
|
27373
|
-
const operands = [];
|
|
27374
|
-
const unknown = [];
|
|
27375
|
-
let dest = operands;
|
|
27376
|
-
function maybeOption(arg) {
|
|
27377
|
-
return arg.length > 1 && arg[0] === "-";
|
|
27378
|
-
}
|
|
27379
|
-
const negativeNumberArg = (arg) => {
|
|
27380
|
-
if (!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(arg)) return false;
|
|
27381
|
-
return !this._getCommandAndAncestors().some(
|
|
27382
|
-
(cmd) => cmd.options.map((opt) => opt.short).some((short) => /^-\d$/.test(short))
|
|
27383
|
-
);
|
|
27384
|
-
};
|
|
27385
|
-
let activeVariadicOption = null;
|
|
27386
|
-
let activeGroup = null;
|
|
27387
|
-
let i = 0;
|
|
27388
|
-
while (i < args.length || activeGroup) {
|
|
27389
|
-
const arg = activeGroup ?? args[i++];
|
|
27390
|
-
activeGroup = null;
|
|
27391
|
-
if (arg === "--") {
|
|
27392
|
-
if (dest === unknown) dest.push(arg);
|
|
27393
|
-
dest.push(...args.slice(i));
|
|
27394
|
-
break;
|
|
27395
|
-
}
|
|
27396
|
-
if (activeVariadicOption && (!maybeOption(arg) || negativeNumberArg(arg))) {
|
|
27397
|
-
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
27398
|
-
continue;
|
|
27399
|
-
}
|
|
27400
|
-
activeVariadicOption = null;
|
|
27401
|
-
if (maybeOption(arg)) {
|
|
27402
|
-
const option = this._findOption(arg);
|
|
27403
|
-
if (option) {
|
|
27404
|
-
if (option.required) {
|
|
27405
|
-
const value = args[i++];
|
|
27406
|
-
if (value === void 0) this.optionMissingArgument(option);
|
|
27407
|
-
this.emit(`option:${option.name()}`, value);
|
|
27408
|
-
} else if (option.optional) {
|
|
27409
|
-
let value = null;
|
|
27410
|
-
if (i < args.length && (!maybeOption(args[i]) || negativeNumberArg(args[i]))) {
|
|
27411
|
-
value = args[i++];
|
|
27412
|
-
}
|
|
27413
|
-
this.emit(`option:${option.name()}`, value);
|
|
27414
|
-
} else {
|
|
27415
|
-
this.emit(`option:${option.name()}`);
|
|
27416
|
-
}
|
|
27417
|
-
activeVariadicOption = option.variadic ? option : null;
|
|
27418
|
-
continue;
|
|
27419
|
-
}
|
|
27420
|
-
}
|
|
27421
|
-
if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
|
|
27422
|
-
const option = this._findOption(`-${arg[1]}`);
|
|
27423
|
-
if (option) {
|
|
27424
|
-
if (option.required || option.optional && this._combineFlagAndOptionalValue) {
|
|
27425
|
-
this.emit(`option:${option.name()}`, arg.slice(2));
|
|
27426
|
-
} else {
|
|
27427
|
-
this.emit(`option:${option.name()}`);
|
|
27428
|
-
activeGroup = `-${arg.slice(2)}`;
|
|
27429
|
-
}
|
|
27430
|
-
continue;
|
|
27431
|
-
}
|
|
27432
|
-
}
|
|
27433
|
-
if (/^--[^=]+=/.test(arg)) {
|
|
27434
|
-
const index = arg.indexOf("=");
|
|
27435
|
-
const option = this._findOption(arg.slice(0, index));
|
|
27436
|
-
if (option && (option.required || option.optional)) {
|
|
27437
|
-
this.emit(`option:${option.name()}`, arg.slice(index + 1));
|
|
27438
|
-
continue;
|
|
27439
|
-
}
|
|
27440
|
-
}
|
|
27441
|
-
if (dest === operands && maybeOption(arg) && !(this.commands.length === 0 && negativeNumberArg(arg))) {
|
|
27442
|
-
dest = unknown;
|
|
27443
|
-
}
|
|
27444
|
-
if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
|
|
27445
|
-
if (this._findCommand(arg)) {
|
|
27446
|
-
operands.push(arg);
|
|
27447
|
-
unknown.push(...args.slice(i));
|
|
27448
|
-
break;
|
|
27449
|
-
} else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
|
|
27450
|
-
operands.push(arg, ...args.slice(i));
|
|
27451
|
-
break;
|
|
27452
|
-
} else if (this._defaultCommandName) {
|
|
27453
|
-
unknown.push(arg, ...args.slice(i));
|
|
27454
|
-
break;
|
|
27455
|
-
}
|
|
27456
|
-
}
|
|
27457
|
-
if (this._passThroughOptions) {
|
|
27458
|
-
dest.push(arg, ...args.slice(i));
|
|
27459
|
-
break;
|
|
27460
|
-
}
|
|
27461
|
-
dest.push(arg);
|
|
27462
|
-
}
|
|
27463
|
-
return { operands, unknown };
|
|
27464
|
-
}
|
|
27465
|
-
/**
|
|
27466
|
-
* Return an object containing local option values as key-value pairs.
|
|
27467
|
-
*
|
|
27468
|
-
* @return {object}
|
|
27469
|
-
*/
|
|
27470
|
-
opts() {
|
|
27471
|
-
if (this._storeOptionsAsProperties) {
|
|
27472
|
-
const result = {};
|
|
27473
|
-
const len = this.options.length;
|
|
27474
|
-
for (let i = 0; i < len; i++) {
|
|
27475
|
-
const key = this.options[i].attributeName();
|
|
27476
|
-
result[key] = key === this._versionOptionName ? this._version : this[key];
|
|
27477
|
-
}
|
|
27478
|
-
return result;
|
|
27479
|
-
}
|
|
27480
|
-
return this._optionValues;
|
|
27481
|
-
}
|
|
27482
|
-
/**
|
|
27483
|
-
* Return an object containing merged local and global option values as key-value pairs.
|
|
27484
|
-
*
|
|
27485
|
-
* @return {object}
|
|
27486
|
-
*/
|
|
27487
|
-
optsWithGlobals() {
|
|
27488
|
-
return this._getCommandAndAncestors().reduce(
|
|
27489
|
-
(combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()),
|
|
27490
|
-
{}
|
|
27491
|
-
);
|
|
27492
|
-
}
|
|
27493
|
-
/**
|
|
27494
|
-
* Display error message and exit (or call exitOverride).
|
|
27495
|
-
*
|
|
27496
|
-
* @param {string} message
|
|
27497
|
-
* @param {object} [errorOptions]
|
|
27498
|
-
* @param {string} [errorOptions.code] - an id string representing the error
|
|
27499
|
-
* @param {number} [errorOptions.exitCode] - used with process.exit
|
|
27500
|
-
*/
|
|
27501
|
-
error(message, errorOptions) {
|
|
27502
|
-
this._outputConfiguration.outputError(
|
|
27503
|
-
`${message}
|
|
27504
|
-
`,
|
|
27505
|
-
this._outputConfiguration.writeErr
|
|
27506
|
-
);
|
|
27507
|
-
if (typeof this._showHelpAfterError === "string") {
|
|
27508
|
-
this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
27509
|
-
`);
|
|
27510
|
-
} else if (this._showHelpAfterError) {
|
|
27511
|
-
this._outputConfiguration.writeErr("\n");
|
|
27512
|
-
this.outputHelp({ error: true });
|
|
27513
|
-
}
|
|
27514
|
-
const config = errorOptions || {};
|
|
27515
|
-
const exitCode3 = config.exitCode || 1;
|
|
27516
|
-
const code = config.code || "commander.error";
|
|
27517
|
-
this._exit(exitCode3, code, message);
|
|
27518
|
-
}
|
|
27519
|
-
/**
|
|
27520
|
-
* Apply any option related environment variables, if option does
|
|
27521
|
-
* not have a value from cli or client code.
|
|
27522
|
-
*
|
|
27523
|
-
* @private
|
|
27524
|
-
*/
|
|
27525
|
-
_parseOptionsEnv() {
|
|
27526
|
-
this.options.forEach((option) => {
|
|
27527
|
-
if (option.envVar && option.envVar in process2.env) {
|
|
27528
|
-
const optionKey = option.attributeName();
|
|
27529
|
-
if (this.getOptionValue(optionKey) === void 0 || ["default", "config", "env"].includes(
|
|
27530
|
-
this.getOptionValueSource(optionKey)
|
|
27531
|
-
)) {
|
|
27532
|
-
if (option.required || option.optional) {
|
|
27533
|
-
this.emit(`optionEnv:${option.name()}`, process2.env[option.envVar]);
|
|
27534
|
-
} else {
|
|
27535
|
-
this.emit(`optionEnv:${option.name()}`);
|
|
27536
|
-
}
|
|
27537
|
-
}
|
|
27538
|
-
}
|
|
27539
|
-
});
|
|
27540
|
-
}
|
|
27541
|
-
/**
|
|
27542
|
-
* Apply any implied option values, if option is undefined or default value.
|
|
27543
|
-
*
|
|
27544
|
-
* @private
|
|
27545
|
-
*/
|
|
27546
|
-
_parseOptionsImplied() {
|
|
27547
|
-
const dualHelper = new DualOptions(this.options);
|
|
27548
|
-
const hasCustomOptionValue = (optionKey) => {
|
|
27549
|
-
return this.getOptionValue(optionKey) !== void 0 && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
|
|
27550
|
-
};
|
|
27551
|
-
this.options.filter(
|
|
27552
|
-
(option) => option.implied !== void 0 && hasCustomOptionValue(option.attributeName()) && dualHelper.valueFromOption(
|
|
27553
|
-
this.getOptionValue(option.attributeName()),
|
|
27554
|
-
option
|
|
27555
|
-
)
|
|
27556
|
-
).forEach((option) => {
|
|
27557
|
-
Object.keys(option.implied).filter((impliedKey) => !hasCustomOptionValue(impliedKey)).forEach((impliedKey) => {
|
|
27558
|
-
this.setOptionValueWithSource(
|
|
27559
|
-
impliedKey,
|
|
27560
|
-
option.implied[impliedKey],
|
|
27561
|
-
"implied"
|
|
27562
|
-
);
|
|
27563
|
-
});
|
|
27564
|
-
});
|
|
27565
|
-
}
|
|
27566
|
-
/**
|
|
27567
|
-
* Argument `name` is missing.
|
|
27568
|
-
*
|
|
27569
|
-
* @param {string} name
|
|
27570
|
-
* @private
|
|
27571
|
-
*/
|
|
27572
|
-
missingArgument(name) {
|
|
27573
|
-
const message = `error: missing required argument '${name}'`;
|
|
27574
|
-
this.error(message, { code: "commander.missingArgument" });
|
|
27575
|
-
}
|
|
27576
|
-
/**
|
|
27577
|
-
* `Option` is missing an argument.
|
|
27578
|
-
*
|
|
27579
|
-
* @param {Option} option
|
|
27580
|
-
* @private
|
|
27581
|
-
*/
|
|
27582
|
-
optionMissingArgument(option) {
|
|
27583
|
-
const message = `error: option '${option.flags}' argument missing`;
|
|
27584
|
-
this.error(message, { code: "commander.optionMissingArgument" });
|
|
27585
|
-
}
|
|
27586
|
-
/**
|
|
27587
|
-
* `Option` does not have a value, and is a mandatory option.
|
|
27588
|
-
*
|
|
27589
|
-
* @param {Option} option
|
|
27590
|
-
* @private
|
|
27591
|
-
*/
|
|
27592
|
-
missingMandatoryOptionValue(option) {
|
|
27593
|
-
const message = `error: required option '${option.flags}' not specified`;
|
|
27594
|
-
this.error(message, { code: "commander.missingMandatoryOptionValue" });
|
|
27595
|
-
}
|
|
27596
|
-
/**
|
|
27597
|
-
* `Option` conflicts with another option.
|
|
27598
|
-
*
|
|
27599
|
-
* @param {Option} option
|
|
27600
|
-
* @param {Option} conflictingOption
|
|
27601
|
-
* @private
|
|
27602
|
-
*/
|
|
27603
|
-
_conflictingOption(option, conflictingOption) {
|
|
27604
|
-
const findBestOptionFromValue = (option2) => {
|
|
27605
|
-
const optionKey = option2.attributeName();
|
|
27606
|
-
const optionValue = this.getOptionValue(optionKey);
|
|
27607
|
-
const negativeOption = this.options.find(
|
|
27608
|
-
(target) => target.negate && optionKey === target.attributeName()
|
|
27609
|
-
);
|
|
27610
|
-
const positiveOption = this.options.find(
|
|
27611
|
-
(target) => !target.negate && optionKey === target.attributeName()
|
|
27612
|
-
);
|
|
27613
|
-
if (negativeOption && (negativeOption.presetArg === void 0 && optionValue === false || negativeOption.presetArg !== void 0 && optionValue === negativeOption.presetArg)) {
|
|
27614
|
-
return negativeOption;
|
|
27615
|
-
}
|
|
27616
|
-
return positiveOption || option2;
|
|
27617
|
-
};
|
|
27618
|
-
const getErrorMessage = (option2) => {
|
|
27619
|
-
const bestOption = findBestOptionFromValue(option2);
|
|
27620
|
-
const optionKey = bestOption.attributeName();
|
|
27621
|
-
const source = this.getOptionValueSource(optionKey);
|
|
27622
|
-
if (source === "env") {
|
|
27623
|
-
return `environment variable '${bestOption.envVar}'`;
|
|
27624
|
-
}
|
|
27625
|
-
return `option '${bestOption.flags}'`;
|
|
27626
|
-
};
|
|
27627
|
-
const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
|
|
27628
|
-
this.error(message, { code: "commander.conflictingOption" });
|
|
27629
|
-
}
|
|
27630
|
-
/**
|
|
27631
|
-
* Unknown option `flag`.
|
|
27632
|
-
*
|
|
27633
|
-
* @param {string} flag
|
|
27634
|
-
* @private
|
|
27635
|
-
*/
|
|
27636
|
-
unknownOption(flag) {
|
|
27637
|
-
if (this._allowUnknownOption) return;
|
|
27638
|
-
let suggestion = "";
|
|
27639
|
-
if (flag.startsWith("--") && this._showSuggestionAfterError) {
|
|
27640
|
-
let candidateFlags = [];
|
|
27641
|
-
let command = this;
|
|
27642
|
-
do {
|
|
27643
|
-
const moreFlags = command.createHelp().visibleOptions(command).filter((option) => option.long).map((option) => option.long);
|
|
27644
|
-
candidateFlags = candidateFlags.concat(moreFlags);
|
|
27645
|
-
command = command.parent;
|
|
27646
|
-
} while (command && !command._enablePositionalOptions);
|
|
27647
|
-
suggestion = suggestSimilar(flag, candidateFlags);
|
|
27648
|
-
}
|
|
27649
|
-
const message = `error: unknown option '${flag}'${suggestion}`;
|
|
27650
|
-
this.error(message, { code: "commander.unknownOption" });
|
|
27651
|
-
}
|
|
27652
|
-
/**
|
|
27653
|
-
* Excess arguments, more than expected.
|
|
27654
|
-
*
|
|
27655
|
-
* @param {string[]} receivedArgs
|
|
27656
|
-
* @private
|
|
27657
|
-
*/
|
|
27658
|
-
_excessArguments(receivedArgs) {
|
|
27659
|
-
if (this._allowExcessArguments) return;
|
|
27660
|
-
const expected = this.registeredArguments.length;
|
|
27661
|
-
const s = expected === 1 ? "" : "s";
|
|
27662
|
-
const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
|
|
27663
|
-
const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
|
|
27664
|
-
this.error(message, { code: "commander.excessArguments" });
|
|
27665
|
-
}
|
|
27666
|
-
/**
|
|
27667
|
-
* Unknown command.
|
|
27668
|
-
*
|
|
27669
|
-
* @private
|
|
27670
|
-
*/
|
|
27671
|
-
unknownCommand() {
|
|
27672
|
-
const unknownName = this.args[0];
|
|
27673
|
-
let suggestion = "";
|
|
27674
|
-
if (this._showSuggestionAfterError) {
|
|
27675
|
-
const candidateNames = [];
|
|
27676
|
-
this.createHelp().visibleCommands(this).forEach((command) => {
|
|
27677
|
-
candidateNames.push(command.name());
|
|
27678
|
-
if (command.alias()) candidateNames.push(command.alias());
|
|
27679
|
-
});
|
|
27680
|
-
suggestion = suggestSimilar(unknownName, candidateNames);
|
|
27681
|
-
}
|
|
27682
|
-
const message = `error: unknown command '${unknownName}'${suggestion}`;
|
|
27683
|
-
this.error(message, { code: "commander.unknownCommand" });
|
|
27684
|
-
}
|
|
27685
|
-
/**
|
|
27686
|
-
* Get or set the program version.
|
|
27687
|
-
*
|
|
27688
|
-
* This method auto-registers the "-V, --version" option which will print the version number.
|
|
27689
|
-
*
|
|
27690
|
-
* You can optionally supply the flags and description to override the defaults.
|
|
27691
|
-
*
|
|
27692
|
-
* @param {string} [str]
|
|
27693
|
-
* @param {string} [flags]
|
|
27694
|
-
* @param {string} [description]
|
|
27695
|
-
* @return {(this | string | undefined)} `this` command for chaining, or version string if no arguments
|
|
27696
|
-
*/
|
|
27697
|
-
version(str3, flags, description) {
|
|
27698
|
-
if (str3 === void 0) return this._version;
|
|
27699
|
-
this._version = str3;
|
|
27700
|
-
flags = flags || "-V, --version";
|
|
27701
|
-
description = description || "output the version number";
|
|
27702
|
-
const versionOption = this.createOption(flags, description);
|
|
27703
|
-
this._versionOptionName = versionOption.attributeName();
|
|
27704
|
-
this._registerOption(versionOption);
|
|
27705
|
-
this.on("option:" + versionOption.name(), () => {
|
|
27706
|
-
this._outputConfiguration.writeOut(`${str3}
|
|
27707
|
-
`);
|
|
27708
|
-
this._exit(0, "commander.version", str3);
|
|
27709
|
-
});
|
|
27710
|
-
return this;
|
|
27711
|
-
}
|
|
27712
|
-
/**
|
|
27713
|
-
* Set the description.
|
|
27714
|
-
*
|
|
27715
|
-
* @param {string} [str]
|
|
27716
|
-
* @param {object} [argsDescription]
|
|
27717
|
-
* @return {(string|Command)}
|
|
27718
|
-
*/
|
|
27719
|
-
description(str3, argsDescription) {
|
|
27720
|
-
if (str3 === void 0 && argsDescription === void 0)
|
|
27721
|
-
return this._description;
|
|
27722
|
-
this._description = str3;
|
|
27723
|
-
if (argsDescription) {
|
|
27724
|
-
this._argsDescription = argsDescription;
|
|
27725
|
-
}
|
|
27726
|
-
return this;
|
|
27727
|
-
}
|
|
27728
|
-
/**
|
|
27729
|
-
* Set the summary. Used when listed as subcommand of parent.
|
|
27730
|
-
*
|
|
27731
|
-
* @param {string} [str]
|
|
27732
|
-
* @return {(string|Command)}
|
|
27733
|
-
*/
|
|
27734
|
-
summary(str3) {
|
|
27735
|
-
if (str3 === void 0) return this._summary;
|
|
27736
|
-
this._summary = str3;
|
|
27737
|
-
return this;
|
|
27738
|
-
}
|
|
27739
|
-
/**
|
|
27740
|
-
* Set an alias for the command.
|
|
27741
|
-
*
|
|
27742
|
-
* You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.
|
|
27743
|
-
*
|
|
27744
|
-
* @param {string} [alias]
|
|
27745
|
-
* @return {(string|Command)}
|
|
27746
|
-
*/
|
|
27747
|
-
alias(alias) {
|
|
27748
|
-
if (alias === void 0) return this._aliases[0];
|
|
27749
|
-
let command = this;
|
|
27750
|
-
if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
|
|
27751
|
-
command = this.commands[this.commands.length - 1];
|
|
27752
|
-
}
|
|
27753
|
-
if (alias === command._name)
|
|
27754
|
-
throw new Error("Command alias can't be the same as its name");
|
|
27755
|
-
const matchingCommand = this.parent?._findCommand(alias);
|
|
27756
|
-
if (matchingCommand) {
|
|
27757
|
-
const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join("|");
|
|
27758
|
-
throw new Error(
|
|
27759
|
-
`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`
|
|
27760
|
-
);
|
|
27761
|
-
}
|
|
27762
|
-
command._aliases.push(alias);
|
|
27763
|
-
return this;
|
|
27764
|
-
}
|
|
27765
|
-
/**
|
|
27766
|
-
* Set aliases for the command.
|
|
27767
|
-
*
|
|
27768
|
-
* Only the first alias is shown in the auto-generated help.
|
|
27769
|
-
*
|
|
27770
|
-
* @param {string[]} [aliases]
|
|
27771
|
-
* @return {(string[]|Command)}
|
|
27772
|
-
*/
|
|
27773
|
-
aliases(aliases) {
|
|
27774
|
-
if (aliases === void 0) return this._aliases;
|
|
27775
|
-
aliases.forEach((alias) => this.alias(alias));
|
|
27776
|
-
return this;
|
|
27777
|
-
}
|
|
27778
|
-
/**
|
|
27779
|
-
* Set / get the command usage `str`.
|
|
27780
|
-
*
|
|
27781
|
-
* @param {string} [str]
|
|
27782
|
-
* @return {(string|Command)}
|
|
27783
|
-
*/
|
|
27784
|
-
usage(str3) {
|
|
27785
|
-
if (str3 === void 0) {
|
|
27786
|
-
if (this._usage) return this._usage;
|
|
27787
|
-
const args = this.registeredArguments.map((arg) => {
|
|
27788
|
-
return humanReadableArgName(arg);
|
|
27789
|
-
});
|
|
27790
|
-
return [].concat(
|
|
27791
|
-
this.options.length || this._helpOption !== null ? "[options]" : [],
|
|
27792
|
-
this.commands.length ? "[command]" : [],
|
|
27793
|
-
this.registeredArguments.length ? args : []
|
|
27794
|
-
).join(" ");
|
|
27795
|
-
}
|
|
27796
|
-
this._usage = str3;
|
|
27797
|
-
return this;
|
|
27798
|
-
}
|
|
27799
|
-
/**
|
|
27800
|
-
* Get or set the name of the command.
|
|
27801
|
-
*
|
|
27802
|
-
* @param {string} [str]
|
|
27803
|
-
* @return {(string|Command)}
|
|
27804
|
-
*/
|
|
27805
|
-
name(str3) {
|
|
27806
|
-
if (str3 === void 0) return this._name;
|
|
27807
|
-
this._name = str3;
|
|
27808
|
-
return this;
|
|
27809
|
-
}
|
|
27810
|
-
/**
|
|
27811
|
-
* Set/get the help group heading for this subcommand in parent command's help.
|
|
27812
|
-
*
|
|
27813
|
-
* @param {string} [heading]
|
|
27814
|
-
* @return {Command | string}
|
|
27815
|
-
*/
|
|
27816
|
-
helpGroup(heading) {
|
|
27817
|
-
if (heading === void 0) return this._helpGroupHeading ?? "";
|
|
27818
|
-
this._helpGroupHeading = heading;
|
|
27819
|
-
return this;
|
|
27820
|
-
}
|
|
27821
|
-
/**
|
|
27822
|
-
* Set/get the default help group heading for subcommands added to this command.
|
|
27823
|
-
* (This does not override a group set directly on the subcommand using .helpGroup().)
|
|
27824
|
-
*
|
|
27825
|
-
* @example
|
|
27826
|
-
* program.commandsGroup('Development Commands:);
|
|
27827
|
-
* program.command('watch')...
|
|
27828
|
-
* program.command('lint')...
|
|
27829
|
-
* ...
|
|
27830
|
-
*
|
|
27831
|
-
* @param {string} [heading]
|
|
27832
|
-
* @returns {Command | string}
|
|
27833
|
-
*/
|
|
27834
|
-
commandsGroup(heading) {
|
|
27835
|
-
if (heading === void 0) return this._defaultCommandGroup ?? "";
|
|
27836
|
-
this._defaultCommandGroup = heading;
|
|
27837
|
-
return this;
|
|
27838
|
-
}
|
|
27839
|
-
/**
|
|
27840
|
-
* Set/get the default help group heading for options added to this command.
|
|
27841
|
-
* (This does not override a group set directly on the option using .helpGroup().)
|
|
27842
|
-
*
|
|
27843
|
-
* @example
|
|
27844
|
-
* program
|
|
27845
|
-
* .optionsGroup('Development Options:')
|
|
27846
|
-
* .option('-d, --debug', 'output extra debugging')
|
|
27847
|
-
* .option('-p, --profile', 'output profiling information')
|
|
27848
|
-
*
|
|
27849
|
-
* @param {string} [heading]
|
|
27850
|
-
* @returns {Command | string}
|
|
27851
|
-
*/
|
|
27852
|
-
optionsGroup(heading) {
|
|
27853
|
-
if (heading === void 0) return this._defaultOptionGroup ?? "";
|
|
27854
|
-
this._defaultOptionGroup = heading;
|
|
27855
|
-
return this;
|
|
27856
|
-
}
|
|
27857
|
-
/**
|
|
27858
|
-
* @param {Option} option
|
|
27859
|
-
* @private
|
|
27860
|
-
*/
|
|
27861
|
-
_initOptionGroup(option) {
|
|
27862
|
-
if (this._defaultOptionGroup && !option.helpGroupHeading)
|
|
27863
|
-
option.helpGroup(this._defaultOptionGroup);
|
|
27864
|
-
}
|
|
27865
|
-
/**
|
|
27866
|
-
* @param {Command} cmd
|
|
27867
|
-
* @private
|
|
27868
|
-
*/
|
|
27869
|
-
_initCommandGroup(cmd) {
|
|
27870
|
-
if (this._defaultCommandGroup && !cmd.helpGroup())
|
|
27871
|
-
cmd.helpGroup(this._defaultCommandGroup);
|
|
27872
|
-
}
|
|
27873
|
-
/**
|
|
27874
|
-
* Set the name of the command from script filename, such as process.argv[1],
|
|
27875
|
-
* or require.main.filename, or __filename.
|
|
27876
|
-
*
|
|
27877
|
-
* (Used internally and public although not documented in README.)
|
|
27878
|
-
*
|
|
27879
|
-
* @example
|
|
27880
|
-
* program.nameFromFilename(require.main.filename);
|
|
27881
|
-
*
|
|
27882
|
-
* @param {string} filename
|
|
27883
|
-
* @return {Command}
|
|
27884
|
-
*/
|
|
27885
|
-
nameFromFilename(filename) {
|
|
27886
|
-
this._name = path19.basename(filename, path19.extname(filename));
|
|
27887
|
-
return this;
|
|
27888
|
-
}
|
|
27889
|
-
/**
|
|
27890
|
-
* Get or set the directory for searching for executable subcommands of this command.
|
|
27891
|
-
*
|
|
27892
|
-
* @example
|
|
27893
|
-
* program.executableDir(__dirname);
|
|
27894
|
-
* // or
|
|
27895
|
-
* program.executableDir('subcommands');
|
|
27896
|
-
*
|
|
27897
|
-
* @param {string} [path]
|
|
27898
|
-
* @return {(string|null|Command)}
|
|
27899
|
-
*/
|
|
27900
|
-
executableDir(path20) {
|
|
27901
|
-
if (path20 === void 0) return this._executableDir;
|
|
27902
|
-
this._executableDir = path20;
|
|
27903
|
-
return this;
|
|
27904
|
-
}
|
|
27905
|
-
/**
|
|
27906
|
-
* Return program help documentation.
|
|
27907
|
-
*
|
|
27908
|
-
* @param {{ error: boolean }} [contextOptions] - pass {error:true} to wrap for stderr instead of stdout
|
|
27909
|
-
* @return {string}
|
|
27910
|
-
*/
|
|
27911
|
-
helpInformation(contextOptions) {
|
|
27912
|
-
const helper = this.createHelp();
|
|
27913
|
-
const context = this._getOutputContext(contextOptions);
|
|
27914
|
-
helper.prepareContext({
|
|
27915
|
-
error: context.error,
|
|
27916
|
-
helpWidth: context.helpWidth,
|
|
27917
|
-
outputHasColors: context.hasColors
|
|
27918
|
-
});
|
|
27919
|
-
const text = helper.formatHelp(this, helper);
|
|
27920
|
-
if (context.hasColors) return text;
|
|
27921
|
-
return this._outputConfiguration.stripColor(text);
|
|
27922
|
-
}
|
|
27923
|
-
/**
|
|
27924
|
-
* @typedef HelpContext
|
|
27925
|
-
* @type {object}
|
|
27926
|
-
* @property {boolean} error
|
|
27927
|
-
* @property {number} helpWidth
|
|
27928
|
-
* @property {boolean} hasColors
|
|
27929
|
-
* @property {function} write - includes stripColor if needed
|
|
27930
|
-
*
|
|
27931
|
-
* @returns {HelpContext}
|
|
27932
|
-
* @private
|
|
27933
|
-
*/
|
|
27934
|
-
_getOutputContext(contextOptions) {
|
|
27935
|
-
contextOptions = contextOptions || {};
|
|
27936
|
-
const error3 = !!contextOptions.error;
|
|
27937
|
-
let baseWrite;
|
|
27938
|
-
let hasColors;
|
|
27939
|
-
let helpWidth;
|
|
27940
|
-
if (error3) {
|
|
27941
|
-
baseWrite = (str3) => this._outputConfiguration.writeErr(str3);
|
|
27942
|
-
hasColors = this._outputConfiguration.getErrHasColors();
|
|
27943
|
-
helpWidth = this._outputConfiguration.getErrHelpWidth();
|
|
27944
|
-
} else {
|
|
27945
|
-
baseWrite = (str3) => this._outputConfiguration.writeOut(str3);
|
|
27946
|
-
hasColors = this._outputConfiguration.getOutHasColors();
|
|
27947
|
-
helpWidth = this._outputConfiguration.getOutHelpWidth();
|
|
27948
|
-
}
|
|
27949
|
-
const write = (str3) => {
|
|
27950
|
-
if (!hasColors) str3 = this._outputConfiguration.stripColor(str3);
|
|
27951
|
-
return baseWrite(str3);
|
|
27952
|
-
};
|
|
27953
|
-
return { error: error3, write, hasColors, helpWidth };
|
|
27954
|
-
}
|
|
27955
|
-
/**
|
|
27956
|
-
* Output help information for this command.
|
|
27957
|
-
*
|
|
27958
|
-
* Outputs built-in help, and custom text added using `.addHelpText()`.
|
|
27959
|
-
*
|
|
27960
|
-
* @param {{ error: boolean } | Function} [contextOptions] - pass {error:true} to write to stderr instead of stdout
|
|
27961
|
-
*/
|
|
27962
|
-
outputHelp(contextOptions) {
|
|
27963
|
-
let deprecatedCallback;
|
|
27964
|
-
if (typeof contextOptions === "function") {
|
|
27965
|
-
deprecatedCallback = contextOptions;
|
|
27966
|
-
contextOptions = void 0;
|
|
27967
|
-
}
|
|
27968
|
-
const outputContext = this._getOutputContext(contextOptions);
|
|
27969
|
-
const eventContext = {
|
|
27970
|
-
error: outputContext.error,
|
|
27971
|
-
write: outputContext.write,
|
|
27972
|
-
command: this
|
|
27973
|
-
};
|
|
27974
|
-
this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", eventContext));
|
|
27975
|
-
this.emit("beforeHelp", eventContext);
|
|
27976
|
-
let helpInformation = this.helpInformation({ error: outputContext.error });
|
|
27977
|
-
if (deprecatedCallback) {
|
|
27978
|
-
helpInformation = deprecatedCallback(helpInformation);
|
|
27979
|
-
if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
|
|
27980
|
-
throw new Error("outputHelp callback must return a string or a Buffer");
|
|
27981
|
-
}
|
|
27982
|
-
}
|
|
27983
|
-
outputContext.write(helpInformation);
|
|
27984
|
-
if (this._getHelpOption()?.long) {
|
|
27985
|
-
this.emit(this._getHelpOption().long);
|
|
27986
|
-
}
|
|
27987
|
-
this.emit("afterHelp", eventContext);
|
|
27988
|
-
this._getCommandAndAncestors().forEach(
|
|
27989
|
-
(command) => command.emit("afterAllHelp", eventContext)
|
|
27990
|
-
);
|
|
27991
|
-
}
|
|
27992
|
-
/**
|
|
27993
|
-
* You can pass in flags and a description to customise the built-in help option.
|
|
27994
|
-
* Pass in false to disable the built-in help option.
|
|
27995
|
-
*
|
|
27996
|
-
* @example
|
|
27997
|
-
* program.helpOption('-?, --help' 'show help'); // customise
|
|
27998
|
-
* program.helpOption(false); // disable
|
|
27999
|
-
*
|
|
28000
|
-
* @param {(string | boolean)} flags
|
|
28001
|
-
* @param {string} [description]
|
|
28002
|
-
* @return {Command} `this` command for chaining
|
|
28003
|
-
*/
|
|
28004
|
-
helpOption(flags, description) {
|
|
28005
|
-
if (typeof flags === "boolean") {
|
|
28006
|
-
if (flags) {
|
|
28007
|
-
if (this._helpOption === null) this._helpOption = void 0;
|
|
28008
|
-
if (this._defaultOptionGroup) {
|
|
28009
|
-
this._initOptionGroup(this._getHelpOption());
|
|
28010
|
-
}
|
|
28011
|
-
} else {
|
|
28012
|
-
this._helpOption = null;
|
|
28013
|
-
}
|
|
28014
|
-
return this;
|
|
28015
|
-
}
|
|
28016
|
-
this._helpOption = this.createOption(
|
|
28017
|
-
flags ?? "-h, --help",
|
|
28018
|
-
description ?? "display help for command"
|
|
28019
|
-
);
|
|
28020
|
-
if (flags || description) this._initOptionGroup(this._helpOption);
|
|
28021
|
-
return this;
|
|
28022
|
-
}
|
|
28023
|
-
/**
|
|
28024
|
-
* Lazy create help option.
|
|
28025
|
-
* Returns null if has been disabled with .helpOption(false).
|
|
28026
|
-
*
|
|
28027
|
-
* @returns {(Option | null)} the help option
|
|
28028
|
-
* @package
|
|
28029
|
-
*/
|
|
28030
|
-
_getHelpOption() {
|
|
28031
|
-
if (this._helpOption === void 0) {
|
|
28032
|
-
this.helpOption(void 0, void 0);
|
|
28033
|
-
}
|
|
28034
|
-
return this._helpOption;
|
|
28035
|
-
}
|
|
28036
|
-
/**
|
|
28037
|
-
* Supply your own option to use for the built-in help option.
|
|
28038
|
-
* This is an alternative to using helpOption() to customise the flags and description etc.
|
|
28039
|
-
*
|
|
28040
|
-
* @param {Option} option
|
|
28041
|
-
* @return {Command} `this` command for chaining
|
|
28042
|
-
*/
|
|
28043
|
-
addHelpOption(option) {
|
|
28044
|
-
this._helpOption = option;
|
|
28045
|
-
this._initOptionGroup(option);
|
|
28046
|
-
return this;
|
|
28047
|
-
}
|
|
28048
|
-
/**
|
|
28049
|
-
* Output help information and exit.
|
|
28050
|
-
*
|
|
28051
|
-
* Outputs built-in help, and custom text added using `.addHelpText()`.
|
|
28052
|
-
*
|
|
28053
|
-
* @param {{ error: boolean }} [contextOptions] - pass {error:true} to write to stderr instead of stdout
|
|
28054
|
-
*/
|
|
28055
|
-
help(contextOptions) {
|
|
28056
|
-
this.outputHelp(contextOptions);
|
|
28057
|
-
let exitCode3 = Number(process2.exitCode ?? 0);
|
|
28058
|
-
if (exitCode3 === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
|
|
28059
|
-
exitCode3 = 1;
|
|
28060
|
-
}
|
|
28061
|
-
this._exit(exitCode3, "commander.help", "(outputHelp)");
|
|
28062
|
-
}
|
|
28063
|
-
/**
|
|
28064
|
-
* // Do a little typing to coordinate emit and listener for the help text events.
|
|
28065
|
-
* @typedef HelpTextEventContext
|
|
28066
|
-
* @type {object}
|
|
28067
|
-
* @property {boolean} error
|
|
28068
|
-
* @property {Command} command
|
|
28069
|
-
* @property {function} write
|
|
28070
|
-
*/
|
|
28071
|
-
/**
|
|
28072
|
-
* Add additional text to be displayed with the built-in help.
|
|
28073
|
-
*
|
|
28074
|
-
* Position is 'before' or 'after' to affect just this command,
|
|
28075
|
-
* and 'beforeAll' or 'afterAll' to affect this command and all its subcommands.
|
|
28076
|
-
*
|
|
28077
|
-
* @param {string} position - before or after built-in help
|
|
28078
|
-
* @param {(string | Function)} text - string to add, or a function returning a string
|
|
28079
|
-
* @return {Command} `this` command for chaining
|
|
28080
|
-
*/
|
|
28081
|
-
addHelpText(position, text) {
|
|
28082
|
-
const allowedValues = ["beforeAll", "before", "after", "afterAll"];
|
|
28083
|
-
if (!allowedValues.includes(position)) {
|
|
28084
|
-
throw new Error(`Unexpected value for position to addHelpText.
|
|
28085
|
-
Expecting one of '${allowedValues.join("', '")}'`);
|
|
28086
|
-
}
|
|
28087
|
-
const helpEvent = `${position}Help`;
|
|
28088
|
-
this.on(helpEvent, (context) => {
|
|
28089
|
-
let helpStr;
|
|
28090
|
-
if (typeof text === "function") {
|
|
28091
|
-
helpStr = text({ error: context.error, command: context.command });
|
|
28092
|
-
} else {
|
|
28093
|
-
helpStr = text;
|
|
28094
|
-
}
|
|
28095
|
-
if (helpStr) {
|
|
28096
|
-
context.write(`${helpStr}
|
|
28097
|
-
`);
|
|
28098
|
-
}
|
|
28099
|
-
});
|
|
28100
|
-
return this;
|
|
28101
|
-
}
|
|
28102
|
-
/**
|
|
28103
|
-
* Output help information if help flags specified
|
|
28104
|
-
*
|
|
28105
|
-
* @param {Array} args - array of options to search for help flags
|
|
28106
|
-
* @private
|
|
28107
|
-
*/
|
|
28108
|
-
_outputHelpIfRequested(args) {
|
|
28109
|
-
const helpOption = this._getHelpOption();
|
|
28110
|
-
const helpRequested = helpOption && args.find((arg) => helpOption.is(arg));
|
|
28111
|
-
if (helpRequested) {
|
|
28112
|
-
this.outputHelp();
|
|
28113
|
-
this._exit(0, "commander.helpDisplayed", "(outputHelp)");
|
|
28114
|
-
}
|
|
28115
|
-
}
|
|
28116
|
-
};
|
|
28117
|
-
function incrementNodeInspectorPort(args) {
|
|
28118
|
-
return args.map((arg) => {
|
|
28119
|
-
if (!arg.startsWith("--inspect")) {
|
|
28120
|
-
return arg;
|
|
28121
|
-
}
|
|
28122
|
-
let debugOption;
|
|
28123
|
-
let debugHost = "127.0.0.1";
|
|
28124
|
-
let debugPort = "9229";
|
|
28125
|
-
let match2;
|
|
28126
|
-
if ((match2 = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
|
|
28127
|
-
debugOption = match2[1];
|
|
28128
|
-
} else if ((match2 = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
|
|
28129
|
-
debugOption = match2[1];
|
|
28130
|
-
if (/^\d+$/.test(match2[3])) {
|
|
28131
|
-
debugPort = match2[3];
|
|
28132
|
-
} else {
|
|
28133
|
-
debugHost = match2[3];
|
|
28134
|
-
}
|
|
28135
|
-
} else if ((match2 = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
|
|
28136
|
-
debugOption = match2[1];
|
|
28137
|
-
debugHost = match2[3];
|
|
28138
|
-
debugPort = match2[4];
|
|
28139
|
-
}
|
|
28140
|
-
if (debugOption && debugPort !== "0") {
|
|
28141
|
-
return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
|
|
28142
|
-
}
|
|
28143
|
-
return arg;
|
|
28144
|
-
});
|
|
28145
|
-
}
|
|
28146
|
-
function useColor() {
|
|
28147
|
-
if (process2.env.NO_COLOR || process2.env.FORCE_COLOR === "0" || process2.env.FORCE_COLOR === "false")
|
|
28148
|
-
return false;
|
|
28149
|
-
if (process2.env.FORCE_COLOR || process2.env.CLICOLOR_FORCE !== void 0)
|
|
28150
|
-
return true;
|
|
28151
|
-
return void 0;
|
|
28152
|
-
}
|
|
28153
|
-
exports2.Command = Command2;
|
|
28154
|
-
exports2.useColor = useColor;
|
|
28155
|
-
}
|
|
28156
|
-
});
|
|
28157
|
-
|
|
28158
|
-
// ../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/index.js
|
|
28159
|
-
var require_commander = __commonJS({
|
|
28160
|
-
"../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/index.js"(exports2) {
|
|
28161
|
-
"use strict";
|
|
28162
|
-
var { Argument: Argument2 } = require_argument();
|
|
28163
|
-
var { Command: Command2 } = require_command();
|
|
28164
|
-
var { CommanderError: CommanderError2, InvalidArgumentError: InvalidArgumentError2 } = require_error();
|
|
28165
|
-
var { Help: Help2 } = require_help();
|
|
28166
|
-
var { Option: Option2 } = require_option();
|
|
28167
|
-
exports2.program = new Command2();
|
|
28168
|
-
exports2.createCommand = (name) => new Command2(name);
|
|
28169
|
-
exports2.createOption = (flags, description) => new Option2(flags, description);
|
|
28170
|
-
exports2.createArgument = (name, description) => new Argument2(name, description);
|
|
28171
|
-
exports2.Command = Command2;
|
|
28172
|
-
exports2.Option = Option2;
|
|
28173
|
-
exports2.Argument = Argument2;
|
|
28174
|
-
exports2.Help = Help2;
|
|
28175
|
-
exports2.CommanderError = CommanderError2;
|
|
28176
|
-
exports2.InvalidArgumentError = InvalidArgumentError2;
|
|
28177
|
-
exports2.InvalidOptionArgumentError = InvalidArgumentError2;
|
|
28178
|
-
}
|
|
28179
|
-
});
|
|
28180
|
-
|
|
28181
|
-
// ../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/esm.mjs
|
|
28182
|
-
var import_index, program, createCommand, createArgument, createOption, CommanderError, InvalidArgumentError, InvalidOptionArgumentError, Command, Argument, Option, Help;
|
|
28183
|
-
var init_esm = __esm({
|
|
28184
|
-
"../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/esm.mjs"() {
|
|
28185
|
-
"use strict";
|
|
28186
|
-
import_index = __toESM(require_commander(), 1);
|
|
28187
|
-
({
|
|
28188
|
-
program,
|
|
28189
|
-
createCommand,
|
|
28190
|
-
createArgument,
|
|
28191
|
-
createOption,
|
|
28192
|
-
CommanderError,
|
|
28193
|
-
InvalidArgumentError,
|
|
28194
|
-
InvalidOptionArgumentError,
|
|
28195
|
-
Command: (
|
|
28196
|
-
// deprecated old name
|
|
28197
|
-
Command
|
|
28198
|
-
),
|
|
28199
|
-
Argument,
|
|
28200
|
-
Option,
|
|
28201
|
-
Help
|
|
28202
|
-
} = import_index.default);
|
|
28203
|
-
}
|
|
28204
|
-
});
|
|
28205
|
-
|
|
28206
24748
|
// ../notes/dist/chunk-F7MUVHZ2.js
|
|
28207
24749
|
import * as fs5 from "fs";
|
|
28208
24750
|
import * as path6 from "path";
|
|
@@ -28392,6 +24934,7 @@ import * as fs8 from "fs";
|
|
|
28392
24934
|
import * as path62 from "path";
|
|
28393
24935
|
import * as fs10 from "fs";
|
|
28394
24936
|
import * as readline from "readline";
|
|
24937
|
+
import { Command } from "commander";
|
|
28395
24938
|
function parseJsonc(content) {
|
|
28396
24939
|
if (content.length > MAX_JSONC_LENGTH) {
|
|
28397
24940
|
throw new Error(`JSONC content too long: ${content.length} characters (max ${MAX_JSONC_LENGTH})`);
|
|
@@ -29712,7 +26255,6 @@ var init_chunk_Y4S5UWCL = __esm({
|
|
|
29712
26255
|
init_ejs();
|
|
29713
26256
|
import_handlebars = __toESM(require_lib(), 1);
|
|
29714
26257
|
init_liquid_node();
|
|
29715
|
-
init_esm();
|
|
29716
26258
|
ConfigError = class extends ReleaseKitError2 {
|
|
29717
26259
|
code = "CONFIG_ERROR";
|
|
29718
26260
|
suggestions;
|
|
@@ -32332,6 +28874,7 @@ import * as fs92 from "fs";
|
|
|
32332
28874
|
import * as path9 from "path";
|
|
32333
28875
|
import * as fs102 from "fs";
|
|
32334
28876
|
import { z as z32 } from "zod";
|
|
28877
|
+
import { Command as Command2 } from "commander";
|
|
32335
28878
|
function setLogLevel3(level) {
|
|
32336
28879
|
currentLevel3 = level;
|
|
32337
28880
|
}
|
|
@@ -33789,7 +30332,7 @@ async function readStdin2() {
|
|
|
33789
30332
|
return chunks.join("");
|
|
33790
30333
|
}
|
|
33791
30334
|
function createPublishCommand() {
|
|
33792
|
-
return new
|
|
30335
|
+
return new Command2("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) => {
|
|
33793
30336
|
if (options.verbose) setLogLevel3("debug");
|
|
33794
30337
|
if (options.json) setJsonMode2(true);
|
|
33795
30338
|
try {
|
|
@@ -33844,7 +30387,6 @@ var init_chunk_OZHNJUFW = __esm({
|
|
|
33844
30387
|
"../publish/dist/chunk-OZHNJUFW.js"() {
|
|
33845
30388
|
"use strict";
|
|
33846
30389
|
import_semver = __toESM(require_semver2(), 1);
|
|
33847
|
-
init_esm();
|
|
33848
30390
|
LOG_LEVELS3 = {
|
|
33849
30391
|
error: 0,
|
|
33850
30392
|
warn: 1,
|
|
@@ -37749,7 +34291,7 @@ var init_node_figlet = __esm({
|
|
|
37749
34291
|
|
|
37750
34292
|
// ../../node_modules/.pnpm/balanced-match@4.0.4/node_modules/balanced-match/dist/esm/index.js
|
|
37751
34293
|
var balanced, maybeMatch, range2;
|
|
37752
|
-
var
|
|
34294
|
+
var init_esm = __esm({
|
|
37753
34295
|
"../../node_modules/.pnpm/balanced-match@4.0.4/node_modules/balanced-match/dist/esm/index.js"() {
|
|
37754
34296
|
"use strict";
|
|
37755
34297
|
balanced = (a, b, str3) => {
|
|
@@ -37950,10 +34492,10 @@ function expand_(str3, max, isTop) {
|
|
|
37950
34492
|
return expansions;
|
|
37951
34493
|
}
|
|
37952
34494
|
var escSlash, escOpen, escClose, escComma, escPeriod, escSlashPattern, escOpenPattern, escClosePattern, escCommaPattern, escPeriodPattern, slashPattern, openPattern, closePattern, commaPattern, periodPattern, EXPANSION_MAX;
|
|
37953
|
-
var
|
|
34495
|
+
var init_esm2 = __esm({
|
|
37954
34496
|
"../../node_modules/.pnpm/brace-expansion@5.0.5/node_modules/brace-expansion/dist/esm/index.js"() {
|
|
37955
34497
|
"use strict";
|
|
37956
|
-
|
|
34498
|
+
init_esm();
|
|
37957
34499
|
escSlash = "\0SLASH" + Math.random() + "\0";
|
|
37958
34500
|
escOpen = "\0OPEN" + Math.random() + "\0";
|
|
37959
34501
|
escClose = "\0CLOSE" + Math.random() + "\0";
|
|
@@ -38786,10 +35328,10 @@ var init_escape = __esm({
|
|
|
38786
35328
|
|
|
38787
35329
|
// ../../node_modules/.pnpm/minimatch@10.2.5/node_modules/minimatch/dist/esm/index.js
|
|
38788
35330
|
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;
|
|
38789
|
-
var
|
|
35331
|
+
var init_esm3 = __esm({
|
|
38790
35332
|
"../../node_modules/.pnpm/minimatch@10.2.5/node_modules/minimatch/dist/esm/index.js"() {
|
|
38791
35333
|
"use strict";
|
|
38792
|
-
|
|
35334
|
+
init_esm2();
|
|
38793
35335
|
init_assert_valid_pattern();
|
|
38794
35336
|
init_ast();
|
|
38795
35337
|
init_escape();
|
|
@@ -46872,6 +43414,7 @@ import fs103 from "fs";
|
|
|
46872
43414
|
import * as path83 from "path";
|
|
46873
43415
|
import { cwd as cwd2 } from "process";
|
|
46874
43416
|
import path92 from "path";
|
|
43417
|
+
import { Command as Command3 } from "commander";
|
|
46875
43418
|
function parseCargoToml2(cargoPath) {
|
|
46876
43419
|
const content = fs15.readFileSync(cargoPath, "utf-8");
|
|
46877
43420
|
return TOML3.parse(content);
|
|
@@ -48563,7 +45106,7 @@ function matchesPackageNamePattern(packageName, pattern) {
|
|
|
48563
45106
|
}
|
|
48564
45107
|
}
|
|
48565
45108
|
function createVersionCommand() {
|
|
48566
|
-
return new
|
|
45109
|
+
return new Command3("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) => {
|
|
48567
45110
|
if (options.json) {
|
|
48568
45111
|
enableJsonOutput(options.dryRun);
|
|
48569
45112
|
}
|
|
@@ -48645,10 +45188,9 @@ var init_chunk_UBCKZYTO = __esm({
|
|
|
48645
45188
|
import_semver5 = __toESM(require_semver2(), 1);
|
|
48646
45189
|
init_node_figlet();
|
|
48647
45190
|
import_semver6 = __toESM(require_semver2(), 1);
|
|
48648
|
-
|
|
45191
|
+
init_esm3();
|
|
48649
45192
|
init_manypkg_get_packages();
|
|
48650
|
-
|
|
48651
|
-
init_esm();
|
|
45193
|
+
init_esm3();
|
|
48652
45194
|
ConfigError4 = class extends ReleaseKitError4 {
|
|
48653
45195
|
code = "CONFIG_ERROR";
|
|
48654
45196
|
suggestions;
|
|
@@ -49490,14 +46032,14 @@ var EXIT_CODES = {
|
|
|
49490
46032
|
init_dist();
|
|
49491
46033
|
init_dist2();
|
|
49492
46034
|
init_dist15();
|
|
49493
|
-
|
|
46035
|
+
import { Command as Command7 } from "commander";
|
|
49494
46036
|
|
|
49495
46037
|
// src/init-command.ts
|
|
49496
46038
|
import * as fs16 from "fs";
|
|
49497
46039
|
init_dist();
|
|
49498
|
-
|
|
46040
|
+
import { Command as Command4 } from "commander";
|
|
49499
46041
|
function createInitCommand() {
|
|
49500
|
-
return new
|
|
46042
|
+
return new Command4("init").description("Create a default releasekit.config.json").option("-f, --force", "Overwrite existing config").action((options) => {
|
|
49501
46043
|
const configPath = "releasekit.config.json";
|
|
49502
46044
|
if (fs16.existsSync(configPath) && !options.force) {
|
|
49503
46045
|
error(`Config file already exists at ${configPath}. Use --force to overwrite.`);
|
|
@@ -49542,7 +46084,7 @@ function createInitCommand() {
|
|
|
49542
46084
|
}
|
|
49543
46085
|
|
|
49544
46086
|
// src/preview-command.ts
|
|
49545
|
-
|
|
46087
|
+
import { Command as Command5 } from "commander";
|
|
49546
46088
|
|
|
49547
46089
|
// ../config/dist/index.js
|
|
49548
46090
|
import * as TOML4 from "smol-toml";
|
|
@@ -50518,7 +47060,7 @@ async function applyLabelOverrides(options, ciConfig, context, existingOctokit)
|
|
|
50518
47060
|
|
|
50519
47061
|
// src/preview-command.ts
|
|
50520
47062
|
function createPreviewCommand() {
|
|
50521
|
-
return new
|
|
47063
|
+
return new Command5("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(
|
|
50522
47064
|
"-d, --dry-run",
|
|
50523
47065
|
"Print the comment to stdout without posting (GitHub context not available in dry-run mode)",
|
|
50524
47066
|
false
|
|
@@ -50541,9 +47083,9 @@ function createPreviewCommand() {
|
|
|
50541
47083
|
}
|
|
50542
47084
|
|
|
50543
47085
|
// src/release-command.ts
|
|
50544
|
-
|
|
47086
|
+
import { Command as Command6, Option } from "commander";
|
|
50545
47087
|
function createReleaseCommand() {
|
|
50546
|
-
return new
|
|
47088
|
+
return new Command6("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) => {
|
|
50547
47089
|
const options = {
|
|
50548
47090
|
config: opts.config,
|
|
50549
47091
|
dryRun: opts.dryRun,
|
|
@@ -50580,14 +47122,14 @@ function createReleaseCommand() {
|
|
|
50580
47122
|
|
|
50581
47123
|
// src/dispatcher.ts
|
|
50582
47124
|
function createDispatcherProgram() {
|
|
50583
|
-
const
|
|
50584
|
-
|
|
50585
|
-
|
|
50586
|
-
|
|
50587
|
-
|
|
50588
|
-
|
|
50589
|
-
|
|
50590
|
-
return
|
|
47125
|
+
const program = new Command7().name("releasekit").description("Unified release pipeline: version, changelog, and publish").version(readPackageVersion(import.meta.url));
|
|
47126
|
+
program.addCommand(createReleaseCommand(), { isDefault: true });
|
|
47127
|
+
program.addCommand(createPreviewCommand());
|
|
47128
|
+
program.addCommand(createInitCommand());
|
|
47129
|
+
program.addCommand(createVersionCommand());
|
|
47130
|
+
program.addCommand(createNotesCommand());
|
|
47131
|
+
program.addCommand(createPublishCommand());
|
|
47132
|
+
return program;
|
|
50591
47133
|
}
|
|
50592
47134
|
var isMain = (() => {
|
|
50593
47135
|
try {
|