@optique/core 0.9.0-dev.206 → 0.9.0-dev.211
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/LICENSE +1 -1
- package/dist/constructs.cjs +609 -1339
- package/dist/constructs.d.cts +64 -184
- package/dist/constructs.d.ts +64 -184
- package/dist/constructs.js +609 -1339
- package/dist/facade.cjs +144 -188
- package/dist/facade.d.cts +3 -41
- package/dist/facade.d.ts +3 -41
- package/dist/facade.js +145 -187
- package/dist/index.cjs +0 -8
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/modifiers.cjs +79 -228
- package/dist/modifiers.d.cts +6 -11
- package/dist/modifiers.d.ts +6 -11
- package/dist/modifiers.js +79 -228
- package/dist/parser.cjs +33 -217
- package/dist/parser.d.cts +18 -202
- package/dist/parser.d.ts +18 -202
- package/dist/parser.js +34 -212
- package/dist/primitives.cjs +97 -242
- package/dist/primitives.d.cts +10 -14
- package/dist/primitives.d.ts +10 -14
- package/dist/primitives.js +97 -242
- package/dist/valueparser.cjs +1 -10
- package/dist/valueparser.d.cts +16 -29
- package/dist/valueparser.d.ts +16 -29
- package/dist/valueparser.js +1 -10
- package/package.json +1 -1
package/dist/facade.js
CHANGED
|
@@ -6,7 +6,7 @@ import { bash, fish, nu, pwsh, zsh } from "./completion.js";
|
|
|
6
6
|
import { multiple, optional, withDefault } from "./modifiers.js";
|
|
7
7
|
import { string } from "./valueparser.js";
|
|
8
8
|
import { argument, command, constant, flag, option } from "./primitives.js";
|
|
9
|
-
import { getDocPage,
|
|
9
|
+
import { getDocPage, parse, suggest } from "./parser.js";
|
|
10
10
|
|
|
11
11
|
//#region src/facade.ts
|
|
12
12
|
/**
|
|
@@ -89,11 +89,6 @@ function createCompletionParser(mode, programName, availableShells, name = "both
|
|
|
89
89
|
{ description: message`Generate shell completion script.` }
|
|
90
90
|
];
|
|
91
91
|
const completionOption = option(...completionOptionArgs);
|
|
92
|
-
const argsParser = withDefault(multiple(argument(string({ metavar: "ARG" }), { description: message`Command line arguments for completion suggestions (used by shell integration; you usually don't need to provide this).` })), []);
|
|
93
|
-
const optionParser = object({
|
|
94
|
-
shell: completionOption,
|
|
95
|
-
args: argsParser
|
|
96
|
-
});
|
|
97
92
|
switch (mode) {
|
|
98
93
|
case "command": return {
|
|
99
94
|
completionCommand,
|
|
@@ -101,11 +96,17 @@ function createCompletionParser(mode, programName, availableShells, name = "both
|
|
|
101
96
|
};
|
|
102
97
|
case "option": return {
|
|
103
98
|
completionCommand: null,
|
|
104
|
-
completionOption:
|
|
99
|
+
completionOption: object({
|
|
100
|
+
shell: completionOption,
|
|
101
|
+
args: withDefault(multiple(argument(string({ metavar: "ARG" }), { description: message`Command line arguments for completion suggestions (used by shell integration; you usually don't need to provide this).` })), [])
|
|
102
|
+
})
|
|
105
103
|
};
|
|
106
104
|
case "both": return {
|
|
107
105
|
completionCommand,
|
|
108
|
-
completionOption:
|
|
106
|
+
completionOption: object({
|
|
107
|
+
shell: completionOption,
|
|
108
|
+
args: withDefault(multiple(argument(string({ metavar: "ARG" }), { description: message`Command line arguments for completion suggestions (used by shell integration; you usually don't need to provide this).` })), [])
|
|
109
|
+
})
|
|
109
110
|
};
|
|
110
111
|
}
|
|
111
112
|
}
|
|
@@ -116,7 +117,6 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers, com
|
|
|
116
117
|
const parsers = [];
|
|
117
118
|
if (helpParsers.helpOption) {
|
|
118
119
|
const lenientHelpParser = {
|
|
119
|
-
$mode: "sync",
|
|
120
120
|
$valueType: [],
|
|
121
121
|
$stateType: [],
|
|
122
122
|
priority: 200,
|
|
@@ -178,11 +178,12 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers, com
|
|
|
178
178
|
value: state
|
|
179
179
|
};
|
|
180
180
|
},
|
|
181
|
-
|
|
182
|
-
if ("--help".startsWith(prefix))
|
|
181
|
+
suggest(_context, prefix) {
|
|
182
|
+
if ("--help".startsWith(prefix)) return [{
|
|
183
183
|
kind: "literal",
|
|
184
184
|
text: "--help"
|
|
185
|
-
};
|
|
185
|
+
}];
|
|
186
|
+
return [];
|
|
186
187
|
},
|
|
187
188
|
getDocFragments(state) {
|
|
188
189
|
return helpParsers.helpOption?.getDocFragments(state) ?? { fragments: [] };
|
|
@@ -192,7 +193,6 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers, com
|
|
|
192
193
|
}
|
|
193
194
|
if (versionParsers.versionOption) {
|
|
194
195
|
const lenientVersionParser = {
|
|
195
|
-
$mode: "sync",
|
|
196
196
|
$valueType: [],
|
|
197
197
|
$stateType: [],
|
|
198
198
|
priority: 200,
|
|
@@ -246,11 +246,12 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers, com
|
|
|
246
246
|
value: state
|
|
247
247
|
};
|
|
248
248
|
},
|
|
249
|
-
|
|
250
|
-
if ("--version".startsWith(prefix))
|
|
249
|
+
suggest(_context, prefix) {
|
|
250
|
+
if ("--version".startsWith(prefix)) return [{
|
|
251
251
|
kind: "literal",
|
|
252
252
|
text: "--version"
|
|
253
|
-
};
|
|
253
|
+
}];
|
|
254
|
+
return [];
|
|
254
255
|
},
|
|
255
256
|
getDocFragments(state) {
|
|
256
257
|
return versionParsers.versionOption?.getDocFragments(state) ?? { fragments: [] };
|
|
@@ -345,20 +346,6 @@ function classifyResult(result, args) {
|
|
|
345
346
|
function handleCompletion(completionArgs, programName, parser, completionParser, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionMode, completionName) {
|
|
346
347
|
const shellName = completionArgs[0] || "";
|
|
347
348
|
const args = completionArgs.slice(1);
|
|
348
|
-
const callOnError = (code) => {
|
|
349
|
-
try {
|
|
350
|
-
return onError(code);
|
|
351
|
-
} catch {
|
|
352
|
-
return onError();
|
|
353
|
-
}
|
|
354
|
-
};
|
|
355
|
-
const callOnCompletion = (code) => {
|
|
356
|
-
try {
|
|
357
|
-
return onCompletion(code);
|
|
358
|
-
} catch {
|
|
359
|
-
return onCompletion();
|
|
360
|
-
}
|
|
361
|
-
};
|
|
362
349
|
if (!shellName) {
|
|
363
350
|
stderr("Error: Missing shell name for completion.\n");
|
|
364
351
|
if (completionParser) {
|
|
@@ -368,43 +355,72 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
|
|
|
368
355
|
maxWidth
|
|
369
356
|
}));
|
|
370
357
|
}
|
|
371
|
-
|
|
372
|
-
|
|
358
|
+
try {
|
|
359
|
+
return onError(1);
|
|
360
|
+
} catch {
|
|
361
|
+
return onError();
|
|
362
|
+
}
|
|
373
363
|
}
|
|
374
364
|
const shell = availableShells[shellName];
|
|
375
365
|
if (!shell) {
|
|
376
366
|
const available = [];
|
|
377
|
-
for (const
|
|
367
|
+
for (const shell$1 in availableShells) {
|
|
378
368
|
if (available.length > 0) available.push(text(", "));
|
|
379
|
-
available.push(value(
|
|
369
|
+
available.push(value(shell$1));
|
|
380
370
|
}
|
|
381
371
|
stderr(formatMessage(message`Error: Unsupported shell ${shellName}. Available shells: ${available}.`, {
|
|
382
372
|
colors,
|
|
383
373
|
quotes: !colors
|
|
384
374
|
}));
|
|
385
|
-
|
|
386
|
-
return callOnError(1);
|
|
375
|
+
return onError(1);
|
|
387
376
|
}
|
|
388
377
|
if (args.length === 0) {
|
|
389
378
|
const usePlural = completionName === "plural";
|
|
390
379
|
const completionArg = completionMode === "option" ? usePlural ? "--completions" : "--completion" : usePlural ? "completions" : "completion";
|
|
391
380
|
const script = shell.generateScript(programName, [completionArg, shellName]);
|
|
392
381
|
stdout(script);
|
|
393
|
-
|
|
394
|
-
|
|
382
|
+
} else {
|
|
383
|
+
const suggestions = suggest(parser, args);
|
|
384
|
+
for (const chunk of shell.encodeSuggestions(suggestions)) stdout(chunk);
|
|
385
|
+
}
|
|
386
|
+
try {
|
|
387
|
+
return onCompletion(0);
|
|
388
|
+
} catch {
|
|
389
|
+
return onCompletion();
|
|
395
390
|
}
|
|
396
|
-
if (parser.$mode === "async") return (async () => {
|
|
397
|
-
const suggestions$1 = await suggestAsync(parser, args);
|
|
398
|
-
for (const chunk of shell.encodeSuggestions(suggestions$1)) stdout(chunk);
|
|
399
|
-
return callOnCompletion(0);
|
|
400
|
-
})();
|
|
401
|
-
const syncParser = parser;
|
|
402
|
-
const suggestions = suggest(syncParser, args);
|
|
403
|
-
for (const chunk of shell.encodeSuggestions(suggestions)) stdout(chunk);
|
|
404
|
-
return callOnCompletion(0);
|
|
405
391
|
}
|
|
392
|
+
/**
|
|
393
|
+
* Runs a parser against command-line arguments with built-in help and error
|
|
394
|
+
* handling.
|
|
395
|
+
*
|
|
396
|
+
* This function provides a complete CLI interface by automatically handling
|
|
397
|
+
* help commands/options and displaying formatted error messages with usage
|
|
398
|
+
* information when parsing fails. It augments the provided parser with help
|
|
399
|
+
* functionality based on the configuration options.
|
|
400
|
+
*
|
|
401
|
+
* The function will:
|
|
402
|
+
*
|
|
403
|
+
* 1. Add help command/option support (unless disabled)
|
|
404
|
+
* 2. Parse the provided arguments
|
|
405
|
+
* 3. Display help if requested
|
|
406
|
+
* 4. Show formatted error messages with usage/help info on parse failures
|
|
407
|
+
* 5. Return the parsed result or invoke the appropriate callback
|
|
408
|
+
*
|
|
409
|
+
* @template TParser The parser type being run.
|
|
410
|
+
* @template THelp Return type when help is shown (defaults to `void`).
|
|
411
|
+
* @template TError Return type when an error occurs (defaults to `never`).
|
|
412
|
+
* @param parser The parser to run against the command-line arguments.
|
|
413
|
+
* @param programName Name of the program used in usage and help output.
|
|
414
|
+
* @param args Command-line arguments to parse (typically from
|
|
415
|
+
* `process.argv.slice(2)` on Node.js or `Deno.args` on Deno).
|
|
416
|
+
* @param options Configuration options for output formatting and callbacks.
|
|
417
|
+
* @returns The parsed result value, or the return value of `onHelp`/`onError`
|
|
418
|
+
* callbacks.
|
|
419
|
+
* @throws {RunParserError} When parsing fails and no `onError` callback is
|
|
420
|
+
* provided.
|
|
421
|
+
*/
|
|
406
422
|
function runParser(parser, programName, args, options = {}) {
|
|
407
|
-
|
|
423
|
+
let { colors, maxWidth, showDefault, aboveError = "usage", onError = () => {
|
|
408
424
|
throw new RunParserError("Failed to parse command line arguments.");
|
|
409
425
|
}, stderr = console.error, stdout = console.log, brief, description, footer } = options;
|
|
410
426
|
const helpMode = options.help?.mode ?? "option";
|
|
@@ -464,155 +480,97 @@ function runParser(parser, programName, args, options = {}) {
|
|
|
464
480
|
}
|
|
465
481
|
}
|
|
466
482
|
const augmentedParser = help === "none" && version === "none" && completion === "none" ? parser : combineWithHelpVersion(parser, helpParsers, versionParsers, completionParsers);
|
|
467
|
-
const
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
483
|
+
const result = parse(augmentedParser, args);
|
|
484
|
+
const classified = classifyResult(result, args);
|
|
485
|
+
switch (classified.type) {
|
|
486
|
+
case "success": return classified.value;
|
|
487
|
+
case "version":
|
|
488
|
+
stdout(versionValue);
|
|
489
|
+
try {
|
|
490
|
+
return onVersion(0);
|
|
491
|
+
} catch {
|
|
492
|
+
return onVersion();
|
|
493
|
+
}
|
|
494
|
+
case "completion": throw new RunParserError("Completion should be handled by early return");
|
|
495
|
+
case "help": {
|
|
496
|
+
let helpGeneratorParser;
|
|
497
|
+
const helpAsCommand = help === "command" || help === "both";
|
|
498
|
+
const versionAsCommand = version === "command" || version === "both";
|
|
499
|
+
const completionAsCommand = completion === "command" || completion === "both";
|
|
500
|
+
const requestedCommand = classified.commands[0];
|
|
501
|
+
if ((requestedCommand === "completion" || requestedCommand === "completions") && completionAsCommand && completionParsers.completionCommand) helpGeneratorParser = completionParsers.completionCommand;
|
|
502
|
+
else if (requestedCommand === "help" && helpAsCommand && helpParsers.helpCommand) helpGeneratorParser = helpParsers.helpCommand;
|
|
503
|
+
else if (requestedCommand === "version" && versionAsCommand && versionParsers.versionCommand) helpGeneratorParser = versionParsers.versionCommand;
|
|
504
|
+
else {
|
|
505
|
+
const commandParsers = [parser];
|
|
506
|
+
if (helpAsCommand) {
|
|
507
|
+
if (helpParsers.helpCommand) commandParsers.push(helpParsers.helpCommand);
|
|
477
508
|
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
let helpGeneratorParser;
|
|
481
|
-
const helpAsCommand = help === "command" || help === "both";
|
|
482
|
-
const versionAsCommand = version === "command" || version === "both";
|
|
483
|
-
const completionAsCommand = completion === "command" || completion === "both";
|
|
484
|
-
const requestedCommand = classified.commands[0];
|
|
485
|
-
if ((requestedCommand === "completion" || requestedCommand === "completions") && completionAsCommand && completionParsers.completionCommand) helpGeneratorParser = completionParsers.completionCommand;
|
|
486
|
-
else if (requestedCommand === "help" && helpAsCommand && helpParsers.helpCommand) helpGeneratorParser = helpParsers.helpCommand;
|
|
487
|
-
else if (requestedCommand === "version" && versionAsCommand && versionParsers.versionCommand) helpGeneratorParser = versionParsers.versionCommand;
|
|
488
|
-
else {
|
|
489
|
-
const commandParsers = [parser];
|
|
490
|
-
if (helpAsCommand) {
|
|
491
|
-
if (helpParsers.helpCommand) commandParsers.push(helpParsers.helpCommand);
|
|
492
|
-
}
|
|
493
|
-
if (versionAsCommand) {
|
|
494
|
-
if (versionParsers.versionCommand) commandParsers.push(versionParsers.versionCommand);
|
|
495
|
-
}
|
|
496
|
-
if (completionAsCommand) {
|
|
497
|
-
if (completionParsers.completionCommand) commandParsers.push(completionParsers.completionCommand);
|
|
498
|
-
}
|
|
499
|
-
if (commandParsers.length === 1) helpGeneratorParser = commandParsers[0];
|
|
500
|
-
else if (commandParsers.length === 2) helpGeneratorParser = longestMatch(commandParsers[0], commandParsers[1]);
|
|
501
|
-
else helpGeneratorParser = longestMatch(...commandParsers);
|
|
509
|
+
if (versionAsCommand) {
|
|
510
|
+
if (versionParsers.versionCommand) commandParsers.push(versionParsers.versionCommand);
|
|
502
511
|
}
|
|
503
|
-
|
|
504
|
-
if (
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
try {
|
|
519
|
-
return onHelp(0);
|
|
520
|
-
} catch {
|
|
521
|
-
return onHelp();
|
|
522
|
-
}
|
|
512
|
+
if (completionAsCommand) {
|
|
513
|
+
if (completionParsers.completionCommand) commandParsers.push(completionParsers.completionCommand);
|
|
514
|
+
}
|
|
515
|
+
if (commandParsers.length === 1) helpGeneratorParser = commandParsers[0];
|
|
516
|
+
else if (commandParsers.length === 2) helpGeneratorParser = longestMatch(commandParsers[0], commandParsers[1]);
|
|
517
|
+
else helpGeneratorParser = longestMatch(...commandParsers);
|
|
518
|
+
}
|
|
519
|
+
const doc = getDocPage(helpGeneratorParser, classified.commands);
|
|
520
|
+
if (doc != null) {
|
|
521
|
+
const isMetaCommandHelp = (completionName === "singular" || completionName === "both" ? requestedCommand === "completion" : false) || (completionName === "plural" || completionName === "both" ? requestedCommand === "completions" : false) || requestedCommand === "help" || requestedCommand === "version";
|
|
522
|
+
const augmentedDoc = {
|
|
523
|
+
...doc,
|
|
524
|
+
brief: !isMetaCommandHelp ? brief ?? doc.brief : doc.brief,
|
|
525
|
+
description: !isMetaCommandHelp ? description ?? doc.description : doc.description,
|
|
526
|
+
footer: !isMetaCommandHelp ? footer ?? doc.footer : doc.footer
|
|
523
527
|
};
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
528
|
+
stdout(formatDocPage(programName, augmentedDoc, {
|
|
529
|
+
colors,
|
|
530
|
+
maxWidth,
|
|
531
|
+
showDefault
|
|
532
|
+
}));
|
|
527
533
|
}
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
colors,
|
|
547
|
-
maxWidth: maxWidth == null ? void 0 : maxWidth - 7,
|
|
548
|
-
expandCommands: true
|
|
549
|
-
}), 7)}`);
|
|
550
|
-
const errorMessage = formatMessage(classified.error, {
|
|
534
|
+
try {
|
|
535
|
+
return onHelp(0);
|
|
536
|
+
} catch {
|
|
537
|
+
return onHelp();
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
case "error": {
|
|
541
|
+
if (aboveError === "help") {
|
|
542
|
+
const doc = getDocPage(args.length < 1 ? augmentedParser : parser, args);
|
|
543
|
+
if (doc == null) aboveError = "usage";
|
|
544
|
+
else {
|
|
545
|
+
const augmentedDoc = {
|
|
546
|
+
...doc,
|
|
547
|
+
brief: brief ?? doc.brief,
|
|
548
|
+
description: description ?? doc.description,
|
|
549
|
+
footer: footer ?? doc.footer
|
|
550
|
+
};
|
|
551
|
+
stderr(formatDocPage(programName, augmentedDoc, {
|
|
551
552
|
colors,
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
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);
|
|
553
|
+
maxWidth,
|
|
554
|
+
showDefault
|
|
555
|
+
}));
|
|
562
556
|
}
|
|
563
|
-
return displayError(void 0, aboveError);
|
|
564
557
|
}
|
|
565
|
-
|
|
558
|
+
if (aboveError === "usage") stderr(`Usage: ${indentLines(formatUsage(programName, augmentedParser.usage, {
|
|
559
|
+
colors,
|
|
560
|
+
maxWidth: maxWidth == null ? void 0 : maxWidth - 7,
|
|
561
|
+
expandCommands: true
|
|
562
|
+
}), 7)}`);
|
|
563
|
+
const errorMessage = formatMessage(classified.error, {
|
|
564
|
+
colors,
|
|
565
|
+
quotes: !colors
|
|
566
|
+
});
|
|
567
|
+
stderr(`Error: ${errorMessage}`);
|
|
568
|
+
return onError(1);
|
|
566
569
|
}
|
|
567
|
-
|
|
568
|
-
if (parser.$mode === "async") return parseAsync(augmentedParser, args).then(handleResult);
|
|
569
|
-
else {
|
|
570
|
-
const result = parseSync(augmentedParser, args);
|
|
571
|
-
return handleResult(result);
|
|
570
|
+
default: throw new RunParserError("Unexpected parse result type");
|
|
572
571
|
}
|
|
573
572
|
}
|
|
574
573
|
/**
|
|
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
|
-
/**
|
|
616
574
|
* @deprecated Use `runParser()` instead. This export will be removed in
|
|
617
575
|
* a future major version. The name `run` conflicts with
|
|
618
576
|
* `@optique/run`'s `run()` function, causing IDE autocomplete
|
|
@@ -639,4 +597,4 @@ function indentLines(text$1, indent) {
|
|
|
639
597
|
}
|
|
640
598
|
|
|
641
599
|
//#endregion
|
|
642
|
-
export { RunError, RunParserError, run, runParser
|
|
600
|
+
export { RunError, RunParserError, run, runParser };
|
package/dist/index.cjs
CHANGED
|
@@ -35,8 +35,6 @@ exports.formatMessage = require_message.formatMessage;
|
|
|
35
35
|
exports.formatUsage = require_usage.formatUsage;
|
|
36
36
|
exports.formatUsageTerm = require_usage.formatUsageTerm;
|
|
37
37
|
exports.getDocPage = require_parser.getDocPage;
|
|
38
|
-
exports.getDocPageAsync = require_parser.getDocPageAsync;
|
|
39
|
-
exports.getDocPageSync = require_parser.getDocPageSync;
|
|
40
38
|
exports.group = require_constructs.group;
|
|
41
39
|
exports.integer = require_valueparser.integer;
|
|
42
40
|
exports.isNonEmptyString = require_nonempty.isNonEmptyString;
|
|
@@ -57,18 +55,12 @@ exports.optionNames = require_message.optionNames;
|
|
|
57
55
|
exports.optional = require_modifiers.optional;
|
|
58
56
|
exports.or = require_constructs.or;
|
|
59
57
|
exports.parse = require_parser.parse;
|
|
60
|
-
exports.parseAsync = require_parser.parseAsync;
|
|
61
|
-
exports.parseSync = require_parser.parseSync;
|
|
62
58
|
exports.passThrough = require_primitives.passThrough;
|
|
63
59
|
exports.pwsh = require_completion.pwsh;
|
|
64
60
|
exports.run = require_facade.run;
|
|
65
61
|
exports.runParser = require_facade.runParser;
|
|
66
|
-
exports.runParserAsync = require_facade.runParserAsync;
|
|
67
|
-
exports.runParserSync = require_facade.runParserSync;
|
|
68
62
|
exports.string = require_valueparser.string;
|
|
69
63
|
exports.suggest = require_parser.suggest;
|
|
70
|
-
exports.suggestAsync = require_parser.suggestAsync;
|
|
71
|
-
exports.suggestSync = require_parser.suggestSync;
|
|
72
64
|
exports.text = require_message.text;
|
|
73
65
|
exports.tuple = require_constructs.tuple;
|
|
74
66
|
exports.url = require_valueparser.url;
|
package/dist/index.d.cts
CHANGED
|
@@ -5,8 +5,8 @@ import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, Doc
|
|
|
5
5
|
import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, FloatOptions, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, choice, float, integer, isValueParser, locale, string, url, uuid } from "./valueparser.cjs";
|
|
6
6
|
import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, optional, withDefault } from "./modifiers.cjs";
|
|
7
7
|
import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, PassThroughFormat, PassThroughOptions, argument, command, constant, flag, option, passThrough } from "./primitives.cjs";
|
|
8
|
-
import {
|
|
8
|
+
import { DocState, InferValue, Parser, ParserContext, ParserResult, Result, Suggestion, getDocPage, parse, suggest } 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
|
|
12
|
-
export { ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString,
|
|
11
|
+
import { RunError, RunOptions, RunParserError, run, runParser } from "./facade.cjs";
|
|
12
|
+
export { ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, 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, group, integer, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, passThrough, pwsh, run, runParser, string, suggest, text, tuple, url, uuid, value, values, withDefault, zsh };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, Doc
|
|
|
5
5
|
import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, FloatOptions, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, choice, float, integer, isValueParser, locale, string, url, uuid } from "./valueparser.js";
|
|
6
6
|
import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, optional, withDefault } from "./modifiers.js";
|
|
7
7
|
import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, PassThroughFormat, PassThroughOptions, argument, command, constant, flag, option, passThrough } from "./primitives.js";
|
|
8
|
-
import {
|
|
8
|
+
import { DocState, InferValue, Parser, ParserContext, ParserResult, Result, Suggestion, getDocPage, parse, suggest } 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
|
|
12
|
-
export { ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString,
|
|
11
|
+
import { RunError, RunOptions, RunParserError, run, runParser } from "./facade.js";
|
|
12
|
+
export { ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, 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, group, integer, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, passThrough, pwsh, run, runParser, string, suggest, text, tuple, url, uuid, value, values, withDefault, zsh };
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { WithDefaultError, map, multiple, optional, withDefault } from "./modifi
|
|
|
7
7
|
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
|
-
import { getDocPage,
|
|
11
|
-
import { RunError, RunParserError, run, runParser
|
|
10
|
+
import { getDocPage, parse, suggest } from "./parser.js";
|
|
11
|
+
import { RunError, RunParserError, run, runParser } 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,
|
|
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, group, integer, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, passThrough, pwsh, run, runParser, string, suggest, text, tuple, url, uuid, value, values, withDefault, zsh };
|