@optique/core 0.9.0-dev.204 → 0.9.0-dev.206
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 +90 -36
- package/dist/facade.d.cts +37 -1
- package/dist/facade.d.ts +37 -1
- package/dist/facade.js +88 -36
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/dist/facade.cjs
CHANGED
|
@@ -404,7 +404,7 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
|
|
|
404
404
|
return callOnCompletion(0);
|
|
405
405
|
}
|
|
406
406
|
function runParser(parser, programName, args, options = {}) {
|
|
407
|
-
|
|
407
|
+
const { colors, maxWidth, showDefault, aboveError = "usage", onError = () => {
|
|
408
408
|
throw new RunParserError("Failed to parse command line arguments.");
|
|
409
409
|
}, stderr = console.error, stdout = console.log, brief, description, footer } = options;
|
|
410
410
|
const helpMode = options.help?.mode ?? "option";
|
|
@@ -500,31 +500,35 @@ function runParser(parser, programName, args, options = {}) {
|
|
|
500
500
|
else if (commandParsers.length === 2) helpGeneratorParser = require_constructs.longestMatch(commandParsers[0], commandParsers[1]);
|
|
501
501
|
else helpGeneratorParser = require_constructs.longestMatch(...commandParsers);
|
|
502
502
|
}
|
|
503
|
-
const
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
503
|
+
const displayHelp = (doc) => {
|
|
504
|
+
if (doc != null) {
|
|
505
|
+
const isMetaCommandHelp = (completionName === "singular" || completionName === "both" ? requestedCommand === "completion" : false) || (completionName === "plural" || completionName === "both" ? requestedCommand === "completions" : false) || requestedCommand === "help" || requestedCommand === "version";
|
|
506
|
+
const augmentedDoc = {
|
|
507
|
+
...doc,
|
|
508
|
+
brief: !isMetaCommandHelp ? brief ?? doc.brief : doc.brief,
|
|
509
|
+
description: !isMetaCommandHelp ? description ?? doc.description : doc.description,
|
|
510
|
+
footer: !isMetaCommandHelp ? footer ?? doc.footer : doc.footer
|
|
511
|
+
};
|
|
512
|
+
stdout(require_doc.formatDocPage(programName, augmentedDoc, {
|
|
513
|
+
colors,
|
|
514
|
+
maxWidth,
|
|
515
|
+
showDefault
|
|
516
|
+
}));
|
|
517
|
+
}
|
|
518
|
+
try {
|
|
519
|
+
return onHelp(0);
|
|
520
|
+
} catch {
|
|
521
|
+
return onHelp();
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
const docOrPromise = require_parser.getDocPage(helpGeneratorParser, classified.commands);
|
|
525
|
+
if (docOrPromise instanceof Promise) return docOrPromise.then(displayHelp);
|
|
526
|
+
return displayHelp(docOrPromise);
|
|
523
527
|
}
|
|
524
528
|
case "error": {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
if (doc == null)
|
|
529
|
+
const displayError = (doc, currentAboveError) => {
|
|
530
|
+
let effectiveAboveError = currentAboveError;
|
|
531
|
+
if (effectiveAboveError === "help") if (doc == null) effectiveAboveError = "usage";
|
|
528
532
|
else {
|
|
529
533
|
const augmentedDoc = {
|
|
530
534
|
...doc,
|
|
@@ -538,18 +542,25 @@ function runParser(parser, programName, args, options = {}) {
|
|
|
538
542
|
showDefault
|
|
539
543
|
}));
|
|
540
544
|
}
|
|
545
|
+
if (effectiveAboveError === "usage") stderr(`Usage: ${indentLines(require_usage.formatUsage(programName, augmentedParser.usage, {
|
|
546
|
+
colors,
|
|
547
|
+
maxWidth: maxWidth == null ? void 0 : maxWidth - 7,
|
|
548
|
+
expandCommands: true
|
|
549
|
+
}), 7)}`);
|
|
550
|
+
const errorMessage = require_message.formatMessage(classified.error, {
|
|
551
|
+
colors,
|
|
552
|
+
quotes: !colors
|
|
553
|
+
});
|
|
554
|
+
stderr(`Error: ${errorMessage}`);
|
|
555
|
+
return onError(1);
|
|
556
|
+
};
|
|
557
|
+
if (aboveError === "help") {
|
|
558
|
+
const parserForDoc = args.length < 1 ? augmentedParser : parser;
|
|
559
|
+
const docOrPromise = require_parser.getDocPage(parserForDoc, args);
|
|
560
|
+
if (docOrPromise instanceof Promise) return docOrPromise.then((doc) => displayError(doc, aboveError));
|
|
561
|
+
return displayError(docOrPromise, aboveError);
|
|
541
562
|
}
|
|
542
|
-
|
|
543
|
-
colors,
|
|
544
|
-
maxWidth: maxWidth == null ? void 0 : maxWidth - 7,
|
|
545
|
-
expandCommands: true
|
|
546
|
-
}), 7)}`);
|
|
547
|
-
const errorMessage = require_message.formatMessage(classified.error, {
|
|
548
|
-
colors,
|
|
549
|
-
quotes: !colors
|
|
550
|
-
});
|
|
551
|
-
stderr(`Error: ${errorMessage}`);
|
|
552
|
-
return onError(1);
|
|
563
|
+
return displayError(void 0, aboveError);
|
|
553
564
|
}
|
|
554
565
|
default: throw new RunParserError("Unexpected parse result type");
|
|
555
566
|
}
|
|
@@ -561,6 +572,47 @@ function runParser(parser, programName, args, options = {}) {
|
|
|
561
572
|
}
|
|
562
573
|
}
|
|
563
574
|
/**
|
|
575
|
+
* Runs a synchronous command-line parser with the given options.
|
|
576
|
+
*
|
|
577
|
+
* This is a type-safe version of {@link runParser} that only accepts sync
|
|
578
|
+
* parsers. Use this when you know your parser is sync-only to get direct
|
|
579
|
+
* return values without Promise wrappers.
|
|
580
|
+
*
|
|
581
|
+
* @template TParser The sync parser type being executed.
|
|
582
|
+
* @template THelp The return type of the onHelp callback.
|
|
583
|
+
* @template TError The return type of the onError callback.
|
|
584
|
+
* @param parser The synchronous command-line parser to execute.
|
|
585
|
+
* @param programName The name of the program for help messages.
|
|
586
|
+
* @param args The command-line arguments to parse.
|
|
587
|
+
* @param options Configuration options for customizing behavior.
|
|
588
|
+
* @returns The parsed result if successful.
|
|
589
|
+
* @since 0.9.0
|
|
590
|
+
*/
|
|
591
|
+
function runParserSync(parser, programName, args, options) {
|
|
592
|
+
return runParser(parser, programName, args, options);
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Runs any command-line parser asynchronously with the given options.
|
|
596
|
+
*
|
|
597
|
+
* This function accepts parsers of any mode (sync or async) and always
|
|
598
|
+
* returns a Promise. Use this when working with parsers that may contain
|
|
599
|
+
* async value parsers.
|
|
600
|
+
*
|
|
601
|
+
* @template TParser The parser type being executed.
|
|
602
|
+
* @template THelp The return type of the onHelp callback.
|
|
603
|
+
* @template TError The return type of the onError callback.
|
|
604
|
+
* @param parser The command-line parser to execute.
|
|
605
|
+
* @param programName The name of the program for help messages.
|
|
606
|
+
* @param args The command-line arguments to parse.
|
|
607
|
+
* @param options Configuration options for customizing behavior.
|
|
608
|
+
* @returns A Promise of the parsed result if successful.
|
|
609
|
+
* @since 0.9.0
|
|
610
|
+
*/
|
|
611
|
+
function runParserAsync(parser, programName, args, options) {
|
|
612
|
+
const result = runParser(parser, programName, args, options);
|
|
613
|
+
return Promise.resolve(result);
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
564
616
|
* @deprecated Use `runParser()` instead. This export will be removed in
|
|
565
617
|
* a future major version. The name `run` conflicts with
|
|
566
618
|
* `@optique/run`'s `run()` function, causing IDE autocomplete
|
|
@@ -590,4 +642,6 @@ function indentLines(text$1, indent) {
|
|
|
590
642
|
exports.RunError = RunError;
|
|
591
643
|
exports.RunParserError = RunParserError;
|
|
592
644
|
exports.run = run;
|
|
593
|
-
exports.runParser = runParser;
|
|
645
|
+
exports.runParser = runParser;
|
|
646
|
+
exports.runParserAsync = runParserAsync;
|
|
647
|
+
exports.runParserSync = runParserSync;
|
package/dist/facade.d.cts
CHANGED
|
@@ -217,6 +217,42 @@ interface RunOptions<THelp, TError> {
|
|
|
217
217
|
declare function runParser<TParser extends Parser<"sync", unknown, unknown>, THelp = void, TError = never>(parser: TParser, programName: string, args: readonly string[], options?: RunOptions<THelp, TError>): InferValue<TParser>;
|
|
218
218
|
declare function runParser<TParser extends Parser<"async", unknown, unknown>, THelp = void, TError = never>(parser: TParser, programName: string, args: readonly string[], options?: RunOptions<THelp, TError>): Promise<InferValue<TParser>>;
|
|
219
219
|
declare function runParser<TParser extends Parser<Mode, unknown, unknown>, THelp = void, TError = never>(parser: TParser, programName: string, args: readonly string[], options?: RunOptions<THelp, TError>): ModeValue<InferMode<TParser>, InferValue<TParser>>;
|
|
220
|
+
/**
|
|
221
|
+
* Runs a synchronous command-line parser with the given options.
|
|
222
|
+
*
|
|
223
|
+
* This is a type-safe version of {@link runParser} that only accepts sync
|
|
224
|
+
* parsers. Use this when you know your parser is sync-only to get direct
|
|
225
|
+
* return values without Promise wrappers.
|
|
226
|
+
*
|
|
227
|
+
* @template TParser The sync parser type being executed.
|
|
228
|
+
* @template THelp The return type of the onHelp callback.
|
|
229
|
+
* @template TError The return type of the onError callback.
|
|
230
|
+
* @param parser The synchronous command-line parser to execute.
|
|
231
|
+
* @param programName The name of the program for help messages.
|
|
232
|
+
* @param args The command-line arguments to parse.
|
|
233
|
+
* @param options Configuration options for customizing behavior.
|
|
234
|
+
* @returns The parsed result if successful.
|
|
235
|
+
* @since 0.9.0
|
|
236
|
+
*/
|
|
237
|
+
declare function runParserSync<TParser extends Parser<"sync", unknown, unknown>, THelp = void, TError = never>(parser: TParser, programName: string, args: readonly string[], options?: RunOptions<THelp, TError>): InferValue<TParser>;
|
|
238
|
+
/**
|
|
239
|
+
* Runs any command-line parser asynchronously with the given options.
|
|
240
|
+
*
|
|
241
|
+
* This function accepts parsers of any mode (sync or async) and always
|
|
242
|
+
* returns a Promise. Use this when working with parsers that may contain
|
|
243
|
+
* async value parsers.
|
|
244
|
+
*
|
|
245
|
+
* @template TParser The parser type being executed.
|
|
246
|
+
* @template THelp The return type of the onHelp callback.
|
|
247
|
+
* @template TError The return type of the onError callback.
|
|
248
|
+
* @param parser The command-line parser to execute.
|
|
249
|
+
* @param programName The name of the program for help messages.
|
|
250
|
+
* @param args The command-line arguments to parse.
|
|
251
|
+
* @param options Configuration options for customizing behavior.
|
|
252
|
+
* @returns A Promise of the parsed result if successful.
|
|
253
|
+
* @since 0.9.0
|
|
254
|
+
*/
|
|
255
|
+
declare function runParserAsync<TParser extends Parser<Mode, unknown, unknown>, THelp = void, TError = never>(parser: TParser, programName: string, args: readonly string[], options?: RunOptions<THelp, TError>): Promise<InferValue<TParser>>;
|
|
220
256
|
/**
|
|
221
257
|
* @deprecated Use `runParser()` instead. This export will be removed in
|
|
222
258
|
* a future major version. The name `run` conflicts with
|
|
@@ -237,4 +273,4 @@ declare class RunParserError extends Error {
|
|
|
237
273
|
*/
|
|
238
274
|
declare const RunError: typeof RunParserError;
|
|
239
275
|
//#endregion
|
|
240
|
-
export { RunError, RunOptions, RunParserError, run, runParser };
|
|
276
|
+
export { RunError, RunOptions, RunParserError, run, runParser, runParserAsync, runParserSync };
|
package/dist/facade.d.ts
CHANGED
|
@@ -217,6 +217,42 @@ interface RunOptions<THelp, TError> {
|
|
|
217
217
|
declare function runParser<TParser extends Parser<"sync", unknown, unknown>, THelp = void, TError = never>(parser: TParser, programName: string, args: readonly string[], options?: RunOptions<THelp, TError>): InferValue<TParser>;
|
|
218
218
|
declare function runParser<TParser extends Parser<"async", unknown, unknown>, THelp = void, TError = never>(parser: TParser, programName: string, args: readonly string[], options?: RunOptions<THelp, TError>): Promise<InferValue<TParser>>;
|
|
219
219
|
declare function runParser<TParser extends Parser<Mode, unknown, unknown>, THelp = void, TError = never>(parser: TParser, programName: string, args: readonly string[], options?: RunOptions<THelp, TError>): ModeValue<InferMode<TParser>, InferValue<TParser>>;
|
|
220
|
+
/**
|
|
221
|
+
* Runs a synchronous command-line parser with the given options.
|
|
222
|
+
*
|
|
223
|
+
* This is a type-safe version of {@link runParser} that only accepts sync
|
|
224
|
+
* parsers. Use this when you know your parser is sync-only to get direct
|
|
225
|
+
* return values without Promise wrappers.
|
|
226
|
+
*
|
|
227
|
+
* @template TParser The sync parser type being executed.
|
|
228
|
+
* @template THelp The return type of the onHelp callback.
|
|
229
|
+
* @template TError The return type of the onError callback.
|
|
230
|
+
* @param parser The synchronous command-line parser to execute.
|
|
231
|
+
* @param programName The name of the program for help messages.
|
|
232
|
+
* @param args The command-line arguments to parse.
|
|
233
|
+
* @param options Configuration options for customizing behavior.
|
|
234
|
+
* @returns The parsed result if successful.
|
|
235
|
+
* @since 0.9.0
|
|
236
|
+
*/
|
|
237
|
+
declare function runParserSync<TParser extends Parser<"sync", unknown, unknown>, THelp = void, TError = never>(parser: TParser, programName: string, args: readonly string[], options?: RunOptions<THelp, TError>): InferValue<TParser>;
|
|
238
|
+
/**
|
|
239
|
+
* Runs any command-line parser asynchronously with the given options.
|
|
240
|
+
*
|
|
241
|
+
* This function accepts parsers of any mode (sync or async) and always
|
|
242
|
+
* returns a Promise. Use this when working with parsers that may contain
|
|
243
|
+
* async value parsers.
|
|
244
|
+
*
|
|
245
|
+
* @template TParser The parser type being executed.
|
|
246
|
+
* @template THelp The return type of the onHelp callback.
|
|
247
|
+
* @template TError The return type of the onError callback.
|
|
248
|
+
* @param parser The command-line parser to execute.
|
|
249
|
+
* @param programName The name of the program for help messages.
|
|
250
|
+
* @param args The command-line arguments to parse.
|
|
251
|
+
* @param options Configuration options for customizing behavior.
|
|
252
|
+
* @returns A Promise of the parsed result if successful.
|
|
253
|
+
* @since 0.9.0
|
|
254
|
+
*/
|
|
255
|
+
declare function runParserAsync<TParser extends Parser<Mode, unknown, unknown>, THelp = void, TError = never>(parser: TParser, programName: string, args: readonly string[], options?: RunOptions<THelp, TError>): Promise<InferValue<TParser>>;
|
|
220
256
|
/**
|
|
221
257
|
* @deprecated Use `runParser()` instead. This export will be removed in
|
|
222
258
|
* a future major version. The name `run` conflicts with
|
|
@@ -237,4 +273,4 @@ declare class RunParserError extends Error {
|
|
|
237
273
|
*/
|
|
238
274
|
declare const RunError: typeof RunParserError;
|
|
239
275
|
//#endregion
|
|
240
|
-
export { RunError, RunOptions, RunParserError, run, runParser };
|
|
276
|
+
export { RunError, RunOptions, RunParserError, run, runParser, runParserAsync, runParserSync };
|
package/dist/facade.js
CHANGED
|
@@ -404,7 +404,7 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
|
|
|
404
404
|
return callOnCompletion(0);
|
|
405
405
|
}
|
|
406
406
|
function runParser(parser, programName, args, options = {}) {
|
|
407
|
-
|
|
407
|
+
const { colors, maxWidth, showDefault, aboveError = "usage", onError = () => {
|
|
408
408
|
throw new RunParserError("Failed to parse command line arguments.");
|
|
409
409
|
}, stderr = console.error, stdout = console.log, brief, description, footer } = options;
|
|
410
410
|
const helpMode = options.help?.mode ?? "option";
|
|
@@ -500,31 +500,35 @@ function runParser(parser, programName, args, options = {}) {
|
|
|
500
500
|
else if (commandParsers.length === 2) helpGeneratorParser = longestMatch(commandParsers[0], commandParsers[1]);
|
|
501
501
|
else helpGeneratorParser = longestMatch(...commandParsers);
|
|
502
502
|
}
|
|
503
|
-
const
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
503
|
+
const displayHelp = (doc) => {
|
|
504
|
+
if (doc != null) {
|
|
505
|
+
const isMetaCommandHelp = (completionName === "singular" || completionName === "both" ? requestedCommand === "completion" : false) || (completionName === "plural" || completionName === "both" ? requestedCommand === "completions" : false) || requestedCommand === "help" || requestedCommand === "version";
|
|
506
|
+
const augmentedDoc = {
|
|
507
|
+
...doc,
|
|
508
|
+
brief: !isMetaCommandHelp ? brief ?? doc.brief : doc.brief,
|
|
509
|
+
description: !isMetaCommandHelp ? description ?? doc.description : doc.description,
|
|
510
|
+
footer: !isMetaCommandHelp ? footer ?? doc.footer : doc.footer
|
|
511
|
+
};
|
|
512
|
+
stdout(formatDocPage(programName, augmentedDoc, {
|
|
513
|
+
colors,
|
|
514
|
+
maxWidth,
|
|
515
|
+
showDefault
|
|
516
|
+
}));
|
|
517
|
+
}
|
|
518
|
+
try {
|
|
519
|
+
return onHelp(0);
|
|
520
|
+
} catch {
|
|
521
|
+
return onHelp();
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
const docOrPromise = getDocPage(helpGeneratorParser, classified.commands);
|
|
525
|
+
if (docOrPromise instanceof Promise) return docOrPromise.then(displayHelp);
|
|
526
|
+
return displayHelp(docOrPromise);
|
|
523
527
|
}
|
|
524
528
|
case "error": {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
if (doc == null)
|
|
529
|
+
const displayError = (doc, currentAboveError) => {
|
|
530
|
+
let effectiveAboveError = currentAboveError;
|
|
531
|
+
if (effectiveAboveError === "help") if (doc == null) effectiveAboveError = "usage";
|
|
528
532
|
else {
|
|
529
533
|
const augmentedDoc = {
|
|
530
534
|
...doc,
|
|
@@ -538,18 +542,25 @@ function runParser(parser, programName, args, options = {}) {
|
|
|
538
542
|
showDefault
|
|
539
543
|
}));
|
|
540
544
|
}
|
|
545
|
+
if (effectiveAboveError === "usage") stderr(`Usage: ${indentLines(formatUsage(programName, augmentedParser.usage, {
|
|
546
|
+
colors,
|
|
547
|
+
maxWidth: maxWidth == null ? void 0 : maxWidth - 7,
|
|
548
|
+
expandCommands: true
|
|
549
|
+
}), 7)}`);
|
|
550
|
+
const errorMessage = formatMessage(classified.error, {
|
|
551
|
+
colors,
|
|
552
|
+
quotes: !colors
|
|
553
|
+
});
|
|
554
|
+
stderr(`Error: ${errorMessage}`);
|
|
555
|
+
return onError(1);
|
|
556
|
+
};
|
|
557
|
+
if (aboveError === "help") {
|
|
558
|
+
const parserForDoc = args.length < 1 ? augmentedParser : parser;
|
|
559
|
+
const docOrPromise = getDocPage(parserForDoc, args);
|
|
560
|
+
if (docOrPromise instanceof Promise) return docOrPromise.then((doc) => displayError(doc, aboveError));
|
|
561
|
+
return displayError(docOrPromise, aboveError);
|
|
541
562
|
}
|
|
542
|
-
|
|
543
|
-
colors,
|
|
544
|
-
maxWidth: maxWidth == null ? void 0 : maxWidth - 7,
|
|
545
|
-
expandCommands: true
|
|
546
|
-
}), 7)}`);
|
|
547
|
-
const errorMessage = formatMessage(classified.error, {
|
|
548
|
-
colors,
|
|
549
|
-
quotes: !colors
|
|
550
|
-
});
|
|
551
|
-
stderr(`Error: ${errorMessage}`);
|
|
552
|
-
return onError(1);
|
|
563
|
+
return displayError(void 0, aboveError);
|
|
553
564
|
}
|
|
554
565
|
default: throw new RunParserError("Unexpected parse result type");
|
|
555
566
|
}
|
|
@@ -561,6 +572,47 @@ function runParser(parser, programName, args, options = {}) {
|
|
|
561
572
|
}
|
|
562
573
|
}
|
|
563
574
|
/**
|
|
575
|
+
* Runs a synchronous command-line parser with the given options.
|
|
576
|
+
*
|
|
577
|
+
* This is a type-safe version of {@link runParser} that only accepts sync
|
|
578
|
+
* parsers. Use this when you know your parser is sync-only to get direct
|
|
579
|
+
* return values without Promise wrappers.
|
|
580
|
+
*
|
|
581
|
+
* @template TParser The sync parser type being executed.
|
|
582
|
+
* @template THelp The return type of the onHelp callback.
|
|
583
|
+
* @template TError The return type of the onError callback.
|
|
584
|
+
* @param parser The synchronous command-line parser to execute.
|
|
585
|
+
* @param programName The name of the program for help messages.
|
|
586
|
+
* @param args The command-line arguments to parse.
|
|
587
|
+
* @param options Configuration options for customizing behavior.
|
|
588
|
+
* @returns The parsed result if successful.
|
|
589
|
+
* @since 0.9.0
|
|
590
|
+
*/
|
|
591
|
+
function runParserSync(parser, programName, args, options) {
|
|
592
|
+
return runParser(parser, programName, args, options);
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Runs any command-line parser asynchronously with the given options.
|
|
596
|
+
*
|
|
597
|
+
* This function accepts parsers of any mode (sync or async) and always
|
|
598
|
+
* returns a Promise. Use this when working with parsers that may contain
|
|
599
|
+
* async value parsers.
|
|
600
|
+
*
|
|
601
|
+
* @template TParser The parser type being executed.
|
|
602
|
+
* @template THelp The return type of the onHelp callback.
|
|
603
|
+
* @template TError The return type of the onError callback.
|
|
604
|
+
* @param parser The command-line parser to execute.
|
|
605
|
+
* @param programName The name of the program for help messages.
|
|
606
|
+
* @param args The command-line arguments to parse.
|
|
607
|
+
* @param options Configuration options for customizing behavior.
|
|
608
|
+
* @returns A Promise of the parsed result if successful.
|
|
609
|
+
* @since 0.9.0
|
|
610
|
+
*/
|
|
611
|
+
function runParserAsync(parser, programName, args, options) {
|
|
612
|
+
const result = runParser(parser, programName, args, options);
|
|
613
|
+
return Promise.resolve(result);
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
564
616
|
* @deprecated Use `runParser()` instead. This export will be removed in
|
|
565
617
|
* a future major version. The name `run` conflicts with
|
|
566
618
|
* `@optique/run`'s `run()` function, causing IDE autocomplete
|
|
@@ -587,4 +639,4 @@ function indentLines(text$1, indent) {
|
|
|
587
639
|
}
|
|
588
640
|
|
|
589
641
|
//#endregion
|
|
590
|
-
export { RunError, RunParserError, run, runParser };
|
|
642
|
+
export { RunError, RunParserError, run, runParser, runParserAsync, runParserSync };
|
package/dist/index.cjs
CHANGED
|
@@ -63,6 +63,8 @@ exports.passThrough = require_primitives.passThrough;
|
|
|
63
63
|
exports.pwsh = require_completion.pwsh;
|
|
64
64
|
exports.run = require_facade.run;
|
|
65
65
|
exports.runParser = require_facade.runParser;
|
|
66
|
+
exports.runParserAsync = require_facade.runParserAsync;
|
|
67
|
+
exports.runParserSync = require_facade.runParserSync;
|
|
66
68
|
exports.string = require_valueparser.string;
|
|
67
69
|
exports.suggest = require_parser.suggest;
|
|
68
70
|
exports.suggestAsync = require_parser.suggestAsync;
|
package/dist/index.d.cts
CHANGED
|
@@ -8,5 +8,5 @@ import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOpti
|
|
|
8
8
|
import { CombineModes, DocState, InferMode, InferValue, Mode, ModeIterable, ModeValue, Parser, ParserContext, ParserResult, Result, Suggestion, getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.cjs";
|
|
9
9
|
import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.cjs";
|
|
10
10
|
import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.cjs";
|
|
11
|
-
import { RunError, RunOptions, RunParserError, run, runParser } from "./facade.cjs";
|
|
12
|
-
export { ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, RunError, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, values, withDefault, zsh };
|
|
11
|
+
import { RunError, RunOptions, RunParserError, run, runParser, runParserAsync, runParserSync } from "./facade.cjs";
|
|
12
|
+
export { ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, RunError, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, values, withDefault, zsh };
|
package/dist/index.d.ts
CHANGED
|
@@ -8,5 +8,5 @@ import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOpti
|
|
|
8
8
|
import { CombineModes, DocState, InferMode, InferValue, Mode, ModeIterable, ModeValue, Parser, ParserContext, ParserResult, Result, Suggestion, getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.js";
|
|
9
9
|
import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
|
|
10
10
|
import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.js";
|
|
11
|
-
import { RunError, RunOptions, RunParserError, run, runParser } from "./facade.js";
|
|
12
|
-
export { ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, RunError, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, values, withDefault, zsh };
|
|
11
|
+
import { RunError, RunOptions, RunParserError, run, runParser, runParserAsync, runParserSync } from "./facade.js";
|
|
12
|
+
export { ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, RunError, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, values, withDefault, zsh };
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,6 @@ import { ensureNonEmptyString, isNonEmptyString } from "./nonempty.js";
|
|
|
8
8
|
import { choice, float, integer, isValueParser, locale, string, url, uuid } from "./valueparser.js";
|
|
9
9
|
import { argument, command, constant, flag, option, passThrough } from "./primitives.js";
|
|
10
10
|
import { getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.js";
|
|
11
|
-
import { RunError, RunParserError, run, runParser } from "./facade.js";
|
|
11
|
+
import { RunError, RunParserError, run, runParser, runParserAsync, runParserSync } from "./facade.js";
|
|
12
12
|
|
|
13
|
-
export { DuplicateOptionError, RunError, RunParserError, WithDefaultError, argument, bash, choice, command, commandLine, concat, conditional, constant, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, values, withDefault, zsh };
|
|
13
|
+
export { DuplicateOptionError, RunError, RunParserError, WithDefaultError, argument, bash, choice, command, commandLine, concat, conditional, constant, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, values, withDefault, zsh };
|