@optique/core 1.0.0-dev.561 → 1.0.0-dev.563
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/facade.cjs +20 -40
- package/dist/facade.js +20 -40
- package/package.json +1 -1
package/dist/facade.cjs
CHANGED
|
@@ -67,6 +67,10 @@ function createVersionParser(commandConfig, optionConfig) {
|
|
|
67
67
|
versionOption
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
|
+
const metaResultBrand = Symbol("@optique/core/facade/meta");
|
|
71
|
+
function isMetaParseResult(value$1) {
|
|
72
|
+
return typeof value$1 === "object" && value$1 != null && metaResultBrand in value$1;
|
|
73
|
+
}
|
|
70
74
|
/**
|
|
71
75
|
* Creates completion parsers based on the sub-config.
|
|
72
76
|
*/
|
|
@@ -163,8 +167,10 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers, com
|
|
|
163
167
|
...context,
|
|
164
168
|
buffer: [],
|
|
165
169
|
state: {
|
|
170
|
+
[metaResultBrand]: true,
|
|
166
171
|
help: true,
|
|
167
172
|
version: false,
|
|
173
|
+
completion: false,
|
|
168
174
|
commands,
|
|
169
175
|
helpFlag: true
|
|
170
176
|
}
|
|
@@ -234,8 +240,10 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers, com
|
|
|
234
240
|
...context,
|
|
235
241
|
buffer: [],
|
|
236
242
|
state: {
|
|
243
|
+
[metaResultBrand]: true,
|
|
237
244
|
help: false,
|
|
238
245
|
version: true,
|
|
246
|
+
completion: false,
|
|
239
247
|
versionFlag: true
|
|
240
248
|
}
|
|
241
249
|
},
|
|
@@ -268,6 +276,7 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers, com
|
|
|
268
276
|
}
|
|
269
277
|
if (versionParsers.versionCommand) {
|
|
270
278
|
const versionParser = require_constructs.object({
|
|
279
|
+
[metaResultBrand]: require_primitives.constant(true),
|
|
271
280
|
help: require_primitives.constant(false),
|
|
272
281
|
version: require_primitives.constant(true),
|
|
273
282
|
completion: require_primitives.constant(false),
|
|
@@ -278,6 +287,7 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers, com
|
|
|
278
287
|
}
|
|
279
288
|
if (completionParsers.completionCommand) {
|
|
280
289
|
const completionParser = require_constructs.object({
|
|
290
|
+
[metaResultBrand]: require_primitives.constant(true),
|
|
281
291
|
help: require_primitives.constant(false),
|
|
282
292
|
version: require_primitives.constant(false),
|
|
283
293
|
completion: require_primitives.constant(true),
|
|
@@ -288,6 +298,7 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers, com
|
|
|
288
298
|
}
|
|
289
299
|
if (helpParsers.helpCommand) {
|
|
290
300
|
const helpParser = require_constructs.object({
|
|
301
|
+
[metaResultBrand]: require_primitives.constant(true),
|
|
291
302
|
help: require_primitives.constant(true),
|
|
292
303
|
version: require_primitives.constant(false),
|
|
293
304
|
completion: require_primitives.constant(false),
|
|
@@ -296,6 +307,7 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers, com
|
|
|
296
307
|
parsers.push(groups?.helpCommandGroup ? require_constructs.group(groups.helpCommandGroup, helpParser) : helpParser);
|
|
297
308
|
}
|
|
298
309
|
parsers.push(require_constructs.object({
|
|
310
|
+
[metaResultBrand]: require_primitives.constant(true),
|
|
299
311
|
help: require_primitives.constant(false),
|
|
300
312
|
version: require_primitives.constant(false),
|
|
301
313
|
completion: require_primitives.constant(false),
|
|
@@ -332,7 +344,7 @@ function classifyResult(result, args, helpOptionNames, helpCommandNames, version
|
|
|
332
344
|
error: result.error
|
|
333
345
|
};
|
|
334
346
|
const value$1 = result.value;
|
|
335
|
-
if (
|
|
347
|
+
if (isMetaParseResult(value$1)) {
|
|
336
348
|
const parsedValue = value$1;
|
|
337
349
|
const hasVersionOption = versionOptionNames.some((n) => args.includes(n));
|
|
338
350
|
const hasVersionCommand = args.length > 0 && versionCommandNames.includes(args[0]);
|
|
@@ -364,7 +376,7 @@ function classifyResult(result, args, helpOptionNames, helpCommandNames, version
|
|
|
364
376
|
};
|
|
365
377
|
return {
|
|
366
378
|
type: "success",
|
|
367
|
-
value: parsedValue.result
|
|
379
|
+
value: "result" in parsedValue ? parsedValue.result : value$1
|
|
368
380
|
};
|
|
369
381
|
}
|
|
370
382
|
return {
|
|
@@ -379,20 +391,8 @@ function classifyResult(result, args, helpOptionNames, helpCommandNames, version
|
|
|
379
391
|
function handleCompletion(completionArgs, programName, parser, completionParser, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionCommandDisplayName, completionOptionDisplayName, isOptionMode, sectionOrder) {
|
|
380
392
|
const shellName = completionArgs[0] || "";
|
|
381
393
|
const args = completionArgs.slice(1);
|
|
382
|
-
const callOnError = (code) =>
|
|
383
|
-
|
|
384
|
-
return onError(code);
|
|
385
|
-
} catch {
|
|
386
|
-
return onError();
|
|
387
|
-
}
|
|
388
|
-
};
|
|
389
|
-
const callOnCompletion = (code) => {
|
|
390
|
-
try {
|
|
391
|
-
return onCompletion(code);
|
|
392
|
-
} catch {
|
|
393
|
-
return onCompletion();
|
|
394
|
-
}
|
|
395
|
-
};
|
|
394
|
+
const callOnError = (code) => onError(code);
|
|
395
|
+
const callOnCompletion = (code) => onCompletion(code);
|
|
396
396
|
if (!shellName) {
|
|
397
397
|
stderr("Error: Missing shell name for completion.\n");
|
|
398
398
|
if (completionParser) {
|
|
@@ -477,20 +477,8 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
477
477
|
const completionCommandConfig = norm(options.completion?.command);
|
|
478
478
|
const completionOptionConfig = norm(options.completion?.option);
|
|
479
479
|
const onCompletion = options.completion?.onShow ?? (() => ({}));
|
|
480
|
-
const onCompletionResult = (code) =>
|
|
481
|
-
|
|
482
|
-
return onCompletion(code);
|
|
483
|
-
} catch {
|
|
484
|
-
return onCompletion();
|
|
485
|
-
}
|
|
486
|
-
};
|
|
487
|
-
const onErrorResult = (code) => {
|
|
488
|
-
try {
|
|
489
|
-
return onError(code);
|
|
490
|
-
} catch {
|
|
491
|
-
return onError();
|
|
492
|
-
}
|
|
493
|
-
};
|
|
480
|
+
const onCompletionResult = (code) => onCompletion(code);
|
|
481
|
+
const onErrorResult = (code) => onError(code);
|
|
494
482
|
const helpOptionNames = helpOptionConfig?.names ?? ["--help"];
|
|
495
483
|
const helpCommandNames = helpCommandConfig?.names ?? ["help"];
|
|
496
484
|
const versionOptionNames = versionOptionConfig?.names ?? ["--version"];
|
|
@@ -553,11 +541,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
553
541
|
case "success": return classified.value;
|
|
554
542
|
case "version":
|
|
555
543
|
stdout(versionValue);
|
|
556
|
-
|
|
557
|
-
return onVersion(0);
|
|
558
|
-
} catch {
|
|
559
|
-
return onVersion();
|
|
560
|
-
}
|
|
544
|
+
return onVersion(0);
|
|
561
545
|
case "completion": throw new RunParserError("Completion should be handled by early return");
|
|
562
546
|
case "help": {
|
|
563
547
|
let helpGeneratorParser;
|
|
@@ -637,11 +621,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
637
621
|
sectionOrder
|
|
638
622
|
}));
|
|
639
623
|
}
|
|
640
|
-
|
|
641
|
-
return onHelp(0);
|
|
642
|
-
} catch {
|
|
643
|
-
return onHelp();
|
|
644
|
-
}
|
|
624
|
+
return onHelp(0);
|
|
645
625
|
};
|
|
646
626
|
if (classified.commands.length > 0) {
|
|
647
627
|
let validationContext = {
|
package/dist/facade.js
CHANGED
|
@@ -67,6 +67,10 @@ function createVersionParser(commandConfig, optionConfig) {
|
|
|
67
67
|
versionOption
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
|
+
const metaResultBrand = Symbol("@optique/core/facade/meta");
|
|
71
|
+
function isMetaParseResult(value$1) {
|
|
72
|
+
return typeof value$1 === "object" && value$1 != null && metaResultBrand in value$1;
|
|
73
|
+
}
|
|
70
74
|
/**
|
|
71
75
|
* Creates completion parsers based on the sub-config.
|
|
72
76
|
*/
|
|
@@ -163,8 +167,10 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers, com
|
|
|
163
167
|
...context,
|
|
164
168
|
buffer: [],
|
|
165
169
|
state: {
|
|
170
|
+
[metaResultBrand]: true,
|
|
166
171
|
help: true,
|
|
167
172
|
version: false,
|
|
173
|
+
completion: false,
|
|
168
174
|
commands,
|
|
169
175
|
helpFlag: true
|
|
170
176
|
}
|
|
@@ -234,8 +240,10 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers, com
|
|
|
234
240
|
...context,
|
|
235
241
|
buffer: [],
|
|
236
242
|
state: {
|
|
243
|
+
[metaResultBrand]: true,
|
|
237
244
|
help: false,
|
|
238
245
|
version: true,
|
|
246
|
+
completion: false,
|
|
239
247
|
versionFlag: true
|
|
240
248
|
}
|
|
241
249
|
},
|
|
@@ -268,6 +276,7 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers, com
|
|
|
268
276
|
}
|
|
269
277
|
if (versionParsers.versionCommand) {
|
|
270
278
|
const versionParser = object({
|
|
279
|
+
[metaResultBrand]: constant(true),
|
|
271
280
|
help: constant(false),
|
|
272
281
|
version: constant(true),
|
|
273
282
|
completion: constant(false),
|
|
@@ -278,6 +287,7 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers, com
|
|
|
278
287
|
}
|
|
279
288
|
if (completionParsers.completionCommand) {
|
|
280
289
|
const completionParser = object({
|
|
290
|
+
[metaResultBrand]: constant(true),
|
|
281
291
|
help: constant(false),
|
|
282
292
|
version: constant(false),
|
|
283
293
|
completion: constant(true),
|
|
@@ -288,6 +298,7 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers, com
|
|
|
288
298
|
}
|
|
289
299
|
if (helpParsers.helpCommand) {
|
|
290
300
|
const helpParser = object({
|
|
301
|
+
[metaResultBrand]: constant(true),
|
|
291
302
|
help: constant(true),
|
|
292
303
|
version: constant(false),
|
|
293
304
|
completion: constant(false),
|
|
@@ -296,6 +307,7 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers, com
|
|
|
296
307
|
parsers.push(groups?.helpCommandGroup ? group(groups.helpCommandGroup, helpParser) : helpParser);
|
|
297
308
|
}
|
|
298
309
|
parsers.push(object({
|
|
310
|
+
[metaResultBrand]: constant(true),
|
|
299
311
|
help: constant(false),
|
|
300
312
|
version: constant(false),
|
|
301
313
|
completion: constant(false),
|
|
@@ -332,7 +344,7 @@ function classifyResult(result, args, helpOptionNames, helpCommandNames, version
|
|
|
332
344
|
error: result.error
|
|
333
345
|
};
|
|
334
346
|
const value$1 = result.value;
|
|
335
|
-
if (
|
|
347
|
+
if (isMetaParseResult(value$1)) {
|
|
336
348
|
const parsedValue = value$1;
|
|
337
349
|
const hasVersionOption = versionOptionNames.some((n) => args.includes(n));
|
|
338
350
|
const hasVersionCommand = args.length > 0 && versionCommandNames.includes(args[0]);
|
|
@@ -364,7 +376,7 @@ function classifyResult(result, args, helpOptionNames, helpCommandNames, version
|
|
|
364
376
|
};
|
|
365
377
|
return {
|
|
366
378
|
type: "success",
|
|
367
|
-
value: parsedValue.result
|
|
379
|
+
value: "result" in parsedValue ? parsedValue.result : value$1
|
|
368
380
|
};
|
|
369
381
|
}
|
|
370
382
|
return {
|
|
@@ -379,20 +391,8 @@ function classifyResult(result, args, helpOptionNames, helpCommandNames, version
|
|
|
379
391
|
function handleCompletion(completionArgs, programName, parser, completionParser, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionCommandDisplayName, completionOptionDisplayName, isOptionMode, sectionOrder) {
|
|
380
392
|
const shellName = completionArgs[0] || "";
|
|
381
393
|
const args = completionArgs.slice(1);
|
|
382
|
-
const callOnError = (code) =>
|
|
383
|
-
|
|
384
|
-
return onError(code);
|
|
385
|
-
} catch {
|
|
386
|
-
return onError();
|
|
387
|
-
}
|
|
388
|
-
};
|
|
389
|
-
const callOnCompletion = (code) => {
|
|
390
|
-
try {
|
|
391
|
-
return onCompletion(code);
|
|
392
|
-
} catch {
|
|
393
|
-
return onCompletion();
|
|
394
|
-
}
|
|
395
|
-
};
|
|
394
|
+
const callOnError = (code) => onError(code);
|
|
395
|
+
const callOnCompletion = (code) => onCompletion(code);
|
|
396
396
|
if (!shellName) {
|
|
397
397
|
stderr("Error: Missing shell name for completion.\n");
|
|
398
398
|
if (completionParser) {
|
|
@@ -477,20 +477,8 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
477
477
|
const completionCommandConfig = norm(options.completion?.command);
|
|
478
478
|
const completionOptionConfig = norm(options.completion?.option);
|
|
479
479
|
const onCompletion = options.completion?.onShow ?? (() => ({}));
|
|
480
|
-
const onCompletionResult = (code) =>
|
|
481
|
-
|
|
482
|
-
return onCompletion(code);
|
|
483
|
-
} catch {
|
|
484
|
-
return onCompletion();
|
|
485
|
-
}
|
|
486
|
-
};
|
|
487
|
-
const onErrorResult = (code) => {
|
|
488
|
-
try {
|
|
489
|
-
return onError(code);
|
|
490
|
-
} catch {
|
|
491
|
-
return onError();
|
|
492
|
-
}
|
|
493
|
-
};
|
|
480
|
+
const onCompletionResult = (code) => onCompletion(code);
|
|
481
|
+
const onErrorResult = (code) => onError(code);
|
|
494
482
|
const helpOptionNames = helpOptionConfig?.names ?? ["--help"];
|
|
495
483
|
const helpCommandNames = helpCommandConfig?.names ?? ["help"];
|
|
496
484
|
const versionOptionNames = versionOptionConfig?.names ?? ["--version"];
|
|
@@ -553,11 +541,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
553
541
|
case "success": return classified.value;
|
|
554
542
|
case "version":
|
|
555
543
|
stdout(versionValue);
|
|
556
|
-
|
|
557
|
-
return onVersion(0);
|
|
558
|
-
} catch {
|
|
559
|
-
return onVersion();
|
|
560
|
-
}
|
|
544
|
+
return onVersion(0);
|
|
561
545
|
case "completion": throw new RunParserError("Completion should be handled by early return");
|
|
562
546
|
case "help": {
|
|
563
547
|
let helpGeneratorParser;
|
|
@@ -637,11 +621,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
637
621
|
sectionOrder
|
|
638
622
|
}));
|
|
639
623
|
}
|
|
640
|
-
|
|
641
|
-
return onHelp(0);
|
|
642
|
-
} catch {
|
|
643
|
-
return onHelp();
|
|
644
|
-
}
|
|
624
|
+
return onHelp(0);
|
|
645
625
|
};
|
|
646
626
|
if (classified.commands.length > 0) {
|
|
647
627
|
let validationContext = {
|