@optique/core 0.10.0-dev.330 → 0.10.0-dev.331
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/annotations.cjs +41 -0
- package/dist/annotations.d.cts +60 -0
- package/dist/annotations.d.ts +60 -0
- package/dist/annotations.js +39 -0
- package/dist/index.cjs +3 -0
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/parser.cjs +73 -26
- package/dist/parser.d.cts +31 -12
- package/dist/parser.d.ts +31 -12
- package/dist/parser.js +73 -26
- package/package.json +9 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/annotations.ts
|
|
3
|
+
/**
|
|
4
|
+
* Runtime context extension system for Optique parsers.
|
|
5
|
+
*
|
|
6
|
+
* This module provides the annotations system that allows external runtime data
|
|
7
|
+
* to be passed to parsers during the parsing session. This enables use cases like
|
|
8
|
+
* config file fallbacks, environment-based validation, and shared context.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
* @since 0.10.0
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Annotation key symbol for storing data in parser state.
|
|
15
|
+
* @since 0.10.0
|
|
16
|
+
*/
|
|
17
|
+
const annotationKey = Symbol.for("@optique/core/parser/annotation");
|
|
18
|
+
/**
|
|
19
|
+
* Extracts annotations from parser state.
|
|
20
|
+
*
|
|
21
|
+
* @param state Parser state that may contain annotations
|
|
22
|
+
* @returns Annotations object or undefined if no annotations are present
|
|
23
|
+
* @since 0.10.0
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const annotations = getAnnotations(state);
|
|
28
|
+
* const myData = annotations?.[myDataKey];
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
function getAnnotations(state) {
|
|
32
|
+
if (state == null || typeof state !== "object") return void 0;
|
|
33
|
+
const stateObj = state;
|
|
34
|
+
const annotations = stateObj[annotationKey];
|
|
35
|
+
if (annotations != null && typeof annotations === "object") return annotations;
|
|
36
|
+
return void 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
exports.annotationKey = annotationKey;
|
|
41
|
+
exports.getAnnotations = getAnnotations;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
//#region src/annotations.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Runtime context extension system for Optique parsers.
|
|
4
|
+
*
|
|
5
|
+
* This module provides the annotations system that allows external runtime data
|
|
6
|
+
* to be passed to parsers during the parsing session. This enables use cases like
|
|
7
|
+
* config file fallbacks, environment-based validation, and shared context.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
* @since 0.10.0
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Annotation key symbol for storing data in parser state.
|
|
14
|
+
* @since 0.10.0
|
|
15
|
+
*/
|
|
16
|
+
declare const annotationKey: unique symbol;
|
|
17
|
+
/**
|
|
18
|
+
* Annotations that can be passed to parsers during execution.
|
|
19
|
+
* Allows external packages to provide additional data that parsers can access
|
|
20
|
+
* during complete() or parse() phases.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const myDataKey = Symbol.for("@my-package/data");
|
|
25
|
+
* const result = parse(parser, args, {
|
|
26
|
+
* annotations: {
|
|
27
|
+
* [myDataKey]: { foo: "bar" }
|
|
28
|
+
* }
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
* @since 0.10.0
|
|
32
|
+
*/
|
|
33
|
+
type Annotations = Record<symbol, unknown>;
|
|
34
|
+
/**
|
|
35
|
+
* Options for parse functions.
|
|
36
|
+
* @since 0.10.0
|
|
37
|
+
*/
|
|
38
|
+
interface ParseOptions {
|
|
39
|
+
/**
|
|
40
|
+
* Annotations to attach to the parsing session.
|
|
41
|
+
* Parsers can access these annotations via getAnnotations(state).
|
|
42
|
+
*/
|
|
43
|
+
annotations?: Annotations;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Extracts annotations from parser state.
|
|
47
|
+
*
|
|
48
|
+
* @param state Parser state that may contain annotations
|
|
49
|
+
* @returns Annotations object or undefined if no annotations are present
|
|
50
|
+
* @since 0.10.0
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const annotations = getAnnotations(state);
|
|
55
|
+
* const myData = annotations?.[myDataKey];
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
declare function getAnnotations(state: unknown): Annotations | undefined;
|
|
59
|
+
//#endregion
|
|
60
|
+
export { Annotations, ParseOptions, annotationKey, getAnnotations };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
//#region src/annotations.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Runtime context extension system for Optique parsers.
|
|
4
|
+
*
|
|
5
|
+
* This module provides the annotations system that allows external runtime data
|
|
6
|
+
* to be passed to parsers during the parsing session. This enables use cases like
|
|
7
|
+
* config file fallbacks, environment-based validation, and shared context.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
* @since 0.10.0
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Annotation key symbol for storing data in parser state.
|
|
14
|
+
* @since 0.10.0
|
|
15
|
+
*/
|
|
16
|
+
declare const annotationKey: unique symbol;
|
|
17
|
+
/**
|
|
18
|
+
* Annotations that can be passed to parsers during execution.
|
|
19
|
+
* Allows external packages to provide additional data that parsers can access
|
|
20
|
+
* during complete() or parse() phases.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const myDataKey = Symbol.for("@my-package/data");
|
|
25
|
+
* const result = parse(parser, args, {
|
|
26
|
+
* annotations: {
|
|
27
|
+
* [myDataKey]: { foo: "bar" }
|
|
28
|
+
* }
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
* @since 0.10.0
|
|
32
|
+
*/
|
|
33
|
+
type Annotations = Record<symbol, unknown>;
|
|
34
|
+
/**
|
|
35
|
+
* Options for parse functions.
|
|
36
|
+
* @since 0.10.0
|
|
37
|
+
*/
|
|
38
|
+
interface ParseOptions {
|
|
39
|
+
/**
|
|
40
|
+
* Annotations to attach to the parsing session.
|
|
41
|
+
* Parsers can access these annotations via getAnnotations(state).
|
|
42
|
+
*/
|
|
43
|
+
annotations?: Annotations;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Extracts annotations from parser state.
|
|
47
|
+
*
|
|
48
|
+
* @param state Parser state that may contain annotations
|
|
49
|
+
* @returns Annotations object or undefined if no annotations are present
|
|
50
|
+
* @since 0.10.0
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const annotations = getAnnotations(state);
|
|
55
|
+
* const myData = annotations?.[myDataKey];
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
declare function getAnnotations(state: unknown): Annotations | undefined;
|
|
59
|
+
//#endregion
|
|
60
|
+
export { Annotations, ParseOptions, annotationKey, getAnnotations };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/annotations.ts
|
|
2
|
+
/**
|
|
3
|
+
* Runtime context extension system for Optique parsers.
|
|
4
|
+
*
|
|
5
|
+
* This module provides the annotations system that allows external runtime data
|
|
6
|
+
* to be passed to parsers during the parsing session. This enables use cases like
|
|
7
|
+
* config file fallbacks, environment-based validation, and shared context.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
* @since 0.10.0
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Annotation key symbol for storing data in parser state.
|
|
14
|
+
* @since 0.10.0
|
|
15
|
+
*/
|
|
16
|
+
const annotationKey = Symbol.for("@optique/core/parser/annotation");
|
|
17
|
+
/**
|
|
18
|
+
* Extracts annotations from parser state.
|
|
19
|
+
*
|
|
20
|
+
* @param state Parser state that may contain annotations
|
|
21
|
+
* @returns Annotations object or undefined if no annotations are present
|
|
22
|
+
* @since 0.10.0
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const annotations = getAnnotations(state);
|
|
27
|
+
* const myData = annotations?.[myDataKey];
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
function getAnnotations(state) {
|
|
31
|
+
if (state == null || typeof state !== "object") return void 0;
|
|
32
|
+
const stateObj = state;
|
|
33
|
+
const annotations = stateObj[annotationKey];
|
|
34
|
+
if (annotations != null && typeof annotations === "object") return annotations;
|
|
35
|
+
return void 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { annotationKey, getAnnotations };
|
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const require_annotations = require('./annotations.cjs');
|
|
1
2
|
const require_message = require('./message.cjs');
|
|
2
3
|
const require_completion = require('./completion.cjs');
|
|
3
4
|
const require_dependency = require('./dependency.cjs');
|
|
@@ -15,6 +16,7 @@ exports.DependencyRegistry = require_dependency.DependencyRegistry;
|
|
|
15
16
|
exports.DuplicateOptionError = require_constructs.DuplicateOptionError;
|
|
16
17
|
exports.RunParserError = require_facade.RunParserError;
|
|
17
18
|
exports.WithDefaultError = require_modifiers.WithDefaultError;
|
|
19
|
+
exports.annotationKey = require_annotations.annotationKey;
|
|
18
20
|
exports.argument = require_primitives.argument;
|
|
19
21
|
exports.bash = require_completion.bash;
|
|
20
22
|
exports.choice = require_valueparser.choice;
|
|
@@ -50,6 +52,7 @@ exports.formatDocPage = require_doc.formatDocPage;
|
|
|
50
52
|
exports.formatMessage = require_message.formatMessage;
|
|
51
53
|
exports.formatUsage = require_usage.formatUsage;
|
|
52
54
|
exports.formatUsageTerm = require_usage.formatUsageTerm;
|
|
55
|
+
exports.getAnnotations = require_annotations.getAnnotations;
|
|
53
56
|
exports.getDefaultValuesFunction = require_dependency.getDefaultValuesFunction;
|
|
54
57
|
exports.getDependencyIds = require_dependency.getDependencyIds;
|
|
55
58
|
exports.getDocPage = require_parser.getDocPage;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Annotations, ParseOptions, annotationKey, getAnnotations } from "./annotations.cjs";
|
|
1
2
|
import { NonEmptyString, ensureNonEmptyString, isNonEmptyString } from "./nonempty.cjs";
|
|
2
3
|
import { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, link, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.cjs";
|
|
3
4
|
import { OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, normalizeUsage } from "./usage.cjs";
|
|
@@ -10,4 +11,4 @@ import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOpti
|
|
|
10
11
|
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";
|
|
11
12
|
import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.cjs";
|
|
12
13
|
import { RunOptions, RunParserError, runParser, runParserAsync, runParserSync } from "./facade.cjs";
|
|
13
|
-
export { AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, ResolvedDependency, Result, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, link, locale, longestMatch, map, merge, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, pwsh, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
|
14
|
+
export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, ResolvedDependency, Result, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, annotationKey, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, link, locale, longestMatch, map, merge, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, pwsh, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Annotations, ParseOptions, annotationKey, getAnnotations } from "./annotations.js";
|
|
1
2
|
import { NonEmptyString, ensureNonEmptyString, isNonEmptyString } from "./nonempty.js";
|
|
2
3
|
import { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, link, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.js";
|
|
3
4
|
import { OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, normalizeUsage } from "./usage.js";
|
|
@@ -10,4 +11,4 @@ import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOpti
|
|
|
10
11
|
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";
|
|
11
12
|
import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.js";
|
|
12
13
|
import { RunOptions, RunParserError, runParser, runParserAsync, runParserSync } from "./facade.js";
|
|
13
|
-
export { AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, ResolvedDependency, Result, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, link, locale, longestMatch, map, merge, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, pwsh, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
|
14
|
+
export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, ResolvedDependency, Result, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, annotationKey, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, link, locale, longestMatch, map, merge, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, pwsh, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { annotationKey, getAnnotations } from "./annotations.js";
|
|
1
2
|
import { commandLine, envVar, formatMessage, link, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.js";
|
|
2
3
|
import { bash, fish, nu, pwsh, zsh } from "./completion.js";
|
|
3
4
|
import { DependencyRegistry, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, formatDependencyError, getDefaultValuesFunction, getDependencyIds, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource, parseWithDependency, pendingDependencySourceStateMarker, suggestWithDependency, transformsDependencyValue, transformsDependencyValueMarker, wrappedDependencySourceMarker } from "./dependency.js";
|
|
@@ -11,4 +12,4 @@ import { argument, command, constant, flag, option, passThrough } from "./primit
|
|
|
11
12
|
import { getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.js";
|
|
12
13
|
import { RunParserError, runParser, runParserAsync, runParserSync } from "./facade.js";
|
|
13
14
|
|
|
14
|
-
export { DependencyRegistry, DuplicateOptionError, RunParserError, WithDefaultError, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, link, locale, longestMatch, map, merge, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, pwsh, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
|
15
|
+
export { DependencyRegistry, DuplicateOptionError, RunParserError, WithDefaultError, annotationKey, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, link, locale, longestMatch, map, merge, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, pwsh, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
package/dist/parser.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const require_annotations = require('./annotations.cjs');
|
|
1
2
|
const require_message = require('./message.cjs');
|
|
2
3
|
const require_usage = require('./usage.cjs');
|
|
3
4
|
const require_constructs = require('./constructs.cjs');
|
|
@@ -18,18 +19,25 @@ const require_primitives = require('./primitives.cjs');
|
|
|
18
19
|
* arguments. Must be a synchronous parser.
|
|
19
20
|
* @param args The array of command-line arguments to parse. Usually this is
|
|
20
21
|
* `process.argv.slice(2)` in Node.js or `Deno.args` in Deno.
|
|
22
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
21
23
|
* @returns A {@link Result} object indicating whether the parsing was
|
|
22
24
|
* successful or not. If successful, it contains the parsed value of
|
|
23
25
|
* type `T`. If not, it contains an error message describing the
|
|
24
26
|
* failure.
|
|
25
27
|
* @since 0.9.0 Renamed from the original `parse` function which now delegates
|
|
26
28
|
* to this for sync parsers.
|
|
29
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
27
30
|
*/
|
|
28
|
-
function parseSync(parser, args) {
|
|
31
|
+
function parseSync(parser, args, options) {
|
|
32
|
+
let initialState = parser.initialState;
|
|
33
|
+
if (options?.annotations) initialState = {
|
|
34
|
+
...typeof initialState === "object" && initialState !== null ? initialState : {},
|
|
35
|
+
[require_annotations.annotationKey]: options.annotations
|
|
36
|
+
};
|
|
29
37
|
let context = {
|
|
30
38
|
buffer: args,
|
|
31
39
|
optionsTerminated: false,
|
|
32
|
-
state:
|
|
40
|
+
state: initialState,
|
|
33
41
|
usage: parser.usage
|
|
34
42
|
};
|
|
35
43
|
do {
|
|
@@ -67,15 +75,22 @@ function parseSync(parser, args) {
|
|
|
67
75
|
* arguments.
|
|
68
76
|
* @param args The array of command-line arguments to parse. Usually this is
|
|
69
77
|
* `process.argv.slice(2)` in Node.js or `Deno.args` in Deno.
|
|
78
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
70
79
|
* @returns A Promise that resolves to a {@link Result} object indicating
|
|
71
80
|
* whether the parsing was successful or not.
|
|
72
81
|
* @since 0.9.0
|
|
82
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
73
83
|
*/
|
|
74
|
-
async function parseAsync(parser, args) {
|
|
84
|
+
async function parseAsync(parser, args, options) {
|
|
85
|
+
let initialState = parser.initialState;
|
|
86
|
+
if (options?.annotations) initialState = {
|
|
87
|
+
...typeof initialState === "object" && initialState !== null ? initialState : {},
|
|
88
|
+
[require_annotations.annotationKey]: options.annotations
|
|
89
|
+
};
|
|
75
90
|
let context = {
|
|
76
91
|
buffer: args,
|
|
77
92
|
optionsTerminated: false,
|
|
78
|
-
state:
|
|
93
|
+
state: initialState,
|
|
79
94
|
usage: parser.usage
|
|
80
95
|
};
|
|
81
96
|
do {
|
|
@@ -117,12 +132,14 @@ async function parseAsync(parser, args) {
|
|
|
117
132
|
* arguments.
|
|
118
133
|
* @param args The array of command-line arguments to parse. Usually this is
|
|
119
134
|
* `process.argv.slice(2)` in Node.js or `Deno.args` in Deno.
|
|
135
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
120
136
|
* @returns A {@link Result} object (for sync) or Promise thereof (for async)
|
|
121
137
|
* indicating whether the parsing was successful or not.
|
|
138
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
122
139
|
*/
|
|
123
|
-
function parse(parser, args) {
|
|
124
|
-
if (parser.$mode === "async") return parseAsync(parser, args);
|
|
125
|
-
return parseSync(parser, args);
|
|
140
|
+
function parse(parser, args, options) {
|
|
141
|
+
if (parser.$mode === "async") return parseAsync(parser, args, options);
|
|
142
|
+
return parseSync(parser, args, options);
|
|
126
143
|
}
|
|
127
144
|
/**
|
|
128
145
|
* Generates command-line suggestions based on current parsing state.
|
|
@@ -138,6 +155,7 @@ function parse(parser, args) {
|
|
|
138
155
|
* @param args The array of command-line arguments including the partial
|
|
139
156
|
* argument to complete. The last element is treated as
|
|
140
157
|
* the prefix for suggestions.
|
|
158
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
141
159
|
* @returns An array of {@link Suggestion} objects containing completion
|
|
142
160
|
* candidates.
|
|
143
161
|
* @example
|
|
@@ -157,14 +175,20 @@ function parse(parser, args) {
|
|
|
157
175
|
* ```
|
|
158
176
|
* @since 0.6.0
|
|
159
177
|
* @since 0.9.0 Renamed from the original `suggest` function.
|
|
178
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
160
179
|
*/
|
|
161
|
-
function suggestSync(parser, args) {
|
|
180
|
+
function suggestSync(parser, args, options) {
|
|
162
181
|
const allButLast = args.slice(0, -1);
|
|
163
182
|
const prefix = args[args.length - 1];
|
|
183
|
+
let initialState = parser.initialState;
|
|
184
|
+
if (options?.annotations) initialState = {
|
|
185
|
+
...typeof initialState === "object" && initialState !== null ? initialState : {},
|
|
186
|
+
[require_annotations.annotationKey]: options.annotations
|
|
187
|
+
};
|
|
164
188
|
let context = {
|
|
165
189
|
buffer: allButLast,
|
|
166
190
|
optionsTerminated: false,
|
|
167
|
-
state:
|
|
191
|
+
state: initialState,
|
|
168
192
|
usage: parser.usage
|
|
169
193
|
};
|
|
170
194
|
while (context.buffer.length > 0) {
|
|
@@ -190,17 +214,24 @@ function suggestSync(parser, args) {
|
|
|
190
214
|
* @param args The array of command-line arguments including the partial
|
|
191
215
|
* argument to complete. The last element is treated as
|
|
192
216
|
* the prefix for suggestions.
|
|
217
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
193
218
|
* @returns A Promise that resolves to an array of {@link Suggestion} objects
|
|
194
219
|
* containing completion candidates.
|
|
195
220
|
* @since 0.9.0
|
|
221
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
196
222
|
*/
|
|
197
|
-
async function suggestAsync(parser, args) {
|
|
223
|
+
async function suggestAsync(parser, args, options) {
|
|
198
224
|
const allButLast = args.slice(0, -1);
|
|
199
225
|
const prefix = args[args.length - 1];
|
|
226
|
+
let initialState = parser.initialState;
|
|
227
|
+
if (options?.annotations) initialState = {
|
|
228
|
+
...typeof initialState === "object" && initialState !== null ? initialState : {},
|
|
229
|
+
[require_annotations.annotationKey]: options.annotations
|
|
230
|
+
};
|
|
200
231
|
let context = {
|
|
201
232
|
buffer: allButLast,
|
|
202
233
|
optionsTerminated: false,
|
|
203
|
-
state:
|
|
234
|
+
state: initialState,
|
|
204
235
|
usage: parser.usage
|
|
205
236
|
};
|
|
206
237
|
while (context.buffer.length > 0) {
|
|
@@ -235,13 +266,15 @@ async function suggestAsync(parser, args) {
|
|
|
235
266
|
* @param args The array of command-line arguments including the partial
|
|
236
267
|
* argument to complete. The last element is treated as
|
|
237
268
|
* the prefix for suggestions.
|
|
269
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
238
270
|
* @returns An array of {@link Suggestion} objects (for sync) or Promise thereof
|
|
239
271
|
* (for async) containing completion candidates.
|
|
240
272
|
* @since 0.6.0
|
|
273
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
241
274
|
*/
|
|
242
|
-
function suggest(parser, args) {
|
|
243
|
-
if (parser.$mode === "async") return suggestAsync(parser, args);
|
|
244
|
-
return suggestSync(parser, args);
|
|
275
|
+
function suggest(parser, args, options) {
|
|
276
|
+
if (parser.$mode === "async") return suggestAsync(parser, args, options);
|
|
277
|
+
return suggestSync(parser, args, options);
|
|
245
278
|
}
|
|
246
279
|
/**
|
|
247
280
|
* Recursively searches for a command within nested exclusive usage terms.
|
|
@@ -272,11 +305,13 @@ function findCommandInExclusive(term, commandName) {
|
|
|
272
305
|
*
|
|
273
306
|
* @param parser The sync parser to generate documentation for.
|
|
274
307
|
* @param args Optional array of command-line arguments for context.
|
|
308
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
275
309
|
* @returns A {@link DocPage} or `undefined`.
|
|
276
310
|
* @since 0.9.0
|
|
311
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
277
312
|
*/
|
|
278
|
-
function getDocPageSync(parser, args = []) {
|
|
279
|
-
return getDocPageSyncImpl(parser, args);
|
|
313
|
+
function getDocPageSync(parser, args = [], options) {
|
|
314
|
+
return getDocPageSyncImpl(parser, args, options);
|
|
280
315
|
}
|
|
281
316
|
/**
|
|
282
317
|
* Generates a documentation page for any parser, returning a Promise.
|
|
@@ -287,25 +322,32 @@ function getDocPageSync(parser, args = []) {
|
|
|
287
322
|
*
|
|
288
323
|
* @param parser The parser to generate documentation for.
|
|
289
324
|
* @param args Optional array of command-line arguments for context.
|
|
325
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
290
326
|
* @returns A Promise of {@link DocPage} or `undefined`.
|
|
291
327
|
* @since 0.9.0
|
|
328
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
292
329
|
*/
|
|
293
|
-
function getDocPageAsync(parser, args = []) {
|
|
294
|
-
if (parser.$mode === "sync") return Promise.resolve(getDocPageSyncImpl(parser, args));
|
|
295
|
-
return getDocPageAsyncImpl(parser, args);
|
|
330
|
+
function getDocPageAsync(parser, args = [], options) {
|
|
331
|
+
if (parser.$mode === "sync") return Promise.resolve(getDocPageSyncImpl(parser, args, options));
|
|
332
|
+
return getDocPageAsyncImpl(parser, args, options);
|
|
296
333
|
}
|
|
297
|
-
function getDocPage(parser, args = []) {
|
|
298
|
-
if (parser.$mode === "sync") return getDocPageSyncImpl(parser, args);
|
|
299
|
-
return getDocPageAsyncImpl(parser, args);
|
|
334
|
+
function getDocPage(parser, args = [], options) {
|
|
335
|
+
if (parser.$mode === "sync") return getDocPageSyncImpl(parser, args, options);
|
|
336
|
+
return getDocPageAsyncImpl(parser, args, options);
|
|
300
337
|
}
|
|
301
338
|
/**
|
|
302
339
|
* Internal sync implementation of getDocPage.
|
|
303
340
|
*/
|
|
304
|
-
function getDocPageSyncImpl(parser, args) {
|
|
341
|
+
function getDocPageSyncImpl(parser, args, options) {
|
|
342
|
+
let initialState = parser.initialState;
|
|
343
|
+
if (options?.annotations) initialState = {
|
|
344
|
+
...typeof initialState === "object" && initialState !== null ? initialState : {},
|
|
345
|
+
[require_annotations.annotationKey]: options.annotations
|
|
346
|
+
};
|
|
305
347
|
let context = {
|
|
306
348
|
buffer: args,
|
|
307
349
|
optionsTerminated: false,
|
|
308
|
-
state:
|
|
350
|
+
state: initialState,
|
|
309
351
|
usage: parser.usage
|
|
310
352
|
};
|
|
311
353
|
do {
|
|
@@ -318,11 +360,16 @@ function getDocPageSyncImpl(parser, args) {
|
|
|
318
360
|
/**
|
|
319
361
|
* Internal async implementation of getDocPage.
|
|
320
362
|
*/
|
|
321
|
-
async function getDocPageAsyncImpl(parser, args) {
|
|
363
|
+
async function getDocPageAsyncImpl(parser, args, options) {
|
|
364
|
+
let initialState = parser.initialState;
|
|
365
|
+
if (options?.annotations) initialState = {
|
|
366
|
+
...typeof initialState === "object" && initialState !== null ? initialState : {},
|
|
367
|
+
[require_annotations.annotationKey]: options.annotations
|
|
368
|
+
};
|
|
322
369
|
let context = {
|
|
323
370
|
buffer: args,
|
|
324
371
|
optionsTerminated: false,
|
|
325
|
-
state:
|
|
372
|
+
state: initialState,
|
|
326
373
|
usage: parser.usage
|
|
327
374
|
};
|
|
328
375
|
do {
|
package/dist/parser.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ParseOptions } from "./annotations.cjs";
|
|
1
2
|
import { Message } from "./message.cjs";
|
|
2
3
|
import { Usage } from "./usage.cjs";
|
|
3
4
|
import { DocFragments, DocPage } from "./doc.cjs";
|
|
@@ -325,14 +326,16 @@ type Result<T> = {
|
|
|
325
326
|
* arguments. Must be a synchronous parser.
|
|
326
327
|
* @param args The array of command-line arguments to parse. Usually this is
|
|
327
328
|
* `process.argv.slice(2)` in Node.js or `Deno.args` in Deno.
|
|
329
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
328
330
|
* @returns A {@link Result} object indicating whether the parsing was
|
|
329
331
|
* successful or not. If successful, it contains the parsed value of
|
|
330
332
|
* type `T`. If not, it contains an error message describing the
|
|
331
333
|
* failure.
|
|
332
334
|
* @since 0.9.0 Renamed from the original `parse` function which now delegates
|
|
333
335
|
* to this for sync parsers.
|
|
336
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
334
337
|
*/
|
|
335
|
-
declare function parseSync<T>(parser: Parser<"sync", T, unknown>, args: readonly string[]): Result<T>;
|
|
338
|
+
declare function parseSync<T>(parser: Parser<"sync", T, unknown>, args: readonly string[], options?: ParseOptions): Result<T>;
|
|
336
339
|
/**
|
|
337
340
|
* Parses an array of command-line arguments using the provided combined parser.
|
|
338
341
|
* This function processes the input arguments, applying the parser to each
|
|
@@ -346,11 +349,13 @@ declare function parseSync<T>(parser: Parser<"sync", T, unknown>, args: readonly
|
|
|
346
349
|
* arguments.
|
|
347
350
|
* @param args The array of command-line arguments to parse. Usually this is
|
|
348
351
|
* `process.argv.slice(2)` in Node.js or `Deno.args` in Deno.
|
|
352
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
349
353
|
* @returns A Promise that resolves to a {@link Result} object indicating
|
|
350
354
|
* whether the parsing was successful or not.
|
|
351
355
|
* @since 0.9.0
|
|
356
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
352
357
|
*/
|
|
353
|
-
declare function parseAsync<T>(parser: Parser<Mode, T, unknown>, args: readonly string[]): Promise<Result<T>>;
|
|
358
|
+
declare function parseAsync<T>(parser: Parser<Mode, T, unknown>, args: readonly string[], options?: ParseOptions): Promise<Result<T>>;
|
|
354
359
|
/**
|
|
355
360
|
* Parses an array of command-line arguments using the provided combined parser.
|
|
356
361
|
* This function processes the input arguments, applying the parser to each
|
|
@@ -368,10 +373,12 @@ declare function parseAsync<T>(parser: Parser<Mode, T, unknown>, args: readonly
|
|
|
368
373
|
* arguments.
|
|
369
374
|
* @param args The array of command-line arguments to parse. Usually this is
|
|
370
375
|
* `process.argv.slice(2)` in Node.js or `Deno.args` in Deno.
|
|
376
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
371
377
|
* @returns A {@link Result} object (for sync) or Promise thereof (for async)
|
|
372
378
|
* indicating whether the parsing was successful or not.
|
|
379
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
373
380
|
*/
|
|
374
|
-
declare function parse<M extends Mode, T>(parser: Parser<M, T, unknown>, args: readonly string[]): ModeValue<M, Result<T>>;
|
|
381
|
+
declare function parse<M extends Mode, T>(parser: Parser<M, T, unknown>, args: readonly string[], options?: ParseOptions): ModeValue<M, Result<T>>;
|
|
375
382
|
/**
|
|
376
383
|
* Generates command-line suggestions based on current parsing state.
|
|
377
384
|
* This function processes the input arguments up to the last argument,
|
|
@@ -386,6 +393,7 @@ declare function parse<M extends Mode, T>(parser: Parser<M, T, unknown>, args: r
|
|
|
386
393
|
* @param args The array of command-line arguments including the partial
|
|
387
394
|
* argument to complete. The last element is treated as
|
|
388
395
|
* the prefix for suggestions.
|
|
396
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
389
397
|
* @returns An array of {@link Suggestion} objects containing completion
|
|
390
398
|
* candidates.
|
|
391
399
|
* @example
|
|
@@ -405,8 +413,9 @@ declare function parse<M extends Mode, T>(parser: Parser<M, T, unknown>, args: r
|
|
|
405
413
|
* ```
|
|
406
414
|
* @since 0.6.0
|
|
407
415
|
* @since 0.9.0 Renamed from the original `suggest` function.
|
|
416
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
408
417
|
*/
|
|
409
|
-
declare function suggestSync<T>(parser: Parser<"sync", T, unknown>, args: readonly [string, ...readonly string[]]): readonly Suggestion[];
|
|
418
|
+
declare function suggestSync<T>(parser: Parser<"sync", T, unknown>, args: readonly [string, ...readonly string[]], options?: ParseOptions): readonly Suggestion[];
|
|
410
419
|
/**
|
|
411
420
|
* Generates command-line suggestions based on current parsing state.
|
|
412
421
|
* This function processes the input arguments up to the last argument,
|
|
@@ -421,11 +430,13 @@ declare function suggestSync<T>(parser: Parser<"sync", T, unknown>, args: readon
|
|
|
421
430
|
* @param args The array of command-line arguments including the partial
|
|
422
431
|
* argument to complete. The last element is treated as
|
|
423
432
|
* the prefix for suggestions.
|
|
433
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
424
434
|
* @returns A Promise that resolves to an array of {@link Suggestion} objects
|
|
425
435
|
* containing completion candidates.
|
|
426
436
|
* @since 0.9.0
|
|
437
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
427
438
|
*/
|
|
428
|
-
declare function suggestAsync<T>(parser: Parser<Mode, T, unknown>, args: readonly [string, ...readonly string[]]): Promise<readonly Suggestion[]>;
|
|
439
|
+
declare function suggestAsync<T>(parser: Parser<Mode, T, unknown>, args: readonly [string, ...readonly string[]], options?: ParseOptions): Promise<readonly Suggestion[]>;
|
|
429
440
|
/**
|
|
430
441
|
* Generates command-line suggestions based on current parsing state.
|
|
431
442
|
* This function processes the input arguments up to the last argument,
|
|
@@ -443,11 +454,13 @@ declare function suggestAsync<T>(parser: Parser<Mode, T, unknown>, args: readonl
|
|
|
443
454
|
* @param args The array of command-line arguments including the partial
|
|
444
455
|
* argument to complete. The last element is treated as
|
|
445
456
|
* the prefix for suggestions.
|
|
457
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
446
458
|
* @returns An array of {@link Suggestion} objects (for sync) or Promise thereof
|
|
447
459
|
* (for async) containing completion candidates.
|
|
448
460
|
* @since 0.6.0
|
|
461
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
449
462
|
*/
|
|
450
|
-
declare function suggest<M extends Mode, T>(parser: Parser<M, T, unknown>, args: readonly [string, ...readonly string[]]): ModeValue<M, readonly Suggestion[]>;
|
|
463
|
+
declare function suggest<M extends Mode, T>(parser: Parser<M, T, unknown>, args: readonly [string, ...readonly string[]], options?: ParseOptions): ModeValue<M, readonly Suggestion[]>;
|
|
451
464
|
/**
|
|
452
465
|
* Generates a documentation page for a synchronous parser.
|
|
453
466
|
*
|
|
@@ -457,10 +470,12 @@ declare function suggest<M extends Mode, T>(parser: Parser<M, T, unknown>, args:
|
|
|
457
470
|
*
|
|
458
471
|
* @param parser The sync parser to generate documentation for.
|
|
459
472
|
* @param args Optional array of command-line arguments for context.
|
|
473
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
460
474
|
* @returns A {@link DocPage} or `undefined`.
|
|
461
475
|
* @since 0.9.0
|
|
476
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
462
477
|
*/
|
|
463
|
-
declare function getDocPageSync(parser: Parser<"sync", unknown, unknown>, args?: readonly string[]): DocPage | undefined;
|
|
478
|
+
declare function getDocPageSync(parser: Parser<"sync", unknown, unknown>, args?: readonly string[], options?: ParseOptions): DocPage | undefined;
|
|
464
479
|
/**
|
|
465
480
|
* Generates a documentation page for any parser, returning a Promise.
|
|
466
481
|
*
|
|
@@ -470,10 +485,12 @@ declare function getDocPageSync(parser: Parser<"sync", unknown, unknown>, args?:
|
|
|
470
485
|
*
|
|
471
486
|
* @param parser The parser to generate documentation for.
|
|
472
487
|
* @param args Optional array of command-line arguments for context.
|
|
488
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
473
489
|
* @returns A Promise of {@link DocPage} or `undefined`.
|
|
474
490
|
* @since 0.9.0
|
|
491
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
475
492
|
*/
|
|
476
|
-
declare function getDocPageAsync(parser: Parser<Mode, unknown, unknown>, args?: readonly string[]): Promise<DocPage | undefined>;
|
|
493
|
+
declare function getDocPageAsync(parser: Parser<Mode, unknown, unknown>, args?: readonly string[], options?: ParseOptions): Promise<DocPage | undefined>;
|
|
477
494
|
/**
|
|
478
495
|
* Generates a documentation page for a parser based on its current state after
|
|
479
496
|
* attempting to parse the provided arguments. This function is useful for
|
|
@@ -492,6 +509,7 @@ declare function getDocPageAsync(parser: Parser<Mode, unknown, unknown>, args?:
|
|
|
492
509
|
* @param args Optional array of command-line arguments that have been parsed
|
|
493
510
|
* so far. Defaults to an empty array. This is used to determine
|
|
494
511
|
* the current parsing context and generate contextual documentation.
|
|
512
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
495
513
|
* @returns For sync parsers, returns a {@link DocPage} directly.
|
|
496
514
|
* For async parsers, returns a Promise of {@link DocPage}.
|
|
497
515
|
* Returns `undefined` if no documentation can be generated.
|
|
@@ -510,9 +528,10 @@ declare function getDocPageAsync(parser: Parser<Mode, unknown, unknown>, args?:
|
|
|
510
528
|
* const asyncDoc = await getDocPage(asyncParser);
|
|
511
529
|
* ```
|
|
512
530
|
* @since 0.9.0 Updated to support async parsers.
|
|
531
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
513
532
|
*/
|
|
514
|
-
declare function getDocPage(parser: Parser<"sync", unknown, unknown>, args?: readonly string[]): DocPage | undefined;
|
|
515
|
-
declare function getDocPage(parser: Parser<"async", unknown, unknown>, args?: readonly string[]): Promise<DocPage | undefined>;
|
|
516
|
-
declare function getDocPage<M extends Mode>(parser: Parser<M, unknown, unknown>, args?: readonly string[]): ModeValue<M, DocPage | undefined>;
|
|
533
|
+
declare function getDocPage(parser: Parser<"sync", unknown, unknown>, args?: readonly string[], options?: ParseOptions): DocPage | undefined;
|
|
534
|
+
declare function getDocPage(parser: Parser<"async", unknown, unknown>, args?: readonly string[], options?: ParseOptions): Promise<DocPage | undefined>;
|
|
535
|
+
declare function getDocPage<M extends Mode>(parser: Parser<M, unknown, unknown>, args?: readonly string[], options?: ParseOptions): ModeValue<M, DocPage | undefined>;
|
|
517
536
|
//#endregion
|
|
518
|
-
export { ArgumentErrorOptions, ArgumentOptions, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, InferMode, InferValue, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionOptions, OptionState, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, Suggestion, TupleOptions, WithDefaultError, WithDefaultOptions, argument, command, concat, conditional, constant, flag, getDocPage, getDocPageAsync, getDocPageSync, group, longestMatch, map, merge, multiple, nonEmpty, object, option, optional, or, parse, parseAsync, parseSync, passThrough, suggest, suggestAsync, suggestSync, tuple, withDefault };
|
|
537
|
+
export { ArgumentErrorOptions, ArgumentOptions, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, InferMode, InferValue, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionOptions, OptionState, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, Suggestion, TupleOptions, WithDefaultError, WithDefaultOptions, argument, command, concat, conditional, constant, flag, getDocPage, getDocPageAsync, getDocPageSync, group, longestMatch, map, merge, multiple, nonEmpty, object, option, optional, or, parse, parseAsync, parseSync, passThrough, suggest, suggestAsync, suggestSync, tuple, withDefault };
|
package/dist/parser.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ParseOptions } from "./annotations.js";
|
|
1
2
|
import { Message } from "./message.js";
|
|
2
3
|
import { Usage } from "./usage.js";
|
|
3
4
|
import { DocFragments, DocPage } from "./doc.js";
|
|
@@ -325,14 +326,16 @@ type Result<T> = {
|
|
|
325
326
|
* arguments. Must be a synchronous parser.
|
|
326
327
|
* @param args The array of command-line arguments to parse. Usually this is
|
|
327
328
|
* `process.argv.slice(2)` in Node.js or `Deno.args` in Deno.
|
|
329
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
328
330
|
* @returns A {@link Result} object indicating whether the parsing was
|
|
329
331
|
* successful or not. If successful, it contains the parsed value of
|
|
330
332
|
* type `T`. If not, it contains an error message describing the
|
|
331
333
|
* failure.
|
|
332
334
|
* @since 0.9.0 Renamed from the original `parse` function which now delegates
|
|
333
335
|
* to this for sync parsers.
|
|
336
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
334
337
|
*/
|
|
335
|
-
declare function parseSync<T>(parser: Parser<"sync", T, unknown>, args: readonly string[]): Result<T>;
|
|
338
|
+
declare function parseSync<T>(parser: Parser<"sync", T, unknown>, args: readonly string[], options?: ParseOptions): Result<T>;
|
|
336
339
|
/**
|
|
337
340
|
* Parses an array of command-line arguments using the provided combined parser.
|
|
338
341
|
* This function processes the input arguments, applying the parser to each
|
|
@@ -346,11 +349,13 @@ declare function parseSync<T>(parser: Parser<"sync", T, unknown>, args: readonly
|
|
|
346
349
|
* arguments.
|
|
347
350
|
* @param args The array of command-line arguments to parse. Usually this is
|
|
348
351
|
* `process.argv.slice(2)` in Node.js or `Deno.args` in Deno.
|
|
352
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
349
353
|
* @returns A Promise that resolves to a {@link Result} object indicating
|
|
350
354
|
* whether the parsing was successful or not.
|
|
351
355
|
* @since 0.9.0
|
|
356
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
352
357
|
*/
|
|
353
|
-
declare function parseAsync<T>(parser: Parser<Mode, T, unknown>, args: readonly string[]): Promise<Result<T>>;
|
|
358
|
+
declare function parseAsync<T>(parser: Parser<Mode, T, unknown>, args: readonly string[], options?: ParseOptions): Promise<Result<T>>;
|
|
354
359
|
/**
|
|
355
360
|
* Parses an array of command-line arguments using the provided combined parser.
|
|
356
361
|
* This function processes the input arguments, applying the parser to each
|
|
@@ -368,10 +373,12 @@ declare function parseAsync<T>(parser: Parser<Mode, T, unknown>, args: readonly
|
|
|
368
373
|
* arguments.
|
|
369
374
|
* @param args The array of command-line arguments to parse. Usually this is
|
|
370
375
|
* `process.argv.slice(2)` in Node.js or `Deno.args` in Deno.
|
|
376
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
371
377
|
* @returns A {@link Result} object (for sync) or Promise thereof (for async)
|
|
372
378
|
* indicating whether the parsing was successful or not.
|
|
379
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
373
380
|
*/
|
|
374
|
-
declare function parse<M extends Mode, T>(parser: Parser<M, T, unknown>, args: readonly string[]): ModeValue<M, Result<T>>;
|
|
381
|
+
declare function parse<M extends Mode, T>(parser: Parser<M, T, unknown>, args: readonly string[], options?: ParseOptions): ModeValue<M, Result<T>>;
|
|
375
382
|
/**
|
|
376
383
|
* Generates command-line suggestions based on current parsing state.
|
|
377
384
|
* This function processes the input arguments up to the last argument,
|
|
@@ -386,6 +393,7 @@ declare function parse<M extends Mode, T>(parser: Parser<M, T, unknown>, args: r
|
|
|
386
393
|
* @param args The array of command-line arguments including the partial
|
|
387
394
|
* argument to complete. The last element is treated as
|
|
388
395
|
* the prefix for suggestions.
|
|
396
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
389
397
|
* @returns An array of {@link Suggestion} objects containing completion
|
|
390
398
|
* candidates.
|
|
391
399
|
* @example
|
|
@@ -405,8 +413,9 @@ declare function parse<M extends Mode, T>(parser: Parser<M, T, unknown>, args: r
|
|
|
405
413
|
* ```
|
|
406
414
|
* @since 0.6.0
|
|
407
415
|
* @since 0.9.0 Renamed from the original `suggest` function.
|
|
416
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
408
417
|
*/
|
|
409
|
-
declare function suggestSync<T>(parser: Parser<"sync", T, unknown>, args: readonly [string, ...readonly string[]]): readonly Suggestion[];
|
|
418
|
+
declare function suggestSync<T>(parser: Parser<"sync", T, unknown>, args: readonly [string, ...readonly string[]], options?: ParseOptions): readonly Suggestion[];
|
|
410
419
|
/**
|
|
411
420
|
* Generates command-line suggestions based on current parsing state.
|
|
412
421
|
* This function processes the input arguments up to the last argument,
|
|
@@ -421,11 +430,13 @@ declare function suggestSync<T>(parser: Parser<"sync", T, unknown>, args: readon
|
|
|
421
430
|
* @param args The array of command-line arguments including the partial
|
|
422
431
|
* argument to complete. The last element is treated as
|
|
423
432
|
* the prefix for suggestions.
|
|
433
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
424
434
|
* @returns A Promise that resolves to an array of {@link Suggestion} objects
|
|
425
435
|
* containing completion candidates.
|
|
426
436
|
* @since 0.9.0
|
|
437
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
427
438
|
*/
|
|
428
|
-
declare function suggestAsync<T>(parser: Parser<Mode, T, unknown>, args: readonly [string, ...readonly string[]]): Promise<readonly Suggestion[]>;
|
|
439
|
+
declare function suggestAsync<T>(parser: Parser<Mode, T, unknown>, args: readonly [string, ...readonly string[]], options?: ParseOptions): Promise<readonly Suggestion[]>;
|
|
429
440
|
/**
|
|
430
441
|
* Generates command-line suggestions based on current parsing state.
|
|
431
442
|
* This function processes the input arguments up to the last argument,
|
|
@@ -443,11 +454,13 @@ declare function suggestAsync<T>(parser: Parser<Mode, T, unknown>, args: readonl
|
|
|
443
454
|
* @param args The array of command-line arguments including the partial
|
|
444
455
|
* argument to complete. The last element is treated as
|
|
445
456
|
* the prefix for suggestions.
|
|
457
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
446
458
|
* @returns An array of {@link Suggestion} objects (for sync) or Promise thereof
|
|
447
459
|
* (for async) containing completion candidates.
|
|
448
460
|
* @since 0.6.0
|
|
461
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
449
462
|
*/
|
|
450
|
-
declare function suggest<M extends Mode, T>(parser: Parser<M, T, unknown>, args: readonly [string, ...readonly string[]]): ModeValue<M, readonly Suggestion[]>;
|
|
463
|
+
declare function suggest<M extends Mode, T>(parser: Parser<M, T, unknown>, args: readonly [string, ...readonly string[]], options?: ParseOptions): ModeValue<M, readonly Suggestion[]>;
|
|
451
464
|
/**
|
|
452
465
|
* Generates a documentation page for a synchronous parser.
|
|
453
466
|
*
|
|
@@ -457,10 +470,12 @@ declare function suggest<M extends Mode, T>(parser: Parser<M, T, unknown>, args:
|
|
|
457
470
|
*
|
|
458
471
|
* @param parser The sync parser to generate documentation for.
|
|
459
472
|
* @param args Optional array of command-line arguments for context.
|
|
473
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
460
474
|
* @returns A {@link DocPage} or `undefined`.
|
|
461
475
|
* @since 0.9.0
|
|
476
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
462
477
|
*/
|
|
463
|
-
declare function getDocPageSync(parser: Parser<"sync", unknown, unknown>, args?: readonly string[]): DocPage | undefined;
|
|
478
|
+
declare function getDocPageSync(parser: Parser<"sync", unknown, unknown>, args?: readonly string[], options?: ParseOptions): DocPage | undefined;
|
|
464
479
|
/**
|
|
465
480
|
* Generates a documentation page for any parser, returning a Promise.
|
|
466
481
|
*
|
|
@@ -470,10 +485,12 @@ declare function getDocPageSync(parser: Parser<"sync", unknown, unknown>, args?:
|
|
|
470
485
|
*
|
|
471
486
|
* @param parser The parser to generate documentation for.
|
|
472
487
|
* @param args Optional array of command-line arguments for context.
|
|
488
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
473
489
|
* @returns A Promise of {@link DocPage} or `undefined`.
|
|
474
490
|
* @since 0.9.0
|
|
491
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
475
492
|
*/
|
|
476
|
-
declare function getDocPageAsync(parser: Parser<Mode, unknown, unknown>, args?: readonly string[]): Promise<DocPage | undefined>;
|
|
493
|
+
declare function getDocPageAsync(parser: Parser<Mode, unknown, unknown>, args?: readonly string[], options?: ParseOptions): Promise<DocPage | undefined>;
|
|
477
494
|
/**
|
|
478
495
|
* Generates a documentation page for a parser based on its current state after
|
|
479
496
|
* attempting to parse the provided arguments. This function is useful for
|
|
@@ -492,6 +509,7 @@ declare function getDocPageAsync(parser: Parser<Mode, unknown, unknown>, args?:
|
|
|
492
509
|
* @param args Optional array of command-line arguments that have been parsed
|
|
493
510
|
* so far. Defaults to an empty array. This is used to determine
|
|
494
511
|
* the current parsing context and generate contextual documentation.
|
|
512
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
495
513
|
* @returns For sync parsers, returns a {@link DocPage} directly.
|
|
496
514
|
* For async parsers, returns a Promise of {@link DocPage}.
|
|
497
515
|
* Returns `undefined` if no documentation can be generated.
|
|
@@ -510,9 +528,10 @@ declare function getDocPageAsync(parser: Parser<Mode, unknown, unknown>, args?:
|
|
|
510
528
|
* const asyncDoc = await getDocPage(asyncParser);
|
|
511
529
|
* ```
|
|
512
530
|
* @since 0.9.0 Updated to support async parsers.
|
|
531
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
513
532
|
*/
|
|
514
|
-
declare function getDocPage(parser: Parser<"sync", unknown, unknown>, args?: readonly string[]): DocPage | undefined;
|
|
515
|
-
declare function getDocPage(parser: Parser<"async", unknown, unknown>, args?: readonly string[]): Promise<DocPage | undefined>;
|
|
516
|
-
declare function getDocPage<M extends Mode>(parser: Parser<M, unknown, unknown>, args?: readonly string[]): ModeValue<M, DocPage | undefined>;
|
|
533
|
+
declare function getDocPage(parser: Parser<"sync", unknown, unknown>, args?: readonly string[], options?: ParseOptions): DocPage | undefined;
|
|
534
|
+
declare function getDocPage(parser: Parser<"async", unknown, unknown>, args?: readonly string[], options?: ParseOptions): Promise<DocPage | undefined>;
|
|
535
|
+
declare function getDocPage<M extends Mode>(parser: Parser<M, unknown, unknown>, args?: readonly string[], options?: ParseOptions): ModeValue<M, DocPage | undefined>;
|
|
517
536
|
//#endregion
|
|
518
|
-
export { ArgumentErrorOptions, ArgumentOptions, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, InferMode, InferValue, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionOptions, OptionState, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, Suggestion, TupleOptions, WithDefaultError, WithDefaultOptions, argument, command, concat, conditional, constant, flag, getDocPage, getDocPageAsync, getDocPageSync, group, longestMatch, map, merge, multiple, nonEmpty, object, option, optional, or, parse, parseAsync, parseSync, passThrough, suggest, suggestAsync, suggestSync, tuple, withDefault };
|
|
537
|
+
export { ArgumentErrorOptions, ArgumentOptions, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, InferMode, InferValue, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionOptions, OptionState, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, Suggestion, TupleOptions, WithDefaultError, WithDefaultOptions, argument, command, concat, conditional, constant, flag, getDocPage, getDocPageAsync, getDocPageSync, group, longestMatch, map, merge, multiple, nonEmpty, object, option, optional, or, parse, parseAsync, parseSync, passThrough, suggest, suggestAsync, suggestSync, tuple, withDefault };
|
package/dist/parser.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { annotationKey } from "./annotations.js";
|
|
1
2
|
import { message } from "./message.js";
|
|
2
3
|
import { normalizeUsage } from "./usage.js";
|
|
3
4
|
import { DuplicateOptionError, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
|
|
@@ -18,18 +19,25 @@ import { argument, command, constant, flag, option, passThrough } from "./primit
|
|
|
18
19
|
* arguments. Must be a synchronous parser.
|
|
19
20
|
* @param args The array of command-line arguments to parse. Usually this is
|
|
20
21
|
* `process.argv.slice(2)` in Node.js or `Deno.args` in Deno.
|
|
22
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
21
23
|
* @returns A {@link Result} object indicating whether the parsing was
|
|
22
24
|
* successful or not. If successful, it contains the parsed value of
|
|
23
25
|
* type `T`. If not, it contains an error message describing the
|
|
24
26
|
* failure.
|
|
25
27
|
* @since 0.9.0 Renamed from the original `parse` function which now delegates
|
|
26
28
|
* to this for sync parsers.
|
|
29
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
27
30
|
*/
|
|
28
|
-
function parseSync(parser, args) {
|
|
31
|
+
function parseSync(parser, args, options) {
|
|
32
|
+
let initialState = parser.initialState;
|
|
33
|
+
if (options?.annotations) initialState = {
|
|
34
|
+
...typeof initialState === "object" && initialState !== null ? initialState : {},
|
|
35
|
+
[annotationKey]: options.annotations
|
|
36
|
+
};
|
|
29
37
|
let context = {
|
|
30
38
|
buffer: args,
|
|
31
39
|
optionsTerminated: false,
|
|
32
|
-
state:
|
|
40
|
+
state: initialState,
|
|
33
41
|
usage: parser.usage
|
|
34
42
|
};
|
|
35
43
|
do {
|
|
@@ -67,15 +75,22 @@ function parseSync(parser, args) {
|
|
|
67
75
|
* arguments.
|
|
68
76
|
* @param args The array of command-line arguments to parse. Usually this is
|
|
69
77
|
* `process.argv.slice(2)` in Node.js or `Deno.args` in Deno.
|
|
78
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
70
79
|
* @returns A Promise that resolves to a {@link Result} object indicating
|
|
71
80
|
* whether the parsing was successful or not.
|
|
72
81
|
* @since 0.9.0
|
|
82
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
73
83
|
*/
|
|
74
|
-
async function parseAsync(parser, args) {
|
|
84
|
+
async function parseAsync(parser, args, options) {
|
|
85
|
+
let initialState = parser.initialState;
|
|
86
|
+
if (options?.annotations) initialState = {
|
|
87
|
+
...typeof initialState === "object" && initialState !== null ? initialState : {},
|
|
88
|
+
[annotationKey]: options.annotations
|
|
89
|
+
};
|
|
75
90
|
let context = {
|
|
76
91
|
buffer: args,
|
|
77
92
|
optionsTerminated: false,
|
|
78
|
-
state:
|
|
93
|
+
state: initialState,
|
|
79
94
|
usage: parser.usage
|
|
80
95
|
};
|
|
81
96
|
do {
|
|
@@ -117,12 +132,14 @@ async function parseAsync(parser, args) {
|
|
|
117
132
|
* arguments.
|
|
118
133
|
* @param args The array of command-line arguments to parse. Usually this is
|
|
119
134
|
* `process.argv.slice(2)` in Node.js or `Deno.args` in Deno.
|
|
135
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
120
136
|
* @returns A {@link Result} object (for sync) or Promise thereof (for async)
|
|
121
137
|
* indicating whether the parsing was successful or not.
|
|
138
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
122
139
|
*/
|
|
123
|
-
function parse(parser, args) {
|
|
124
|
-
if (parser.$mode === "async") return parseAsync(parser, args);
|
|
125
|
-
return parseSync(parser, args);
|
|
140
|
+
function parse(parser, args, options) {
|
|
141
|
+
if (parser.$mode === "async") return parseAsync(parser, args, options);
|
|
142
|
+
return parseSync(parser, args, options);
|
|
126
143
|
}
|
|
127
144
|
/**
|
|
128
145
|
* Generates command-line suggestions based on current parsing state.
|
|
@@ -138,6 +155,7 @@ function parse(parser, args) {
|
|
|
138
155
|
* @param args The array of command-line arguments including the partial
|
|
139
156
|
* argument to complete. The last element is treated as
|
|
140
157
|
* the prefix for suggestions.
|
|
158
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
141
159
|
* @returns An array of {@link Suggestion} objects containing completion
|
|
142
160
|
* candidates.
|
|
143
161
|
* @example
|
|
@@ -157,14 +175,20 @@ function parse(parser, args) {
|
|
|
157
175
|
* ```
|
|
158
176
|
* @since 0.6.0
|
|
159
177
|
* @since 0.9.0 Renamed from the original `suggest` function.
|
|
178
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
160
179
|
*/
|
|
161
|
-
function suggestSync(parser, args) {
|
|
180
|
+
function suggestSync(parser, args, options) {
|
|
162
181
|
const allButLast = args.slice(0, -1);
|
|
163
182
|
const prefix = args[args.length - 1];
|
|
183
|
+
let initialState = parser.initialState;
|
|
184
|
+
if (options?.annotations) initialState = {
|
|
185
|
+
...typeof initialState === "object" && initialState !== null ? initialState : {},
|
|
186
|
+
[annotationKey]: options.annotations
|
|
187
|
+
};
|
|
164
188
|
let context = {
|
|
165
189
|
buffer: allButLast,
|
|
166
190
|
optionsTerminated: false,
|
|
167
|
-
state:
|
|
191
|
+
state: initialState,
|
|
168
192
|
usage: parser.usage
|
|
169
193
|
};
|
|
170
194
|
while (context.buffer.length > 0) {
|
|
@@ -190,17 +214,24 @@ function suggestSync(parser, args) {
|
|
|
190
214
|
* @param args The array of command-line arguments including the partial
|
|
191
215
|
* argument to complete. The last element is treated as
|
|
192
216
|
* the prefix for suggestions.
|
|
217
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
193
218
|
* @returns A Promise that resolves to an array of {@link Suggestion} objects
|
|
194
219
|
* containing completion candidates.
|
|
195
220
|
* @since 0.9.0
|
|
221
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
196
222
|
*/
|
|
197
|
-
async function suggestAsync(parser, args) {
|
|
223
|
+
async function suggestAsync(parser, args, options) {
|
|
198
224
|
const allButLast = args.slice(0, -1);
|
|
199
225
|
const prefix = args[args.length - 1];
|
|
226
|
+
let initialState = parser.initialState;
|
|
227
|
+
if (options?.annotations) initialState = {
|
|
228
|
+
...typeof initialState === "object" && initialState !== null ? initialState : {},
|
|
229
|
+
[annotationKey]: options.annotations
|
|
230
|
+
};
|
|
200
231
|
let context = {
|
|
201
232
|
buffer: allButLast,
|
|
202
233
|
optionsTerminated: false,
|
|
203
|
-
state:
|
|
234
|
+
state: initialState,
|
|
204
235
|
usage: parser.usage
|
|
205
236
|
};
|
|
206
237
|
while (context.buffer.length > 0) {
|
|
@@ -235,13 +266,15 @@ async function suggestAsync(parser, args) {
|
|
|
235
266
|
* @param args The array of command-line arguments including the partial
|
|
236
267
|
* argument to complete. The last element is treated as
|
|
237
268
|
* the prefix for suggestions.
|
|
269
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
238
270
|
* @returns An array of {@link Suggestion} objects (for sync) or Promise thereof
|
|
239
271
|
* (for async) containing completion candidates.
|
|
240
272
|
* @since 0.6.0
|
|
273
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
241
274
|
*/
|
|
242
|
-
function suggest(parser, args) {
|
|
243
|
-
if (parser.$mode === "async") return suggestAsync(parser, args);
|
|
244
|
-
return suggestSync(parser, args);
|
|
275
|
+
function suggest(parser, args, options) {
|
|
276
|
+
if (parser.$mode === "async") return suggestAsync(parser, args, options);
|
|
277
|
+
return suggestSync(parser, args, options);
|
|
245
278
|
}
|
|
246
279
|
/**
|
|
247
280
|
* Recursively searches for a command within nested exclusive usage terms.
|
|
@@ -272,11 +305,13 @@ function findCommandInExclusive(term, commandName) {
|
|
|
272
305
|
*
|
|
273
306
|
* @param parser The sync parser to generate documentation for.
|
|
274
307
|
* @param args Optional array of command-line arguments for context.
|
|
308
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
275
309
|
* @returns A {@link DocPage} or `undefined`.
|
|
276
310
|
* @since 0.9.0
|
|
311
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
277
312
|
*/
|
|
278
|
-
function getDocPageSync(parser, args = []) {
|
|
279
|
-
return getDocPageSyncImpl(parser, args);
|
|
313
|
+
function getDocPageSync(parser, args = [], options) {
|
|
314
|
+
return getDocPageSyncImpl(parser, args, options);
|
|
280
315
|
}
|
|
281
316
|
/**
|
|
282
317
|
* Generates a documentation page for any parser, returning a Promise.
|
|
@@ -287,25 +322,32 @@ function getDocPageSync(parser, args = []) {
|
|
|
287
322
|
*
|
|
288
323
|
* @param parser The parser to generate documentation for.
|
|
289
324
|
* @param args Optional array of command-line arguments for context.
|
|
325
|
+
* @param options Optional {@link ParseOptions} for customizing parsing behavior.
|
|
290
326
|
* @returns A Promise of {@link DocPage} or `undefined`.
|
|
291
327
|
* @since 0.9.0
|
|
328
|
+
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
292
329
|
*/
|
|
293
|
-
function getDocPageAsync(parser, args = []) {
|
|
294
|
-
if (parser.$mode === "sync") return Promise.resolve(getDocPageSyncImpl(parser, args));
|
|
295
|
-
return getDocPageAsyncImpl(parser, args);
|
|
330
|
+
function getDocPageAsync(parser, args = [], options) {
|
|
331
|
+
if (parser.$mode === "sync") return Promise.resolve(getDocPageSyncImpl(parser, args, options));
|
|
332
|
+
return getDocPageAsyncImpl(parser, args, options);
|
|
296
333
|
}
|
|
297
|
-
function getDocPage(parser, args = []) {
|
|
298
|
-
if (parser.$mode === "sync") return getDocPageSyncImpl(parser, args);
|
|
299
|
-
return getDocPageAsyncImpl(parser, args);
|
|
334
|
+
function getDocPage(parser, args = [], options) {
|
|
335
|
+
if (parser.$mode === "sync") return getDocPageSyncImpl(parser, args, options);
|
|
336
|
+
return getDocPageAsyncImpl(parser, args, options);
|
|
300
337
|
}
|
|
301
338
|
/**
|
|
302
339
|
* Internal sync implementation of getDocPage.
|
|
303
340
|
*/
|
|
304
|
-
function getDocPageSyncImpl(parser, args) {
|
|
341
|
+
function getDocPageSyncImpl(parser, args, options) {
|
|
342
|
+
let initialState = parser.initialState;
|
|
343
|
+
if (options?.annotations) initialState = {
|
|
344
|
+
...typeof initialState === "object" && initialState !== null ? initialState : {},
|
|
345
|
+
[annotationKey]: options.annotations
|
|
346
|
+
};
|
|
305
347
|
let context = {
|
|
306
348
|
buffer: args,
|
|
307
349
|
optionsTerminated: false,
|
|
308
|
-
state:
|
|
350
|
+
state: initialState,
|
|
309
351
|
usage: parser.usage
|
|
310
352
|
};
|
|
311
353
|
do {
|
|
@@ -318,11 +360,16 @@ function getDocPageSyncImpl(parser, args) {
|
|
|
318
360
|
/**
|
|
319
361
|
* Internal async implementation of getDocPage.
|
|
320
362
|
*/
|
|
321
|
-
async function getDocPageAsyncImpl(parser, args) {
|
|
363
|
+
async function getDocPageAsyncImpl(parser, args, options) {
|
|
364
|
+
let initialState = parser.initialState;
|
|
365
|
+
if (options?.annotations) initialState = {
|
|
366
|
+
...typeof initialState === "object" && initialState !== null ? initialState : {},
|
|
367
|
+
[annotationKey]: options.annotations
|
|
368
|
+
};
|
|
322
369
|
let context = {
|
|
323
370
|
buffer: args,
|
|
324
371
|
optionsTerminated: false,
|
|
325
|
-
state:
|
|
372
|
+
state: initialState,
|
|
326
373
|
usage: parser.usage
|
|
327
374
|
};
|
|
328
375
|
do {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/core",
|
|
3
|
-
"version": "0.10.0-dev.
|
|
3
|
+
"version": "0.10.0-dev.331+425449c7",
|
|
4
4
|
"description": "Type-safe combinatorial command-line interface parser",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -51,6 +51,14 @@
|
|
|
51
51
|
"import": "./dist/index.js",
|
|
52
52
|
"require": "./dist/index.cjs"
|
|
53
53
|
},
|
|
54
|
+
"./annotations": {
|
|
55
|
+
"types": {
|
|
56
|
+
"import": "./dist/annotations.d.ts",
|
|
57
|
+
"require": "./dist/annotations.d.cts"
|
|
58
|
+
},
|
|
59
|
+
"import": "./dist/annotations.js",
|
|
60
|
+
"require": "./dist/annotations.cjs"
|
|
61
|
+
},
|
|
54
62
|
"./completion": {
|
|
55
63
|
"types": {
|
|
56
64
|
"import": "./dist/completion.d.ts",
|