@optique/core 1.0.0-dev.1901 → 1.0.0-dev.1970
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/annotation-state.cjs +115 -60
- package/dist/annotation-state.d.cts +24 -0
- package/dist/annotation-state.d.ts +24 -0
- package/dist/annotation-state.js +114 -60
- package/dist/annotations.cjs +2 -267
- package/dist/annotations.d.cts +2 -152
- package/dist/annotations.d.ts +2 -152
- package/dist/annotations.js +2 -256
- package/dist/completion.d.cts +1 -1
- package/dist/completion.d.ts +1 -1
- package/dist/constructs.cjs +206 -238
- package/dist/constructs.d.cts +1 -1
- package/dist/constructs.d.ts +1 -1
- package/dist/constructs.js +96 -128
- package/dist/context.d.cts +1 -1
- package/dist/context.d.ts +1 -1
- package/dist/dependency-metadata.cjs +1 -1
- package/dist/dependency-metadata.d.cts +1 -1
- package/dist/dependency-metadata.d.ts +1 -1
- package/dist/dependency-metadata.js +1 -1
- package/dist/dependency-runtime.cjs +2 -2
- package/dist/dependency-runtime.js +2 -2
- package/dist/dependency.cjs +7 -1111
- package/dist/dependency.d.cts +2 -838
- package/dist/dependency.d.ts +2 -838
- package/dist/dependency.js +2 -1078
- package/dist/execution-context.cjs +56 -0
- package/dist/execution-context.js +53 -0
- package/dist/extension.cjs +87 -0
- package/dist/extension.d.cts +97 -0
- package/dist/extension.d.ts +97 -0
- package/dist/extension.js +76 -0
- package/dist/facade.cjs +19 -19
- package/dist/facade.d.cts +1 -1
- package/dist/facade.d.ts +1 -1
- package/dist/facade.js +19 -19
- package/dist/index.cjs +4 -41
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +5 -5
- package/dist/internal/annotations.cjs +316 -0
- package/dist/internal/annotations.d.cts +140 -0
- package/dist/internal/annotations.d.ts +140 -0
- package/dist/internal/annotations.js +306 -0
- package/dist/internal/dependency.cjs +984 -0
- package/dist/internal/dependency.d.cts +539 -0
- package/dist/internal/dependency.d.ts +539 -0
- package/dist/internal/dependency.js +964 -0
- package/dist/{mode-dispatch.cjs → internal/mode-dispatch.cjs} +1 -3
- package/dist/{mode-dispatch.d.cts → internal/mode-dispatch.d.cts} +3 -7
- package/dist/{mode-dispatch.d.ts → internal/mode-dispatch.d.ts} +3 -7
- package/dist/{mode-dispatch.js → internal/mode-dispatch.js} +1 -3
- package/dist/internal/parser.cjs +728 -0
- package/dist/internal/parser.d.cts +947 -0
- package/dist/internal/parser.d.ts +947 -0
- package/dist/internal/parser.js +711 -0
- package/dist/modifiers.cjs +108 -125
- package/dist/modifiers.d.cts +1 -1
- package/dist/modifiers.d.ts +1 -1
- package/dist/modifiers.js +92 -109
- package/dist/parser.cjs +11 -743
- package/dist/parser.d.cts +3 -991
- package/dist/parser.d.ts +3 -991
- package/dist/parser.js +2 -704
- package/dist/phase2-seed.cjs +4 -4
- package/dist/phase2-seed.js +4 -4
- package/dist/primitives.cjs +39 -74
- package/dist/primitives.d.cts +1 -1
- package/dist/primitives.d.ts +1 -1
- package/dist/primitives.js +26 -61
- package/dist/program.d.cts +1 -1
- package/dist/program.d.ts +1 -1
- package/dist/valueparser.cjs +23 -23
- package/dist/valueparser.d.cts +3 -3
- package/dist/valueparser.d.ts +3 -3
- package/dist/valueparser.js +23 -23
- package/package.json +9 -9
package/dist/phase2-seed.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_annotations = require('./annotations.cjs');
|
|
2
|
-
const require_mode_dispatch = require('./mode-dispatch.cjs');
|
|
1
|
+
const require_annotations = require('./internal/annotations.cjs');
|
|
2
|
+
const require_mode_dispatch = require('./internal/mode-dispatch.cjs');
|
|
3
3
|
|
|
4
4
|
//#region src/phase2-seed.ts
|
|
5
5
|
/**
|
|
@@ -26,7 +26,7 @@ function phase2SeedFromValueResult(result) {
|
|
|
26
26
|
* @internal
|
|
27
27
|
*/
|
|
28
28
|
function extractPhase2Seed(parser, state, exec) {
|
|
29
|
-
return require_mode_dispatch.dispatchByMode(parser
|
|
29
|
+
return require_mode_dispatch.dispatchByMode(parser.mode, () => {
|
|
30
30
|
const extractor = parser[extractPhase2SeedKey];
|
|
31
31
|
return extractor == null ? null : extractor(state, exec);
|
|
32
32
|
}, async () => {
|
|
@@ -41,7 +41,7 @@ function extractPhase2Seed(parser, state, exec) {
|
|
|
41
41
|
* @internal
|
|
42
42
|
*/
|
|
43
43
|
function completeOrExtractPhase2Seed(parser, state, exec) {
|
|
44
|
-
return require_mode_dispatch.dispatchByMode(parser
|
|
44
|
+
return require_mode_dispatch.dispatchByMode(parser.mode, () => {
|
|
45
45
|
const result = parser.complete(state, exec);
|
|
46
46
|
if (result.success) return phase2SeedFromValueResult(result);
|
|
47
47
|
return extractPhase2Seed(parser, state, exec);
|
package/dist/phase2-seed.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { unwrapInjectedAnnotationWrapper } from "./annotations.js";
|
|
2
|
-
import { dispatchByMode } from "./mode-dispatch.js";
|
|
1
|
+
import { unwrapInjectedAnnotationWrapper } from "./internal/annotations.js";
|
|
2
|
+
import { dispatchByMode } from "./internal/mode-dispatch.js";
|
|
3
3
|
|
|
4
4
|
//#region src/phase2-seed.ts
|
|
5
5
|
/**
|
|
@@ -26,7 +26,7 @@ function phase2SeedFromValueResult(result) {
|
|
|
26
26
|
* @internal
|
|
27
27
|
*/
|
|
28
28
|
function extractPhase2Seed(parser, state, exec) {
|
|
29
|
-
return dispatchByMode(parser
|
|
29
|
+
return dispatchByMode(parser.mode, () => {
|
|
30
30
|
const extractor = parser[extractPhase2SeedKey];
|
|
31
31
|
return extractor == null ? null : extractor(state, exec);
|
|
32
32
|
}, async () => {
|
|
@@ -41,7 +41,7 @@ function extractPhase2Seed(parser, state, exec) {
|
|
|
41
41
|
* @internal
|
|
42
42
|
*/
|
|
43
43
|
function completeOrExtractPhase2Seed(parser, state, exec) {
|
|
44
|
-
return dispatchByMode(parser
|
|
44
|
+
return dispatchByMode(parser.mode, () => {
|
|
45
45
|
const result = parser.complete(state, exec);
|
|
46
46
|
if (result.success) return phase2SeedFromValueResult(result);
|
|
47
47
|
return extractPhase2Seed(parser, state, exec);
|
package/dist/primitives.cjs
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
const require_annotations = require('./annotations.cjs');
|
|
1
|
+
const require_annotations = require('./internal/annotations.cjs');
|
|
2
2
|
const require_message = require('./message.cjs');
|
|
3
3
|
const require_validate = require('./validate.cjs');
|
|
4
4
|
const require_usage = require('./usage.cjs');
|
|
5
|
-
const require_mode_dispatch = require('./mode-dispatch.cjs');
|
|
6
|
-
const require_dependency = require('./dependency.cjs');
|
|
5
|
+
const require_mode_dispatch = require('./internal/mode-dispatch.cjs');
|
|
6
|
+
const require_dependency = require('./internal/dependency.cjs');
|
|
7
7
|
const require_dependency_runtime = require('./dependency-runtime.cjs');
|
|
8
|
-
const
|
|
8
|
+
const require_annotation_state = require('./annotation-state.cjs');
|
|
9
|
+
const require_execution_context = require('./execution-context.cjs');
|
|
9
10
|
const require_phase2_seed = require('./phase2-seed.cjs');
|
|
10
11
|
const require_suggestion = require('./suggestion.cjs');
|
|
11
12
|
const require_usage_internals = require('./usage-internals.cjs');
|
|
13
|
+
const require_dependency_metadata = require('./dependency-metadata.cjs');
|
|
12
14
|
const require_valueparser = require('./valueparser.cjs');
|
|
13
|
-
const require_annotation_state = require('./annotation-state.cjs');
|
|
14
15
|
|
|
15
16
|
//#region src/primitives.ts
|
|
16
17
|
/**
|
|
@@ -18,42 +19,6 @@ const require_annotation_state = require('./annotation-state.cjs');
|
|
|
18
19
|
* do not match any specific name at the first buffer position.
|
|
19
20
|
*/
|
|
20
21
|
const EMPTY_LEADING_NAMES = /* @__PURE__ */ new Set();
|
|
21
|
-
function withChildExecPath(exec, segment) {
|
|
22
|
-
if (exec == null) return void 0;
|
|
23
|
-
return {
|
|
24
|
-
...exec,
|
|
25
|
-
path: [...exec.path ?? [], segment]
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
function mergeChildExec(parent, child) {
|
|
29
|
-
if (parent == null) return child;
|
|
30
|
-
if (child == null) return parent;
|
|
31
|
-
return {
|
|
32
|
-
...parent,
|
|
33
|
-
trace: child.trace ?? parent.trace,
|
|
34
|
-
dependencyRuntime: child.dependencyRuntime ?? parent.dependencyRuntime,
|
|
35
|
-
dependencyRegistry: child.dependencyRegistry ?? parent.dependencyRegistry,
|
|
36
|
-
commandPath: child.commandPath ?? parent.commandPath,
|
|
37
|
-
preCompletedByParser: child.preCompletedByParser ?? parent.preCompletedByParser,
|
|
38
|
-
excludedSourceFields: child.excludedSourceFields ?? parent.excludedSourceFields
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
function withChildContext(context, segment, state, usage) {
|
|
42
|
-
const exec = withChildExecPath(context.exec, segment);
|
|
43
|
-
const dependencyRegistry = context.dependencyRegistry ?? exec?.dependencyRegistry;
|
|
44
|
-
return {
|
|
45
|
-
...context,
|
|
46
|
-
state,
|
|
47
|
-
...usage != null ? { usage } : {},
|
|
48
|
-
...exec != null ? {
|
|
49
|
-
exec: dependencyRegistry === exec.dependencyRegistry ? exec : {
|
|
50
|
-
...exec,
|
|
51
|
-
dependencyRegistry
|
|
52
|
-
},
|
|
53
|
-
dependencyRegistry
|
|
54
|
-
} : {}
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
22
|
function hasParsedOptionValue(state, valueParser) {
|
|
58
23
|
if (valueParser != null) return state != null && typeof state === "object" && "success" in state && typeof state.success === "boolean";
|
|
59
24
|
return state != null && "success" in state && state.success && state.value === true;
|
|
@@ -146,7 +111,7 @@ function constant(value) {
|
|
|
146
111
|
const result = {
|
|
147
112
|
$valueType: [],
|
|
148
113
|
$stateType: [],
|
|
149
|
-
|
|
114
|
+
mode: "sync",
|
|
150
115
|
priority: 0,
|
|
151
116
|
usage: [],
|
|
152
117
|
leadingNames: EMPTY_LEADING_NAMES,
|
|
@@ -203,7 +168,7 @@ function fail() {
|
|
|
203
168
|
return {
|
|
204
169
|
$valueType: [],
|
|
205
170
|
$stateType: [],
|
|
206
|
-
|
|
171
|
+
mode: "sync",
|
|
207
172
|
priority: 0,
|
|
208
173
|
usage: [],
|
|
209
174
|
leadingNames: EMPTY_LEADING_NAMES,
|
|
@@ -437,13 +402,13 @@ function option(...args) {
|
|
|
437
402
|
valueParser = void 0;
|
|
438
403
|
}
|
|
439
404
|
require_validate.validateOptionNames(optionNames$1, "Option");
|
|
440
|
-
const mode = valueParser
|
|
405
|
+
const mode = valueParser?.mode ?? "sync";
|
|
441
406
|
const isAsync = mode === "async";
|
|
442
407
|
const syncValueParser = valueParser;
|
|
443
408
|
const dependencyMetadata = valueParser != null ? require_dependency_metadata.extractDependencyMetadata(valueParser) : void 0;
|
|
444
409
|
const formatInvalidValueError = (error) => options.errors?.invalidValue ? typeof options.errors.invalidValue === "function" ? options.errors.invalidValue(error) : options.errors.invalidValue : require_message.message`${require_message.optionNames(optionNames$1)}: ${error}`;
|
|
445
410
|
const result = {
|
|
446
|
-
|
|
411
|
+
mode,
|
|
447
412
|
$valueType: [],
|
|
448
413
|
$stateType: [],
|
|
449
414
|
priority: 10,
|
|
@@ -807,7 +772,7 @@ function flag(...args) {
|
|
|
807
772
|
const result = {
|
|
808
773
|
$valueType: [],
|
|
809
774
|
$stateType: [],
|
|
810
|
-
|
|
775
|
+
mode: "sync",
|
|
811
776
|
priority: 10,
|
|
812
777
|
usage: [{
|
|
813
778
|
type: "option",
|
|
@@ -978,7 +943,7 @@ function flag(...args) {
|
|
|
978
943
|
* the parsed value of type {@link T}.
|
|
979
944
|
*/
|
|
980
945
|
function argument(valueParser, options = {}) {
|
|
981
|
-
const isAsync = valueParser
|
|
946
|
+
const isAsync = valueParser.mode === "async";
|
|
982
947
|
const syncValueParser = valueParser;
|
|
983
948
|
const dependencyMetadata = require_dependency_metadata.extractDependencyMetadata(valueParser);
|
|
984
949
|
const formatInvalidValueError = (error) => options.errors?.invalidValue ? typeof options.errors.invalidValue === "function" ? options.errors.invalidValue(error) : options.errors.invalidValue : require_message.message`${require_message.metavar(valueParser.metavar)}: ${error}`;
|
|
@@ -989,7 +954,7 @@ function argument(valueParser, options = {}) {
|
|
|
989
954
|
...options.hidden != null && { hidden: options.hidden }
|
|
990
955
|
};
|
|
991
956
|
const result = {
|
|
992
|
-
|
|
957
|
+
mode: valueParser.mode,
|
|
993
958
|
$valueType: [],
|
|
994
959
|
$stateType: [],
|
|
995
960
|
priority: 5,
|
|
@@ -1027,7 +992,7 @@ function argument(valueParser, options = {}) {
|
|
|
1027
992
|
error: options.errors?.multiple ? typeof options.errors.multiple === "function" ? options.errors.multiple(valueParser.metavar) : options.errors.multiple : require_message.message`The argument ${require_message.metavar(valueParser.metavar)} cannot be used multiple times.`
|
|
1028
993
|
};
|
|
1029
994
|
const rawInput = context.buffer[i];
|
|
1030
|
-
return require_mode_dispatch.dispatchByMode(valueParser
|
|
995
|
+
return require_mode_dispatch.dispatchByMode(valueParser.mode, () => {
|
|
1031
996
|
const parseResult = syncValueParser.parse(rawInput);
|
|
1032
997
|
const next = recordTrace(context, buildTraceEntry("argument-value", rawInput, context.buffer.slice(0, i + 1), syncValueParser, parseResult));
|
|
1033
998
|
return {
|
|
@@ -1077,10 +1042,10 @@ function argument(valueParser, options = {}) {
|
|
|
1077
1042
|
error: formatInvalidValueError(resolved.error)
|
|
1078
1043
|
};
|
|
1079
1044
|
};
|
|
1080
|
-
return require_mode_dispatch.dispatchByMode(valueParser
|
|
1045
|
+
return require_mode_dispatch.dispatchByMode(valueParser.mode, completeSync, completeAsync);
|
|
1081
1046
|
},
|
|
1082
1047
|
suggest(context, prefix) {
|
|
1083
|
-
if (require_annotation_state.normalizeInjectedAnnotationState(context.state) != null) return require_mode_dispatch.dispatchIterableByMode(valueParser
|
|
1048
|
+
if (require_annotation_state.normalizeInjectedAnnotationState(context.state) != null) return require_mode_dispatch.dispatchIterableByMode(valueParser.mode, function* () {}, async function* () {});
|
|
1084
1049
|
if (isAsync) return suggestArgumentAsync(valueParser, require_usage.isSuggestionHidden(options.hidden), prefix, context.dependencyRegistry, context.exec);
|
|
1085
1050
|
return suggestArgumentSync(valueParser, require_usage.isSuggestionHidden(options.hidden), prefix, context.dependencyRegistry, context.exec);
|
|
1086
1051
|
},
|
|
@@ -1125,7 +1090,7 @@ function argument(valueParser, options = {}) {
|
|
|
1125
1090
|
}
|
|
1126
1091
|
if (!require_dependency.isDerivedValueParser(valueParser)) {
|
|
1127
1092
|
const vp = valueParser;
|
|
1128
|
-
const vpMode = valueParser
|
|
1093
|
+
const vpMode = valueParser.mode;
|
|
1129
1094
|
const wrapParseResult = (parsed) => parsed.success ? parsed : {
|
|
1130
1095
|
success: false,
|
|
1131
1096
|
error: formatInvalidValueError(parsed.error)
|
|
@@ -1197,8 +1162,8 @@ function* suggestCommandSync(context, prefix, name, parser, options) {
|
|
|
1197
1162
|
text: name,
|
|
1198
1163
|
...options.description && { description: options.description }
|
|
1199
1164
|
};
|
|
1200
|
-
} else if (state[0] === "matched") yield* parser.suggest(withChildContext(context, name, getCommandChildState(context.state, parser.initialState, parser), parser.usage), prefix);
|
|
1201
|
-
else if (state[0] === "parsing") yield* parser.suggest(withChildContext(context, name, getCommandChildState(context.state, state[1], parser), parser.usage), prefix);
|
|
1165
|
+
} else if (state[0] === "matched") yield* parser.suggest(require_execution_context.withChildContext(context, name, getCommandChildState(context.state, parser.initialState, parser), parser.usage), prefix);
|
|
1166
|
+
else if (state[0] === "parsing") yield* parser.suggest(require_execution_context.withChildContext(context, name, getCommandChildState(context.state, state[1], parser), parser.usage), prefix);
|
|
1202
1167
|
}
|
|
1203
1168
|
async function* suggestCommandAsync(context, prefix, name, parser, options) {
|
|
1204
1169
|
if (require_usage.isSuggestionHidden(options.hidden)) return;
|
|
@@ -1210,10 +1175,10 @@ async function* suggestCommandAsync(context, prefix, name, parser, options) {
|
|
|
1210
1175
|
...options.description && { description: options.description }
|
|
1211
1176
|
};
|
|
1212
1177
|
} else if (state[0] === "matched") {
|
|
1213
|
-
const suggestions = parser.suggest(withChildContext(context, name, getCommandChildState(context.state, parser.initialState, parser), parser.usage), prefix);
|
|
1178
|
+
const suggestions = parser.suggest(require_execution_context.withChildContext(context, name, getCommandChildState(context.state, parser.initialState, parser), parser.usage), prefix);
|
|
1214
1179
|
for await (const s of suggestions) yield s;
|
|
1215
1180
|
} else if (state[0] === "parsing") {
|
|
1216
|
-
const suggestions = parser.suggest(withChildContext(context, name, getCommandChildState(context.state, state[1], parser), parser.usage), prefix);
|
|
1181
|
+
const suggestions = parser.suggest(require_execution_context.withChildContext(context, name, getCommandChildState(context.state, state[1], parser), parser.usage), prefix);
|
|
1217
1182
|
for await (const s of suggestions) yield s;
|
|
1218
1183
|
}
|
|
1219
1184
|
}
|
|
@@ -1235,12 +1200,12 @@ async function* suggestCommandAsync(context, prefix, name, parser, options) {
|
|
|
1235
1200
|
*/
|
|
1236
1201
|
function command(name, parser, options = {}) {
|
|
1237
1202
|
require_validate.validateCommandNames([name], "Command");
|
|
1238
|
-
const isAsync = parser
|
|
1203
|
+
const isAsync = parser.mode === "async";
|
|
1239
1204
|
const syncInnerParser = parser;
|
|
1240
1205
|
const asyncInnerParser = parser;
|
|
1241
1206
|
const result = {
|
|
1242
1207
|
[Symbol.for("@optique/core/commandParser")]: true,
|
|
1243
|
-
|
|
1208
|
+
mode: parser.mode,
|
|
1244
1209
|
$valueType: [],
|
|
1245
1210
|
$stateType: [],
|
|
1246
1211
|
priority: 15,
|
|
@@ -1310,7 +1275,7 @@ function command(name, parser, options = {}) {
|
|
|
1310
1275
|
const innerState = state[0] === "matched" ? getCommandParseChildState(context.state, parser.initialState, parser) : getCommandParseChildState(context.state, state[1], parser);
|
|
1311
1276
|
const wrapState = (parseResult) => {
|
|
1312
1277
|
if (parseResult.success) {
|
|
1313
|
-
const mergedExec = mergeChildExec(context.exec, parseResult.next.exec);
|
|
1278
|
+
const mergedExec = require_execution_context.mergeChildExec(context.exec, parseResult.next.exec);
|
|
1314
1279
|
return {
|
|
1315
1280
|
success: true,
|
|
1316
1281
|
next: {
|
|
@@ -1326,7 +1291,7 @@ function command(name, parser, options = {}) {
|
|
|
1326
1291
|
}
|
|
1327
1292
|
return parseResult;
|
|
1328
1293
|
};
|
|
1329
|
-
return require_mode_dispatch.dispatchByMode(parser
|
|
1294
|
+
return require_mode_dispatch.dispatchByMode(parser.mode, () => wrapState(syncInnerParser.parse(require_execution_context.withChildContext(context, name, innerState, parser.usage))), async () => wrapState(await parser.parse(require_execution_context.withChildContext(context, name, innerState, parser.usage))));
|
|
1330
1295
|
}
|
|
1331
1296
|
return {
|
|
1332
1297
|
success: false,
|
|
@@ -1341,7 +1306,7 @@ function command(name, parser, options = {}) {
|
|
|
1341
1306
|
error: options.errors?.notFound ?? require_message.message`Command ${require_message.optionName(name)} was not matched.`
|
|
1342
1307
|
};
|
|
1343
1308
|
else if (normalizedState[0] === "matched") {
|
|
1344
|
-
const childExec = withChildExecPath(exec, name);
|
|
1309
|
+
const childExec = require_execution_context.withChildExecPath(exec, name);
|
|
1345
1310
|
const childContext = {
|
|
1346
1311
|
buffer: [],
|
|
1347
1312
|
optionsTerminated: false,
|
|
@@ -1353,18 +1318,18 @@ function command(name, parser, options = {}) {
|
|
|
1353
1318
|
dependencyRegistry: childExec.dependencyRegistry
|
|
1354
1319
|
} : {}
|
|
1355
1320
|
};
|
|
1356
|
-
return require_mode_dispatch.dispatchByMode(parser
|
|
1321
|
+
return require_mode_dispatch.dispatchByMode(parser.mode, () => {
|
|
1357
1322
|
const parseResult = syncInnerParser.parse(childContext);
|
|
1358
|
-
const nextExec = parseResult.success ? mergeChildExec(childExec, parseResult.next.exec) : childExec;
|
|
1323
|
+
const nextExec = parseResult.success ? require_execution_context.mergeChildExec(childExec, parseResult.next.exec) : childExec;
|
|
1359
1324
|
return syncInnerParser.complete(parseResult.success ? getCommandChildState(state, parseResult.next.state, parser) : getCommandChildState(state, syncInnerParser.initialState, parser), nextExec);
|
|
1360
1325
|
}, async () => {
|
|
1361
1326
|
const parseResult = await asyncInnerParser.parse(childContext);
|
|
1362
|
-
const nextExec = parseResult.success ? mergeChildExec(childExec, parseResult.next.exec) : childExec;
|
|
1327
|
+
const nextExec = parseResult.success ? require_execution_context.mergeChildExec(childExec, parseResult.next.exec) : childExec;
|
|
1363
1328
|
return asyncInnerParser.complete(parseResult.success ? getCommandChildState(state, parseResult.next.state, parser) : getCommandChildState(state, parser.initialState, parser), nextExec);
|
|
1364
1329
|
});
|
|
1365
1330
|
} else if (normalizedState[0] === "parsing") {
|
|
1366
|
-
const childExec = withChildExecPath(exec, name);
|
|
1367
|
-
return require_mode_dispatch.dispatchByMode(parser
|
|
1331
|
+
const childExec = require_execution_context.withChildExecPath(exec, name);
|
|
1332
|
+
return require_mode_dispatch.dispatchByMode(parser.mode, () => syncInnerParser.complete(getCommandChildState(state, normalizedState[1], parser), childExec), async () => await asyncInnerParser.complete(getCommandChildState(state, normalizedState[1], parser), childExec));
|
|
1368
1333
|
}
|
|
1369
1334
|
return {
|
|
1370
1335
|
success: false,
|
|
@@ -1373,9 +1338,9 @@ function command(name, parser, options = {}) {
|
|
|
1373
1338
|
},
|
|
1374
1339
|
[require_phase2_seed.extractPhase2SeedKey](state, exec) {
|
|
1375
1340
|
const normalizedState = normalizeCommandState(state);
|
|
1376
|
-
if (typeof normalizedState === "undefined") return require_mode_dispatch.wrapForMode(parser
|
|
1341
|
+
if (typeof normalizedState === "undefined") return require_mode_dispatch.wrapForMode(parser.mode, null);
|
|
1377
1342
|
if (normalizedState[0] === "matched") {
|
|
1378
|
-
const childExec = withChildExecPath(exec, name);
|
|
1343
|
+
const childExec = require_execution_context.withChildExecPath(exec, name);
|
|
1379
1344
|
const childContext = {
|
|
1380
1345
|
buffer: [],
|
|
1381
1346
|
optionsTerminated: false,
|
|
@@ -1387,18 +1352,18 @@ function command(name, parser, options = {}) {
|
|
|
1387
1352
|
dependencyRegistry: childExec.dependencyRegistry
|
|
1388
1353
|
} : {}
|
|
1389
1354
|
};
|
|
1390
|
-
return require_mode_dispatch.dispatchByMode(parser
|
|
1355
|
+
return require_mode_dispatch.dispatchByMode(parser.mode, () => {
|
|
1391
1356
|
const parseResult = syncInnerParser.parse(childContext);
|
|
1392
|
-
const nextExec = parseResult.success ? mergeChildExec(childExec, parseResult.next.exec) : childExec;
|
|
1357
|
+
const nextExec = parseResult.success ? require_execution_context.mergeChildExec(childExec, parseResult.next.exec) : childExec;
|
|
1393
1358
|
return require_phase2_seed.completeOrExtractPhase2Seed(syncInnerParser, parseResult.success ? getCommandChildState(state, parseResult.next.state, parser) : getCommandChildState(state, syncInnerParser.initialState, parser), nextExec);
|
|
1394
1359
|
}, async () => {
|
|
1395
1360
|
const parseResult = await asyncInnerParser.parse(childContext);
|
|
1396
|
-
const nextExec = parseResult.success ? mergeChildExec(childExec, parseResult.next.exec) : childExec;
|
|
1361
|
+
const nextExec = parseResult.success ? require_execution_context.mergeChildExec(childExec, parseResult.next.exec) : childExec;
|
|
1397
1362
|
return await require_phase2_seed.completeOrExtractPhase2Seed(asyncInnerParser, parseResult.success ? getCommandChildState(state, parseResult.next.state, parser) : getCommandChildState(state, parser.initialState, parser), nextExec);
|
|
1398
1363
|
});
|
|
1399
1364
|
}
|
|
1400
|
-
if (normalizedState[0] === "parsing") return require_phase2_seed.completeOrExtractPhase2Seed(parser, getCommandChildState(state, normalizedState[1], parser), withChildExecPath(exec, name));
|
|
1401
|
-
return require_mode_dispatch.wrapForMode(parser
|
|
1365
|
+
if (normalizedState[0] === "parsing") return require_phase2_seed.completeOrExtractPhase2Seed(parser, getCommandChildState(state, normalizedState[1], parser), require_execution_context.withChildExecPath(exec, name));
|
|
1366
|
+
return require_mode_dispatch.wrapForMode(parser.mode, null);
|
|
1402
1367
|
},
|
|
1403
1368
|
suggest(context, prefix) {
|
|
1404
1369
|
if (isAsync) return suggestCommandAsync(context, prefix, name, parser, options);
|
|
@@ -1507,7 +1472,7 @@ function passThrough(options = {}) {
|
|
|
1507
1472
|
return {
|
|
1508
1473
|
$valueType: [],
|
|
1509
1474
|
$stateType: [],
|
|
1510
|
-
|
|
1475
|
+
mode: "sync",
|
|
1511
1476
|
priority: -10,
|
|
1512
1477
|
usage: [{
|
|
1513
1478
|
type: "passthrough",
|
package/dist/primitives.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Message } from "./message.cjs";
|
|
2
2
|
import { HiddenVisibility, OptionName, Usage } from "./usage.cjs";
|
|
3
3
|
import { ValueParser, ValueParserResult } from "./valueparser.cjs";
|
|
4
|
-
import { Mode, Parser } from "./parser.cjs";
|
|
4
|
+
import { Mode, Parser } from "./internal/parser.cjs";
|
|
5
5
|
|
|
6
6
|
//#region src/primitives.d.ts
|
|
7
7
|
/** @internal */
|
package/dist/primitives.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Message } from "./message.js";
|
|
2
2
|
import { HiddenVisibility, OptionName, Usage } from "./usage.js";
|
|
3
3
|
import { ValueParser, ValueParserResult } from "./valueparser.js";
|
|
4
|
-
import { Mode, Parser } from "./parser.js";
|
|
4
|
+
import { Mode, Parser } from "./internal/parser.js";
|
|
5
5
|
|
|
6
6
|
//#region src/primitives.d.ts
|
|
7
7
|
/** @internal */
|
package/dist/primitives.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { annotateFreshArray, getAnnotations } from "./annotations.js";
|
|
1
|
+
import { annotateFreshArray, getAnnotations } from "./internal/annotations.js";
|
|
2
2
|
import { message, metavar, optionName, optionNames, text, valueSet } from "./message.js";
|
|
3
3
|
import { validateCommandNames, validateOptionNames } from "./validate.js";
|
|
4
4
|
import { extractOptionNames, isDocHidden, isSuggestionHidden } from "./usage.js";
|
|
5
|
-
import { dispatchByMode, dispatchIterableByMode, wrapForMode } from "./mode-dispatch.js";
|
|
6
|
-
import { getDefaultValuesFunction, getDependencyIds, getSnapshottedDefaultDependencyValues, isDerivedValueParser, suggestWithDependency } from "./dependency.js";
|
|
5
|
+
import { dispatchByMode, dispatchIterableByMode, wrapForMode } from "./internal/mode-dispatch.js";
|
|
6
|
+
import { getDefaultValuesFunction, getDependencyIds, getSnapshottedDefaultDependencyValues, isDerivedValueParser, suggestWithDependency } from "./internal/dependency.js";
|
|
7
7
|
import { replayDerivedParser, replayDerivedParserAsync } from "./dependency-runtime.js";
|
|
8
|
-
import {
|
|
8
|
+
import { getWrappedChildParseState, getWrappedChildState, isAnnotationWrappedInitialState, normalizeInjectedAnnotationState } from "./annotation-state.js";
|
|
9
|
+
import { mergeChildExec, withChildContext, withChildExecPath } from "./execution-context.js";
|
|
9
10
|
import { completeOrExtractPhase2Seed, extractPhase2SeedKey } from "./phase2-seed.js";
|
|
10
11
|
import { DEFAULT_FIND_SIMILAR_OPTIONS, createErrorWithSuggestions, createSuggestionMessage, findSimilar } from "./suggestion.js";
|
|
11
12
|
import { extractLeadingCommandNames } from "./usage-internals.js";
|
|
13
|
+
import { extractDependencyMetadata } from "./dependency-metadata.js";
|
|
12
14
|
import { isValueParser } from "./valueparser.js";
|
|
13
|
-
import { getWrappedChildParseState, getWrappedChildState, isAnnotationWrappedInitialState, normalizeInjectedAnnotationState } from "./annotation-state.js";
|
|
14
15
|
|
|
15
16
|
//#region src/primitives.ts
|
|
16
17
|
/**
|
|
@@ -18,42 +19,6 @@ import { getWrappedChildParseState, getWrappedChildState, isAnnotationWrappedIni
|
|
|
18
19
|
* do not match any specific name at the first buffer position.
|
|
19
20
|
*/
|
|
20
21
|
const EMPTY_LEADING_NAMES = /* @__PURE__ */ new Set();
|
|
21
|
-
function withChildExecPath(exec, segment) {
|
|
22
|
-
if (exec == null) return void 0;
|
|
23
|
-
return {
|
|
24
|
-
...exec,
|
|
25
|
-
path: [...exec.path ?? [], segment]
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
function mergeChildExec(parent, child) {
|
|
29
|
-
if (parent == null) return child;
|
|
30
|
-
if (child == null) return parent;
|
|
31
|
-
return {
|
|
32
|
-
...parent,
|
|
33
|
-
trace: child.trace ?? parent.trace,
|
|
34
|
-
dependencyRuntime: child.dependencyRuntime ?? parent.dependencyRuntime,
|
|
35
|
-
dependencyRegistry: child.dependencyRegistry ?? parent.dependencyRegistry,
|
|
36
|
-
commandPath: child.commandPath ?? parent.commandPath,
|
|
37
|
-
preCompletedByParser: child.preCompletedByParser ?? parent.preCompletedByParser,
|
|
38
|
-
excludedSourceFields: child.excludedSourceFields ?? parent.excludedSourceFields
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
function withChildContext(context, segment, state, usage) {
|
|
42
|
-
const exec = withChildExecPath(context.exec, segment);
|
|
43
|
-
const dependencyRegistry = context.dependencyRegistry ?? exec?.dependencyRegistry;
|
|
44
|
-
return {
|
|
45
|
-
...context,
|
|
46
|
-
state,
|
|
47
|
-
...usage != null ? { usage } : {},
|
|
48
|
-
...exec != null ? {
|
|
49
|
-
exec: dependencyRegistry === exec.dependencyRegistry ? exec : {
|
|
50
|
-
...exec,
|
|
51
|
-
dependencyRegistry
|
|
52
|
-
},
|
|
53
|
-
dependencyRegistry
|
|
54
|
-
} : {}
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
22
|
function hasParsedOptionValue(state, valueParser) {
|
|
58
23
|
if (valueParser != null) return state != null && typeof state === "object" && "success" in state && typeof state.success === "boolean";
|
|
59
24
|
return state != null && "success" in state && state.success && state.value === true;
|
|
@@ -146,7 +111,7 @@ function constant(value) {
|
|
|
146
111
|
const result = {
|
|
147
112
|
$valueType: [],
|
|
148
113
|
$stateType: [],
|
|
149
|
-
|
|
114
|
+
mode: "sync",
|
|
150
115
|
priority: 0,
|
|
151
116
|
usage: [],
|
|
152
117
|
leadingNames: EMPTY_LEADING_NAMES,
|
|
@@ -203,7 +168,7 @@ function fail() {
|
|
|
203
168
|
return {
|
|
204
169
|
$valueType: [],
|
|
205
170
|
$stateType: [],
|
|
206
|
-
|
|
171
|
+
mode: "sync",
|
|
207
172
|
priority: 0,
|
|
208
173
|
usage: [],
|
|
209
174
|
leadingNames: EMPTY_LEADING_NAMES,
|
|
@@ -437,13 +402,13 @@ function option(...args) {
|
|
|
437
402
|
valueParser = void 0;
|
|
438
403
|
}
|
|
439
404
|
validateOptionNames(optionNames$1, "Option");
|
|
440
|
-
const mode = valueParser
|
|
405
|
+
const mode = valueParser?.mode ?? "sync";
|
|
441
406
|
const isAsync = mode === "async";
|
|
442
407
|
const syncValueParser = valueParser;
|
|
443
408
|
const dependencyMetadata = valueParser != null ? extractDependencyMetadata(valueParser) : void 0;
|
|
444
409
|
const formatInvalidValueError = (error) => options.errors?.invalidValue ? typeof options.errors.invalidValue === "function" ? options.errors.invalidValue(error) : options.errors.invalidValue : message`${optionNames(optionNames$1)}: ${error}`;
|
|
445
410
|
const result = {
|
|
446
|
-
|
|
411
|
+
mode,
|
|
447
412
|
$valueType: [],
|
|
448
413
|
$stateType: [],
|
|
449
414
|
priority: 10,
|
|
@@ -807,7 +772,7 @@ function flag(...args) {
|
|
|
807
772
|
const result = {
|
|
808
773
|
$valueType: [],
|
|
809
774
|
$stateType: [],
|
|
810
|
-
|
|
775
|
+
mode: "sync",
|
|
811
776
|
priority: 10,
|
|
812
777
|
usage: [{
|
|
813
778
|
type: "option",
|
|
@@ -978,7 +943,7 @@ function flag(...args) {
|
|
|
978
943
|
* the parsed value of type {@link T}.
|
|
979
944
|
*/
|
|
980
945
|
function argument(valueParser, options = {}) {
|
|
981
|
-
const isAsync = valueParser
|
|
946
|
+
const isAsync = valueParser.mode === "async";
|
|
982
947
|
const syncValueParser = valueParser;
|
|
983
948
|
const dependencyMetadata = extractDependencyMetadata(valueParser);
|
|
984
949
|
const formatInvalidValueError = (error) => options.errors?.invalidValue ? typeof options.errors.invalidValue === "function" ? options.errors.invalidValue(error) : options.errors.invalidValue : message`${metavar(valueParser.metavar)}: ${error}`;
|
|
@@ -989,7 +954,7 @@ function argument(valueParser, options = {}) {
|
|
|
989
954
|
...options.hidden != null && { hidden: options.hidden }
|
|
990
955
|
};
|
|
991
956
|
const result = {
|
|
992
|
-
|
|
957
|
+
mode: valueParser.mode,
|
|
993
958
|
$valueType: [],
|
|
994
959
|
$stateType: [],
|
|
995
960
|
priority: 5,
|
|
@@ -1027,7 +992,7 @@ function argument(valueParser, options = {}) {
|
|
|
1027
992
|
error: options.errors?.multiple ? typeof options.errors.multiple === "function" ? options.errors.multiple(valueParser.metavar) : options.errors.multiple : message`The argument ${metavar(valueParser.metavar)} cannot be used multiple times.`
|
|
1028
993
|
};
|
|
1029
994
|
const rawInput = context.buffer[i];
|
|
1030
|
-
return dispatchByMode(valueParser
|
|
995
|
+
return dispatchByMode(valueParser.mode, () => {
|
|
1031
996
|
const parseResult = syncValueParser.parse(rawInput);
|
|
1032
997
|
const next = recordTrace(context, buildTraceEntry("argument-value", rawInput, context.buffer.slice(0, i + 1), syncValueParser, parseResult));
|
|
1033
998
|
return {
|
|
@@ -1077,10 +1042,10 @@ function argument(valueParser, options = {}) {
|
|
|
1077
1042
|
error: formatInvalidValueError(resolved.error)
|
|
1078
1043
|
};
|
|
1079
1044
|
};
|
|
1080
|
-
return dispatchByMode(valueParser
|
|
1045
|
+
return dispatchByMode(valueParser.mode, completeSync, completeAsync);
|
|
1081
1046
|
},
|
|
1082
1047
|
suggest(context, prefix) {
|
|
1083
|
-
if (normalizeInjectedAnnotationState(context.state) != null) return dispatchIterableByMode(valueParser
|
|
1048
|
+
if (normalizeInjectedAnnotationState(context.state) != null) return dispatchIterableByMode(valueParser.mode, function* () {}, async function* () {});
|
|
1084
1049
|
if (isAsync) return suggestArgumentAsync(valueParser, isSuggestionHidden(options.hidden), prefix, context.dependencyRegistry, context.exec);
|
|
1085
1050
|
return suggestArgumentSync(valueParser, isSuggestionHidden(options.hidden), prefix, context.dependencyRegistry, context.exec);
|
|
1086
1051
|
},
|
|
@@ -1125,7 +1090,7 @@ function argument(valueParser, options = {}) {
|
|
|
1125
1090
|
}
|
|
1126
1091
|
if (!isDerivedValueParser(valueParser)) {
|
|
1127
1092
|
const vp = valueParser;
|
|
1128
|
-
const vpMode = valueParser
|
|
1093
|
+
const vpMode = valueParser.mode;
|
|
1129
1094
|
const wrapParseResult = (parsed) => parsed.success ? parsed : {
|
|
1130
1095
|
success: false,
|
|
1131
1096
|
error: formatInvalidValueError(parsed.error)
|
|
@@ -1235,12 +1200,12 @@ async function* suggestCommandAsync(context, prefix, name, parser, options) {
|
|
|
1235
1200
|
*/
|
|
1236
1201
|
function command(name, parser, options = {}) {
|
|
1237
1202
|
validateCommandNames([name], "Command");
|
|
1238
|
-
const isAsync = parser
|
|
1203
|
+
const isAsync = parser.mode === "async";
|
|
1239
1204
|
const syncInnerParser = parser;
|
|
1240
1205
|
const asyncInnerParser = parser;
|
|
1241
1206
|
const result = {
|
|
1242
1207
|
[Symbol.for("@optique/core/commandParser")]: true,
|
|
1243
|
-
|
|
1208
|
+
mode: parser.mode,
|
|
1244
1209
|
$valueType: [],
|
|
1245
1210
|
$stateType: [],
|
|
1246
1211
|
priority: 15,
|
|
@@ -1326,7 +1291,7 @@ function command(name, parser, options = {}) {
|
|
|
1326
1291
|
}
|
|
1327
1292
|
return parseResult;
|
|
1328
1293
|
};
|
|
1329
|
-
return dispatchByMode(parser
|
|
1294
|
+
return dispatchByMode(parser.mode, () => wrapState(syncInnerParser.parse(withChildContext(context, name, innerState, parser.usage))), async () => wrapState(await parser.parse(withChildContext(context, name, innerState, parser.usage))));
|
|
1330
1295
|
}
|
|
1331
1296
|
return {
|
|
1332
1297
|
success: false,
|
|
@@ -1353,7 +1318,7 @@ function command(name, parser, options = {}) {
|
|
|
1353
1318
|
dependencyRegistry: childExec.dependencyRegistry
|
|
1354
1319
|
} : {}
|
|
1355
1320
|
};
|
|
1356
|
-
return dispatchByMode(parser
|
|
1321
|
+
return dispatchByMode(parser.mode, () => {
|
|
1357
1322
|
const parseResult = syncInnerParser.parse(childContext);
|
|
1358
1323
|
const nextExec = parseResult.success ? mergeChildExec(childExec, parseResult.next.exec) : childExec;
|
|
1359
1324
|
return syncInnerParser.complete(parseResult.success ? getCommandChildState(state, parseResult.next.state, parser) : getCommandChildState(state, syncInnerParser.initialState, parser), nextExec);
|
|
@@ -1364,7 +1329,7 @@ function command(name, parser, options = {}) {
|
|
|
1364
1329
|
});
|
|
1365
1330
|
} else if (normalizedState[0] === "parsing") {
|
|
1366
1331
|
const childExec = withChildExecPath(exec, name);
|
|
1367
|
-
return dispatchByMode(parser
|
|
1332
|
+
return dispatchByMode(parser.mode, () => syncInnerParser.complete(getCommandChildState(state, normalizedState[1], parser), childExec), async () => await asyncInnerParser.complete(getCommandChildState(state, normalizedState[1], parser), childExec));
|
|
1368
1333
|
}
|
|
1369
1334
|
return {
|
|
1370
1335
|
success: false,
|
|
@@ -1373,7 +1338,7 @@ function command(name, parser, options = {}) {
|
|
|
1373
1338
|
},
|
|
1374
1339
|
[extractPhase2SeedKey](state, exec) {
|
|
1375
1340
|
const normalizedState = normalizeCommandState(state);
|
|
1376
|
-
if (typeof normalizedState === "undefined") return wrapForMode(parser
|
|
1341
|
+
if (typeof normalizedState === "undefined") return wrapForMode(parser.mode, null);
|
|
1377
1342
|
if (normalizedState[0] === "matched") {
|
|
1378
1343
|
const childExec = withChildExecPath(exec, name);
|
|
1379
1344
|
const childContext = {
|
|
@@ -1387,7 +1352,7 @@ function command(name, parser, options = {}) {
|
|
|
1387
1352
|
dependencyRegistry: childExec.dependencyRegistry
|
|
1388
1353
|
} : {}
|
|
1389
1354
|
};
|
|
1390
|
-
return dispatchByMode(parser
|
|
1355
|
+
return dispatchByMode(parser.mode, () => {
|
|
1391
1356
|
const parseResult = syncInnerParser.parse(childContext);
|
|
1392
1357
|
const nextExec = parseResult.success ? mergeChildExec(childExec, parseResult.next.exec) : childExec;
|
|
1393
1358
|
return completeOrExtractPhase2Seed(syncInnerParser, parseResult.success ? getCommandChildState(state, parseResult.next.state, parser) : getCommandChildState(state, syncInnerParser.initialState, parser), nextExec);
|
|
@@ -1398,7 +1363,7 @@ function command(name, parser, options = {}) {
|
|
|
1398
1363
|
});
|
|
1399
1364
|
}
|
|
1400
1365
|
if (normalizedState[0] === "parsing") return completeOrExtractPhase2Seed(parser, getCommandChildState(state, normalizedState[1], parser), withChildExecPath(exec, name));
|
|
1401
|
-
return wrapForMode(parser
|
|
1366
|
+
return wrapForMode(parser.mode, null);
|
|
1402
1367
|
},
|
|
1403
1368
|
suggest(context, prefix) {
|
|
1404
1369
|
if (isAsync) return suggestCommandAsync(context, prefix, name, parser, options);
|
|
@@ -1507,7 +1472,7 @@ function passThrough(options = {}) {
|
|
|
1507
1472
|
return {
|
|
1508
1473
|
$valueType: [],
|
|
1509
1474
|
$stateType: [],
|
|
1510
|
-
|
|
1475
|
+
mode: "sync",
|
|
1511
1476
|
priority: -10,
|
|
1512
1477
|
usage: [{
|
|
1513
1478
|
type: "passthrough",
|
package/dist/program.d.cts
CHANGED
package/dist/program.d.ts
CHANGED