@optique/core 1.0.0-dev.465 → 1.0.0-dev.467
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 +40 -21
- package/dist/facade.js +40 -21
- package/dist/mode-dispatch.cjs +16 -1
- package/dist/mode-dispatch.js +15 -1
- package/dist/modifiers.cjs +5 -16
- package/dist/modifiers.js +6 -17
- package/dist/parser.cjs +3 -4
- package/dist/parser.js +3 -4
- package/package.json +1 -1
package/dist/facade.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const require_annotations = require('./annotations.cjs');
|
|
2
2
|
const require_message = require('./message.cjs');
|
|
3
3
|
const require_completion = require('./completion.cjs');
|
|
4
|
+
const require_mode_dispatch = require('./mode-dispatch.cjs');
|
|
4
5
|
const require_usage = require('./usage.cjs');
|
|
5
6
|
const require_constructs = require('./constructs.cjs');
|
|
6
7
|
const require_doc = require('./doc.cjs');
|
|
@@ -404,8 +405,7 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
|
|
|
404
405
|
sectionOrder
|
|
405
406
|
}));
|
|
406
407
|
}
|
|
407
|
-
|
|
408
|
-
return callOnError(1);
|
|
408
|
+
return require_mode_dispatch.dispatchByMode(parser.$mode, () => callOnError(1), () => Promise.resolve(callOnError(1)));
|
|
409
409
|
}
|
|
410
410
|
const shell = availableShells[shellName];
|
|
411
411
|
if (!shell) {
|
|
@@ -418,25 +418,24 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
|
|
|
418
418
|
colors,
|
|
419
419
|
quotes: !colors
|
|
420
420
|
}));
|
|
421
|
-
|
|
422
|
-
return callOnError(1);
|
|
421
|
+
return require_mode_dispatch.dispatchByMode(parser.$mode, () => callOnError(1), () => Promise.resolve(callOnError(1)));
|
|
423
422
|
}
|
|
424
423
|
if (args.length === 0) {
|
|
425
424
|
const completionArg = isOptionMode ? completionOptionDisplayName ?? "--completion" : completionCommandDisplayName ?? "completion";
|
|
426
425
|
const script = shell.generateScript(programName, [completionArg, shellName]);
|
|
427
426
|
stdout(script);
|
|
428
|
-
|
|
429
|
-
return callOnCompletion(0);
|
|
427
|
+
return require_mode_dispatch.dispatchByMode(parser.$mode, () => callOnCompletion(0), () => Promise.resolve(callOnCompletion(0)));
|
|
430
428
|
}
|
|
431
|
-
|
|
432
|
-
const
|
|
433
|
-
|
|
429
|
+
return require_mode_dispatch.dispatchByMode(parser.$mode, () => {
|
|
430
|
+
const syncParser = parser;
|
|
431
|
+
const suggestions = require_parser.suggest(syncParser, args);
|
|
432
|
+
for (const chunk of shell.encodeSuggestions(suggestions)) stdout(chunk);
|
|
433
|
+
return callOnCompletion(0);
|
|
434
|
+
}, async () => {
|
|
435
|
+
const suggestions = await require_parser.suggestAsync(parser, args);
|
|
436
|
+
for (const chunk of shell.encodeSuggestions(suggestions)) stdout(chunk);
|
|
434
437
|
return callOnCompletion(0);
|
|
435
|
-
})
|
|
436
|
-
const syncParser = parser;
|
|
437
|
-
const suggestions = require_parser.suggest(syncParser, args);
|
|
438
|
-
for (const chunk of shell.encodeSuggestions(suggestions)) stdout(chunk);
|
|
439
|
-
return callOnCompletion(0);
|
|
438
|
+
});
|
|
440
439
|
}
|
|
441
440
|
function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsParam) {
|
|
442
441
|
const isProgram = typeof programNameOrArgs !== "string";
|
|
@@ -479,6 +478,20 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
479
478
|
const completionCommandConfig = norm(options.completion?.command);
|
|
480
479
|
const completionOptionConfig = norm(options.completion?.option);
|
|
481
480
|
const onCompletion = options.completion?.onShow ?? (() => ({}));
|
|
481
|
+
const onCompletionResult = (code) => {
|
|
482
|
+
try {
|
|
483
|
+
return onCompletion(code);
|
|
484
|
+
} catch {
|
|
485
|
+
return onCompletion();
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
const onErrorResult = (code) => {
|
|
489
|
+
try {
|
|
490
|
+
return onError(code);
|
|
491
|
+
} catch {
|
|
492
|
+
return onError();
|
|
493
|
+
}
|
|
494
|
+
};
|
|
482
495
|
const helpOptionNames = helpOptionConfig?.names ?? ["--help"];
|
|
483
496
|
const helpCommandNames = helpCommandConfig?.names ?? ["help"];
|
|
484
497
|
const versionOptionNames = versionOptionConfig?.names ?? ["--version"];
|
|
@@ -510,20 +523,20 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
510
523
|
};
|
|
511
524
|
if (options.completion) {
|
|
512
525
|
const hasHelpOption = helpOptionConfig ? helpOptionNames.some((n) => args.includes(n)) : false;
|
|
513
|
-
if (completionCommandConfig && args.length >= 1 && completionCommandNames.includes(args[0]) && !hasHelpOption) return handleCompletion(args.slice(1), programName, parser, completionParsers.completionCommand, stdout, stderr,
|
|
526
|
+
if (completionCommandConfig && args.length >= 1 && completionCommandNames.includes(args[0]) && !hasHelpOption) return handleCompletion(args.slice(1), programName, parser, completionParsers.completionCommand, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, completionCommandNames[0], completionOptionNames[0], false, sectionOrder);
|
|
514
527
|
if (completionOptionConfig) for (let i = 0; i < args.length; i++) {
|
|
515
528
|
const arg = args[i];
|
|
516
529
|
const equalsMatch = completionOptionNames.find((n) => arg.startsWith(n + "="));
|
|
517
530
|
if (equalsMatch) {
|
|
518
531
|
const shell = arg.slice(equalsMatch.length + 1);
|
|
519
532
|
const completionArgs = args.slice(i + 1);
|
|
520
|
-
return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionCommand, stdout, stderr,
|
|
533
|
+
return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionCommand, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, completionCommandNames[0], completionOptionNames[0], true, sectionOrder);
|
|
521
534
|
}
|
|
522
535
|
const exactMatch = completionOptionNames.includes(arg);
|
|
523
536
|
if (exactMatch) {
|
|
524
537
|
const shell = i + 1 < args.length ? args[i + 1] : "";
|
|
525
538
|
const completionArgs = i + 1 < args.length ? args.slice(i + 2) : [];
|
|
526
|
-
return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionCommand, stdout, stderr,
|
|
539
|
+
return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionCommand, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, completionCommandNames[0], completionOptionNames[0], true, sectionOrder);
|
|
527
540
|
}
|
|
528
541
|
}
|
|
529
542
|
}
|
|
@@ -719,11 +732,17 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
719
732
|
default: throw new RunParserError("Unexpected parse result type");
|
|
720
733
|
}
|
|
721
734
|
};
|
|
722
|
-
|
|
723
|
-
|
|
735
|
+
const parserMode = parser.$mode;
|
|
736
|
+
return require_mode_dispatch.dispatchByMode(parserMode, () => {
|
|
724
737
|
const result = require_parser.parseSync(augmentedParser, args);
|
|
725
|
-
|
|
726
|
-
|
|
738
|
+
const handled = handleResult(result);
|
|
739
|
+
if (handled instanceof Promise) throw new RunParserError("Synchronous parser returned async result.");
|
|
740
|
+
return handled;
|
|
741
|
+
}, async () => {
|
|
742
|
+
const result = await require_parser.parseAsync(augmentedParser, args);
|
|
743
|
+
const handled = handleResult(result);
|
|
744
|
+
return handled instanceof Promise ? await handled : handled;
|
|
745
|
+
});
|
|
727
746
|
}
|
|
728
747
|
/**
|
|
729
748
|
* Runs a synchronous command-line parser with the given options.
|
package/dist/facade.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { annotationKey } from "./annotations.js";
|
|
2
2
|
import { commandLine, formatMessage, lineBreak, message, optionName, text, value } from "./message.js";
|
|
3
3
|
import { bash, fish, nu, pwsh, zsh } from "./completion.js";
|
|
4
|
+
import { dispatchByMode } from "./mode-dispatch.js";
|
|
4
5
|
import { formatUsage } from "./usage.js";
|
|
5
6
|
import { group, longestMatch, object } from "./constructs.js";
|
|
6
7
|
import { formatDocPage } from "./doc.js";
|
|
@@ -404,8 +405,7 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
|
|
|
404
405
|
sectionOrder
|
|
405
406
|
}));
|
|
406
407
|
}
|
|
407
|
-
|
|
408
|
-
return callOnError(1);
|
|
408
|
+
return dispatchByMode(parser.$mode, () => callOnError(1), () => Promise.resolve(callOnError(1)));
|
|
409
409
|
}
|
|
410
410
|
const shell = availableShells[shellName];
|
|
411
411
|
if (!shell) {
|
|
@@ -418,25 +418,24 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
|
|
|
418
418
|
colors,
|
|
419
419
|
quotes: !colors
|
|
420
420
|
}));
|
|
421
|
-
|
|
422
|
-
return callOnError(1);
|
|
421
|
+
return dispatchByMode(parser.$mode, () => callOnError(1), () => Promise.resolve(callOnError(1)));
|
|
423
422
|
}
|
|
424
423
|
if (args.length === 0) {
|
|
425
424
|
const completionArg = isOptionMode ? completionOptionDisplayName ?? "--completion" : completionCommandDisplayName ?? "completion";
|
|
426
425
|
const script = shell.generateScript(programName, [completionArg, shellName]);
|
|
427
426
|
stdout(script);
|
|
428
|
-
|
|
429
|
-
return callOnCompletion(0);
|
|
427
|
+
return dispatchByMode(parser.$mode, () => callOnCompletion(0), () => Promise.resolve(callOnCompletion(0)));
|
|
430
428
|
}
|
|
431
|
-
|
|
432
|
-
const
|
|
433
|
-
|
|
429
|
+
return dispatchByMode(parser.$mode, () => {
|
|
430
|
+
const syncParser = parser;
|
|
431
|
+
const suggestions = suggest(syncParser, args);
|
|
432
|
+
for (const chunk of shell.encodeSuggestions(suggestions)) stdout(chunk);
|
|
433
|
+
return callOnCompletion(0);
|
|
434
|
+
}, async () => {
|
|
435
|
+
const suggestions = await suggestAsync(parser, args);
|
|
436
|
+
for (const chunk of shell.encodeSuggestions(suggestions)) stdout(chunk);
|
|
434
437
|
return callOnCompletion(0);
|
|
435
|
-
})
|
|
436
|
-
const syncParser = parser;
|
|
437
|
-
const suggestions = suggest(syncParser, args);
|
|
438
|
-
for (const chunk of shell.encodeSuggestions(suggestions)) stdout(chunk);
|
|
439
|
-
return callOnCompletion(0);
|
|
438
|
+
});
|
|
440
439
|
}
|
|
441
440
|
function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsParam) {
|
|
442
441
|
const isProgram = typeof programNameOrArgs !== "string";
|
|
@@ -479,6 +478,20 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
479
478
|
const completionCommandConfig = norm(options.completion?.command);
|
|
480
479
|
const completionOptionConfig = norm(options.completion?.option);
|
|
481
480
|
const onCompletion = options.completion?.onShow ?? (() => ({}));
|
|
481
|
+
const onCompletionResult = (code) => {
|
|
482
|
+
try {
|
|
483
|
+
return onCompletion(code);
|
|
484
|
+
} catch {
|
|
485
|
+
return onCompletion();
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
const onErrorResult = (code) => {
|
|
489
|
+
try {
|
|
490
|
+
return onError(code);
|
|
491
|
+
} catch {
|
|
492
|
+
return onError();
|
|
493
|
+
}
|
|
494
|
+
};
|
|
482
495
|
const helpOptionNames = helpOptionConfig?.names ?? ["--help"];
|
|
483
496
|
const helpCommandNames = helpCommandConfig?.names ?? ["help"];
|
|
484
497
|
const versionOptionNames = versionOptionConfig?.names ?? ["--version"];
|
|
@@ -510,20 +523,20 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
510
523
|
};
|
|
511
524
|
if (options.completion) {
|
|
512
525
|
const hasHelpOption = helpOptionConfig ? helpOptionNames.some((n) => args.includes(n)) : false;
|
|
513
|
-
if (completionCommandConfig && args.length >= 1 && completionCommandNames.includes(args[0]) && !hasHelpOption) return handleCompletion(args.slice(1), programName, parser, completionParsers.completionCommand, stdout, stderr,
|
|
526
|
+
if (completionCommandConfig && args.length >= 1 && completionCommandNames.includes(args[0]) && !hasHelpOption) return handleCompletion(args.slice(1), programName, parser, completionParsers.completionCommand, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, completionCommandNames[0], completionOptionNames[0], false, sectionOrder);
|
|
514
527
|
if (completionOptionConfig) for (let i = 0; i < args.length; i++) {
|
|
515
528
|
const arg = args[i];
|
|
516
529
|
const equalsMatch = completionOptionNames.find((n) => arg.startsWith(n + "="));
|
|
517
530
|
if (equalsMatch) {
|
|
518
531
|
const shell = arg.slice(equalsMatch.length + 1);
|
|
519
532
|
const completionArgs = args.slice(i + 1);
|
|
520
|
-
return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionCommand, stdout, stderr,
|
|
533
|
+
return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionCommand, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, completionCommandNames[0], completionOptionNames[0], true, sectionOrder);
|
|
521
534
|
}
|
|
522
535
|
const exactMatch = completionOptionNames.includes(arg);
|
|
523
536
|
if (exactMatch) {
|
|
524
537
|
const shell = i + 1 < args.length ? args[i + 1] : "";
|
|
525
538
|
const completionArgs = i + 1 < args.length ? args.slice(i + 2) : [];
|
|
526
|
-
return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionCommand, stdout, stderr,
|
|
539
|
+
return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionCommand, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, completionCommandNames[0], completionOptionNames[0], true, sectionOrder);
|
|
527
540
|
}
|
|
528
541
|
}
|
|
529
542
|
}
|
|
@@ -719,11 +732,17 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
719
732
|
default: throw new RunParserError("Unexpected parse result type");
|
|
720
733
|
}
|
|
721
734
|
};
|
|
722
|
-
|
|
723
|
-
|
|
735
|
+
const parserMode = parser.$mode;
|
|
736
|
+
return dispatchByMode(parserMode, () => {
|
|
724
737
|
const result = parseSync(augmentedParser, args);
|
|
725
|
-
|
|
726
|
-
|
|
738
|
+
const handled = handleResult(result);
|
|
739
|
+
if (handled instanceof Promise) throw new RunParserError("Synchronous parser returned async result.");
|
|
740
|
+
return handled;
|
|
741
|
+
}, async () => {
|
|
742
|
+
const result = await parseAsync(augmentedParser, args);
|
|
743
|
+
const handled = handleResult(result);
|
|
744
|
+
return handled instanceof Promise ? await handled : handled;
|
|
745
|
+
});
|
|
727
746
|
}
|
|
728
747
|
/**
|
|
729
748
|
* Runs a synchronous command-line parser with the given options.
|
package/dist/mode-dispatch.cjs
CHANGED
|
@@ -19,6 +19,20 @@ function dispatchByMode(mode, syncFn, asyncFn) {
|
|
|
19
19
|
return syncFn();
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
+
* Maps a mode-wrapped value while preserving its execution mode.
|
|
23
|
+
*
|
|
24
|
+
* @param mode The execution mode.
|
|
25
|
+
* @param value The mode-wrapped value to transform.
|
|
26
|
+
* @param mapFn Mapping function applied to the unwrapped value.
|
|
27
|
+
* @returns The mapped value with correct mode wrapping.
|
|
28
|
+
* @internal
|
|
29
|
+
* @since 1.0.0
|
|
30
|
+
*/
|
|
31
|
+
function mapModeValue(mode, value, mapFn) {
|
|
32
|
+
if (mode === "async") return Promise.resolve(value).then(mapFn);
|
|
33
|
+
return mapFn(value);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
22
36
|
* Dispatches iterable to sync or async implementation based on mode.
|
|
23
37
|
*
|
|
24
38
|
* @param mode The execution mode.
|
|
@@ -35,4 +49,5 @@ function dispatchIterableByMode(mode, syncFn, asyncFn) {
|
|
|
35
49
|
|
|
36
50
|
//#endregion
|
|
37
51
|
exports.dispatchByMode = dispatchByMode;
|
|
38
|
-
exports.dispatchIterableByMode = dispatchIterableByMode;
|
|
52
|
+
exports.dispatchIterableByMode = dispatchIterableByMode;
|
|
53
|
+
exports.mapModeValue = mapModeValue;
|
package/dist/mode-dispatch.js
CHANGED
|
@@ -18,6 +18,20 @@ function dispatchByMode(mode, syncFn, asyncFn) {
|
|
|
18
18
|
return syncFn();
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
+
* Maps a mode-wrapped value while preserving its execution mode.
|
|
22
|
+
*
|
|
23
|
+
* @param mode The execution mode.
|
|
24
|
+
* @param value The mode-wrapped value to transform.
|
|
25
|
+
* @param mapFn Mapping function applied to the unwrapped value.
|
|
26
|
+
* @returns The mapped value with correct mode wrapping.
|
|
27
|
+
* @internal
|
|
28
|
+
* @since 1.0.0
|
|
29
|
+
*/
|
|
30
|
+
function mapModeValue(mode, value, mapFn) {
|
|
31
|
+
if (mode === "async") return Promise.resolve(value).then(mapFn);
|
|
32
|
+
return mapFn(value);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
21
35
|
* Dispatches iterable to sync or async implementation based on mode.
|
|
22
36
|
*
|
|
23
37
|
* @param mode The execution mode.
|
|
@@ -33,4 +47,4 @@ function dispatchIterableByMode(mode, syncFn, asyncFn) {
|
|
|
33
47
|
}
|
|
34
48
|
|
|
35
49
|
//#endregion
|
|
36
|
-
export { dispatchByMode, dispatchIterableByMode };
|
|
50
|
+
export { dispatchByMode, dispatchIterableByMode, mapModeValue };
|
package/dist/modifiers.cjs
CHANGED
|
@@ -235,8 +235,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
235
235
|
};
|
|
236
236
|
}
|
|
237
237
|
};
|
|
238
|
-
|
|
239
|
-
return handleInnerResult(innerResult);
|
|
238
|
+
return require_mode_dispatch.mapModeValue(parser.$mode, innerResult, handleInnerResult);
|
|
240
239
|
}
|
|
241
240
|
if (require_dependency.isWrappedDependencySource(parser)) try {
|
|
242
241
|
const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
@@ -293,8 +292,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
293
292
|
};
|
|
294
293
|
}
|
|
295
294
|
};
|
|
296
|
-
|
|
297
|
-
return handleInnerResult(innerResult);
|
|
295
|
+
return require_mode_dispatch.mapModeValue(parser.$mode, innerResult, handleInnerResult);
|
|
298
296
|
}
|
|
299
297
|
try {
|
|
300
298
|
const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
@@ -374,19 +372,10 @@ function withDefault(parser, defaultValue, options) {
|
|
|
374
372
|
*/
|
|
375
373
|
function map(parser, transform) {
|
|
376
374
|
const complete = (state) => {
|
|
377
|
-
|
|
378
|
-
if (res instanceof Promise) return res.then((r) => {
|
|
379
|
-
if (r.success) return {
|
|
380
|
-
success: true,
|
|
381
|
-
value: transform(r.value)
|
|
382
|
-
};
|
|
383
|
-
return r;
|
|
384
|
-
});
|
|
385
|
-
if (res.success) return {
|
|
375
|
+
return require_mode_dispatch.mapModeValue(parser.$mode, parser.complete(state), (result) => result.success ? {
|
|
386
376
|
success: true,
|
|
387
|
-
value: transform(
|
|
388
|
-
};
|
|
389
|
-
return res;
|
|
377
|
+
value: transform(result.value)
|
|
378
|
+
} : result);
|
|
390
379
|
};
|
|
391
380
|
const dependencyMarkers = require_dependency.isWrappedDependencySource(parser) ? {
|
|
392
381
|
[require_dependency.wrappedDependencySourceMarker]: parser[require_dependency.wrappedDependencySourceMarker],
|
package/dist/modifiers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { formatMessage, message, text } from "./message.js";
|
|
2
2
|
import { createDependencySourceState, dependencyId, isDependencySourceState, isPendingDependencySourceState, isWrappedDependencySource, transformsDependencyValue, transformsDependencyValueMarker, wrappedDependencySourceMarker } from "./dependency.js";
|
|
3
|
-
import { dispatchByMode, dispatchIterableByMode } from "./mode-dispatch.js";
|
|
3
|
+
import { dispatchByMode, dispatchIterableByMode, mapModeValue } from "./mode-dispatch.js";
|
|
4
4
|
|
|
5
5
|
//#region src/modifiers.ts
|
|
6
6
|
/**
|
|
@@ -235,8 +235,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
235
235
|
};
|
|
236
236
|
}
|
|
237
237
|
};
|
|
238
|
-
|
|
239
|
-
return handleInnerResult(innerResult);
|
|
238
|
+
return mapModeValue(parser.$mode, innerResult, handleInnerResult);
|
|
240
239
|
}
|
|
241
240
|
if (isWrappedDependencySource(parser)) try {
|
|
242
241
|
const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
@@ -293,8 +292,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
293
292
|
};
|
|
294
293
|
}
|
|
295
294
|
};
|
|
296
|
-
|
|
297
|
-
return handleInnerResult(innerResult);
|
|
295
|
+
return mapModeValue(parser.$mode, innerResult, handleInnerResult);
|
|
298
296
|
}
|
|
299
297
|
try {
|
|
300
298
|
const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
@@ -374,19 +372,10 @@ function withDefault(parser, defaultValue, options) {
|
|
|
374
372
|
*/
|
|
375
373
|
function map(parser, transform) {
|
|
376
374
|
const complete = (state) => {
|
|
377
|
-
|
|
378
|
-
if (res instanceof Promise) return res.then((r) => {
|
|
379
|
-
if (r.success) return {
|
|
380
|
-
success: true,
|
|
381
|
-
value: transform(r.value)
|
|
382
|
-
};
|
|
383
|
-
return r;
|
|
384
|
-
});
|
|
385
|
-
if (res.success) return {
|
|
375
|
+
return mapModeValue(parser.$mode, parser.complete(state), (result) => result.success ? {
|
|
386
376
|
success: true,
|
|
387
|
-
value: transform(
|
|
388
|
-
};
|
|
389
|
-
return res;
|
|
377
|
+
value: transform(result.value)
|
|
378
|
+
} : result);
|
|
390
379
|
};
|
|
391
380
|
const dependencyMarkers = isWrappedDependencySource(parser) ? {
|
|
392
381
|
[wrappedDependencySourceMarker]: parser[wrappedDependencySourceMarker],
|
package/dist/parser.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_annotations = require('./annotations.cjs');
|
|
2
2
|
const require_message = require('./message.cjs');
|
|
3
|
+
const require_mode_dispatch = require('./mode-dispatch.cjs');
|
|
3
4
|
const require_usage = require('./usage.cjs');
|
|
4
5
|
const require_constructs = require('./constructs.cjs');
|
|
5
6
|
const require_modifiers = require('./modifiers.cjs');
|
|
@@ -138,8 +139,7 @@ async function parseAsync(parser, args, options) {
|
|
|
138
139
|
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
139
140
|
*/
|
|
140
141
|
function parse(parser, args, options) {
|
|
141
|
-
|
|
142
|
-
return parseSync(parser, args, options);
|
|
142
|
+
return require_mode_dispatch.dispatchByMode(parser.$mode, () => parseSync(parser, args, options), () => parseAsync(parser, args, options));
|
|
143
143
|
}
|
|
144
144
|
/**
|
|
145
145
|
* Generates command-line suggestions based on current parsing state.
|
|
@@ -273,8 +273,7 @@ async function suggestAsync(parser, args, options) {
|
|
|
273
273
|
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
274
274
|
*/
|
|
275
275
|
function suggest(parser, args, options) {
|
|
276
|
-
|
|
277
|
-
return suggestSync(parser, args, options);
|
|
276
|
+
return require_mode_dispatch.dispatchByMode(parser.$mode, () => suggestSync(parser, args, options), () => suggestAsync(parser, args, options));
|
|
278
277
|
}
|
|
279
278
|
/**
|
|
280
279
|
* Recursively searches for a command within nested exclusive usage terms.
|
package/dist/parser.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { annotationKey } from "./annotations.js";
|
|
2
2
|
import { message } from "./message.js";
|
|
3
|
+
import { dispatchByMode } from "./mode-dispatch.js";
|
|
3
4
|
import { normalizeUsage } from "./usage.js";
|
|
4
5
|
import { DuplicateOptionError, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
|
|
5
6
|
import { WithDefaultError, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
|
|
@@ -138,8 +139,7 @@ async function parseAsync(parser, args, options) {
|
|
|
138
139
|
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
139
140
|
*/
|
|
140
141
|
function parse(parser, args, options) {
|
|
141
|
-
|
|
142
|
-
return parseSync(parser, args, options);
|
|
142
|
+
return dispatchByMode(parser.$mode, () => parseSync(parser, args, options), () => parseAsync(parser, args, options));
|
|
143
143
|
}
|
|
144
144
|
/**
|
|
145
145
|
* Generates command-line suggestions based on current parsing state.
|
|
@@ -273,8 +273,7 @@ async function suggestAsync(parser, args, options) {
|
|
|
273
273
|
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
274
274
|
*/
|
|
275
275
|
function suggest(parser, args, options) {
|
|
276
|
-
|
|
277
|
-
return suggestSync(parser, args, options);
|
|
276
|
+
return dispatchByMode(parser.$mode, () => suggestSync(parser, args, options), () => suggestAsync(parser, args, options));
|
|
278
277
|
}
|
|
279
278
|
/**
|
|
280
279
|
* Recursively searches for a command within nested exclusive usage terms.
|