@optique/core 0.9.0-dev.175 → 0.9.0-dev.176
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/README.md +2 -2
- package/dist/facade.cjs +23 -8
- package/dist/facade.d.cts +17 -4
- package/dist/facade.d.ts +17 -4
- package/dist/facade.js +21 -8
- 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/README.md
CHANGED
|
@@ -37,7 +37,7 @@ Quick example
|
|
|
37
37
|
-------------
|
|
38
38
|
|
|
39
39
|
~~~~ typescript
|
|
40
|
-
import {
|
|
40
|
+
import { runParser } from "@optique/core/facade";
|
|
41
41
|
import { object, option, argument } from "@optique/core/parser";
|
|
42
42
|
import { string, integer } from "@optique/core/valueparser";
|
|
43
43
|
import process from "node:process";
|
|
@@ -48,7 +48,7 @@ const parser = object({
|
|
|
48
48
|
verbose: option("-v", "--verbose"),
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
-
const config =
|
|
51
|
+
const config = runParser(parser, "myapp", process.argv.slice(2), {
|
|
52
52
|
help: "both",
|
|
53
53
|
onError: process.exit,
|
|
54
54
|
});
|
package/dist/facade.cjs
CHANGED
|
@@ -416,11 +416,12 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
|
|
|
416
416
|
* @param options Configuration options for output formatting and callbacks.
|
|
417
417
|
* @returns The parsed result value, or the return value of `onHelp`/`onError`
|
|
418
418
|
* callbacks.
|
|
419
|
-
* @throws {
|
|
419
|
+
* @throws {RunParserError} When parsing fails and no `onError` callback is
|
|
420
|
+
* provided.
|
|
420
421
|
*/
|
|
421
|
-
function
|
|
422
|
+
function runParser(parser, programName, args, options = {}) {
|
|
422
423
|
let { colors, maxWidth, showDefault, aboveError = "usage", onError = () => {
|
|
423
|
-
throw new
|
|
424
|
+
throw new RunParserError("Failed to parse command line arguments.");
|
|
424
425
|
}, stderr = console.error, stdout = console.log, brief, description, footer } = options;
|
|
425
426
|
const helpMode = options.help?.mode ?? "option";
|
|
426
427
|
const onHelp = options.help?.onShow ?? (() => ({}));
|
|
@@ -490,7 +491,7 @@ function run(parser, programName, args, options = {}) {
|
|
|
490
491
|
} catch {
|
|
491
492
|
return onVersion();
|
|
492
493
|
}
|
|
493
|
-
case "completion": throw new
|
|
494
|
+
case "completion": throw new RunParserError("Completion should be handled by early return");
|
|
494
495
|
case "help": {
|
|
495
496
|
let helpGeneratorParser;
|
|
496
497
|
const helpAsCommand = help === "command" || help === "both";
|
|
@@ -566,23 +567,37 @@ function run(parser, programName, args, options = {}) {
|
|
|
566
567
|
stderr(`Error: ${errorMessage}`);
|
|
567
568
|
return onError(1);
|
|
568
569
|
}
|
|
569
|
-
default: throw new
|
|
570
|
+
default: throw new RunParserError("Unexpected parse result type");
|
|
570
571
|
}
|
|
571
572
|
}
|
|
572
573
|
/**
|
|
574
|
+
* @deprecated Use `runParser()` instead. This export will be removed in
|
|
575
|
+
* a future major version. The name `run` conflicts with
|
|
576
|
+
* `@optique/run`'s `run()` function, causing IDE autocomplete
|
|
577
|
+
* confusion.
|
|
578
|
+
*/
|
|
579
|
+
const run = runParser;
|
|
580
|
+
/**
|
|
573
581
|
* An error class used to indicate that the command line arguments
|
|
574
582
|
* could not be parsed successfully.
|
|
575
583
|
*/
|
|
576
|
-
var
|
|
584
|
+
var RunParserError = class extends Error {
|
|
577
585
|
constructor(message$1) {
|
|
578
586
|
super(message$1);
|
|
579
|
-
this.name = "
|
|
587
|
+
this.name = "RunParserError";
|
|
580
588
|
}
|
|
581
589
|
};
|
|
590
|
+
/**
|
|
591
|
+
* @deprecated Use `RunParserError` instead. This export will be removed in
|
|
592
|
+
* a future major version.
|
|
593
|
+
*/
|
|
594
|
+
const RunError = RunParserError;
|
|
582
595
|
function indentLines(text$1, indent) {
|
|
583
596
|
return text$1.split("\n").join("\n" + " ".repeat(indent));
|
|
584
597
|
}
|
|
585
598
|
|
|
586
599
|
//#endregion
|
|
587
600
|
exports.RunError = RunError;
|
|
588
|
-
exports.
|
|
601
|
+
exports.RunParserError = RunParserError;
|
|
602
|
+
exports.run = run;
|
|
603
|
+
exports.runParser = runParser;
|
package/dist/facade.d.cts
CHANGED
|
@@ -211,15 +211,28 @@ interface RunOptions<THelp, TError> {
|
|
|
211
211
|
* @param options Configuration options for output formatting and callbacks.
|
|
212
212
|
* @returns The parsed result value, or the return value of `onHelp`/`onError`
|
|
213
213
|
* callbacks.
|
|
214
|
-
* @throws {
|
|
214
|
+
* @throws {RunParserError} When parsing fails and no `onError` callback is
|
|
215
|
+
* provided.
|
|
215
216
|
*/
|
|
216
|
-
declare function
|
|
217
|
+
declare function runParser<TParser extends Parser<unknown, unknown>, THelp = void, TError = never>(parser: TParser, programName: string, args: readonly string[], options?: RunOptions<THelp, TError>): InferValue<TParser>;
|
|
218
|
+
/**
|
|
219
|
+
* @deprecated Use `runParser()` instead. This export will be removed in
|
|
220
|
+
* a future major version. The name `run` conflicts with
|
|
221
|
+
* `@optique/run`'s `run()` function, causing IDE autocomplete
|
|
222
|
+
* confusion.
|
|
223
|
+
*/
|
|
224
|
+
declare const run: typeof runParser;
|
|
217
225
|
/**
|
|
218
226
|
* An error class used to indicate that the command line arguments
|
|
219
227
|
* could not be parsed successfully.
|
|
220
228
|
*/
|
|
221
|
-
declare class
|
|
229
|
+
declare class RunParserError extends Error {
|
|
222
230
|
constructor(message: string);
|
|
223
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* @deprecated Use `RunParserError` instead. This export will be removed in
|
|
234
|
+
* a future major version.
|
|
235
|
+
*/
|
|
236
|
+
declare const RunError: typeof RunParserError;
|
|
224
237
|
//#endregion
|
|
225
|
-
export { RunError, RunOptions, run };
|
|
238
|
+
export { RunError, RunOptions, RunParserError, run, runParser };
|
package/dist/facade.d.ts
CHANGED
|
@@ -211,15 +211,28 @@ interface RunOptions<THelp, TError> {
|
|
|
211
211
|
* @param options Configuration options for output formatting and callbacks.
|
|
212
212
|
* @returns The parsed result value, or the return value of `onHelp`/`onError`
|
|
213
213
|
* callbacks.
|
|
214
|
-
* @throws {
|
|
214
|
+
* @throws {RunParserError} When parsing fails and no `onError` callback is
|
|
215
|
+
* provided.
|
|
215
216
|
*/
|
|
216
|
-
declare function
|
|
217
|
+
declare function runParser<TParser extends Parser<unknown, unknown>, THelp = void, TError = never>(parser: TParser, programName: string, args: readonly string[], options?: RunOptions<THelp, TError>): InferValue<TParser>;
|
|
218
|
+
/**
|
|
219
|
+
* @deprecated Use `runParser()` instead. This export will be removed in
|
|
220
|
+
* a future major version. The name `run` conflicts with
|
|
221
|
+
* `@optique/run`'s `run()` function, causing IDE autocomplete
|
|
222
|
+
* confusion.
|
|
223
|
+
*/
|
|
224
|
+
declare const run: typeof runParser;
|
|
217
225
|
/**
|
|
218
226
|
* An error class used to indicate that the command line arguments
|
|
219
227
|
* could not be parsed successfully.
|
|
220
228
|
*/
|
|
221
|
-
declare class
|
|
229
|
+
declare class RunParserError extends Error {
|
|
222
230
|
constructor(message: string);
|
|
223
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* @deprecated Use `RunParserError` instead. This export will be removed in
|
|
234
|
+
* a future major version.
|
|
235
|
+
*/
|
|
236
|
+
declare const RunError: typeof RunParserError;
|
|
224
237
|
//#endregion
|
|
225
|
-
export { RunError, RunOptions, run };
|
|
238
|
+
export { RunError, RunOptions, RunParserError, run, runParser };
|
package/dist/facade.js
CHANGED
|
@@ -416,11 +416,12 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
|
|
|
416
416
|
* @param options Configuration options for output formatting and callbacks.
|
|
417
417
|
* @returns The parsed result value, or the return value of `onHelp`/`onError`
|
|
418
418
|
* callbacks.
|
|
419
|
-
* @throws {
|
|
419
|
+
* @throws {RunParserError} When parsing fails and no `onError` callback is
|
|
420
|
+
* provided.
|
|
420
421
|
*/
|
|
421
|
-
function
|
|
422
|
+
function runParser(parser, programName, args, options = {}) {
|
|
422
423
|
let { colors, maxWidth, showDefault, aboveError = "usage", onError = () => {
|
|
423
|
-
throw new
|
|
424
|
+
throw new RunParserError("Failed to parse command line arguments.");
|
|
424
425
|
}, stderr = console.error, stdout = console.log, brief, description, footer } = options;
|
|
425
426
|
const helpMode = options.help?.mode ?? "option";
|
|
426
427
|
const onHelp = options.help?.onShow ?? (() => ({}));
|
|
@@ -490,7 +491,7 @@ function run(parser, programName, args, options = {}) {
|
|
|
490
491
|
} catch {
|
|
491
492
|
return onVersion();
|
|
492
493
|
}
|
|
493
|
-
case "completion": throw new
|
|
494
|
+
case "completion": throw new RunParserError("Completion should be handled by early return");
|
|
494
495
|
case "help": {
|
|
495
496
|
let helpGeneratorParser;
|
|
496
497
|
const helpAsCommand = help === "command" || help === "both";
|
|
@@ -566,22 +567,34 @@ function run(parser, programName, args, options = {}) {
|
|
|
566
567
|
stderr(`Error: ${errorMessage}`);
|
|
567
568
|
return onError(1);
|
|
568
569
|
}
|
|
569
|
-
default: throw new
|
|
570
|
+
default: throw new RunParserError("Unexpected parse result type");
|
|
570
571
|
}
|
|
571
572
|
}
|
|
572
573
|
/**
|
|
574
|
+
* @deprecated Use `runParser()` instead. This export will be removed in
|
|
575
|
+
* a future major version. The name `run` conflicts with
|
|
576
|
+
* `@optique/run`'s `run()` function, causing IDE autocomplete
|
|
577
|
+
* confusion.
|
|
578
|
+
*/
|
|
579
|
+
const run = runParser;
|
|
580
|
+
/**
|
|
573
581
|
* An error class used to indicate that the command line arguments
|
|
574
582
|
* could not be parsed successfully.
|
|
575
583
|
*/
|
|
576
|
-
var
|
|
584
|
+
var RunParserError = class extends Error {
|
|
577
585
|
constructor(message$1) {
|
|
578
586
|
super(message$1);
|
|
579
|
-
this.name = "
|
|
587
|
+
this.name = "RunParserError";
|
|
580
588
|
}
|
|
581
589
|
};
|
|
590
|
+
/**
|
|
591
|
+
* @deprecated Use `RunParserError` instead. This export will be removed in
|
|
592
|
+
* a future major version.
|
|
593
|
+
*/
|
|
594
|
+
const RunError = RunParserError;
|
|
582
595
|
function indentLines(text$1, indent) {
|
|
583
596
|
return text$1.split("\n").join("\n" + " ".repeat(indent));
|
|
584
597
|
}
|
|
585
598
|
|
|
586
599
|
//#endregion
|
|
587
|
-
export { RunError, run };
|
|
600
|
+
export { RunError, RunParserError, run, runParser };
|
package/dist/index.cjs
CHANGED
|
@@ -11,6 +11,7 @@ const require_facade = require('./facade.cjs');
|
|
|
11
11
|
|
|
12
12
|
exports.DuplicateOptionError = require_constructs.DuplicateOptionError;
|
|
13
13
|
exports.RunError = require_facade.RunError;
|
|
14
|
+
exports.RunParserError = require_facade.RunParserError;
|
|
14
15
|
exports.WithDefaultError = require_modifiers.WithDefaultError;
|
|
15
16
|
exports.argument = require_primitives.argument;
|
|
16
17
|
exports.bash = require_completion.bash;
|
|
@@ -54,6 +55,7 @@ exports.parse = require_parser.parse;
|
|
|
54
55
|
exports.passThrough = require_primitives.passThrough;
|
|
55
56
|
exports.pwsh = require_completion.pwsh;
|
|
56
57
|
exports.run = require_facade.run;
|
|
58
|
+
exports.runParser = require_facade.runParser;
|
|
57
59
|
exports.string = require_valueparser.string;
|
|
58
60
|
exports.suggest = require_parser.suggest;
|
|
59
61
|
exports.text = require_message.text;
|
package/dist/index.d.cts
CHANGED
|
@@ -7,5 +7,5 @@ import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOpti
|
|
|
7
7
|
import { DocState, InferValue, Parser, ParserContext, ParserResult, Result, Suggestion, getDocPage, parse, suggest } from "./parser.cjs";
|
|
8
8
|
import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.cjs";
|
|
9
9
|
import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.cjs";
|
|
10
|
-
import { RunError, RunOptions, run } from "./facade.cjs";
|
|
11
|
-
export { ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, 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, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, RunError, RunOptions, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, group, integer, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, passThrough, pwsh, run, string, suggest, text, tuple, url, uuid, value, values, withDefault, zsh };
|
|
10
|
+
import { RunError, RunOptions, RunParserError, run, runParser } from "./facade.cjs";
|
|
11
|
+
export { ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, 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, 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, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, group, integer, 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
|
@@ -7,5 +7,5 @@ import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOpti
|
|
|
7
7
|
import { DocState, InferValue, Parser, ParserContext, ParserResult, Result, Suggestion, getDocPage, parse, suggest } from "./parser.js";
|
|
8
8
|
import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
|
|
9
9
|
import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.js";
|
|
10
|
-
import { RunError, RunOptions, run } from "./facade.js";
|
|
11
|
-
export { ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, 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, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, RunError, RunOptions, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, group, integer, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, passThrough, pwsh, run, string, suggest, text, tuple, url, uuid, value, values, withDefault, zsh };
|
|
10
|
+
import { RunError, RunOptions, RunParserError, run, runParser } from "./facade.js";
|
|
11
|
+
export { ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, 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, 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, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, group, integer, 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,6 +7,6 @@ import { WithDefaultError, map, multiple, optional, withDefault } from "./modifi
|
|
|
7
7
|
import { choice, float, integer, isValueParser, locale, string, url, uuid } from "./valueparser.js";
|
|
8
8
|
import { argument, command, constant, flag, option, passThrough } from "./primitives.js";
|
|
9
9
|
import { getDocPage, parse, suggest } from "./parser.js";
|
|
10
|
-
import { RunError, run } from "./facade.js";
|
|
10
|
+
import { RunError, RunParserError, run, runParser } from "./facade.js";
|
|
11
11
|
|
|
12
|
-
export { DuplicateOptionError, RunError, WithDefaultError, argument, bash, choice, command, commandLine, concat, conditional, constant, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, group, integer, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, passThrough, pwsh, run, string, suggest, text, tuple, url, uuid, value, values, withDefault, zsh };
|
|
12
|
+
export { DuplicateOptionError, RunError, RunParserError, WithDefaultError, argument, bash, choice, command, commandLine, concat, conditional, constant, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, group, integer, 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 };
|