@optique/core 1.3.0-dev.2488 → 1.3.0-dev.2497
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/facade.cjs +13 -143
- package/dist/facade.js +15 -145
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/internal/mode-dispatch.cjs +19 -0
- package/dist/internal/mode-dispatch.d.cts +16 -0
- package/dist/internal/mode-dispatch.d.ts +16 -0
- package/dist/internal/mode-dispatch.js +19 -1
- package/dist/internal/parser.cjs +196 -85
- package/dist/internal/parser.d.cts +72 -1
- package/dist/internal/parser.d.ts +72 -1
- package/dist/internal/parser.js +195 -87
- package/dist/parser.cjs +1 -0
- package/dist/parser.d.cts +2 -2
- package/dist/parser.d.ts +2 -2
- package/dist/parser.js +2 -2
- package/package.json +2 -2
- package/skills/optique/SKILL.md +7 -7
package/dist/internal/parser.cjs
CHANGED
|
@@ -91,6 +91,160 @@ function createParserContext(frame, exec) {
|
|
|
91
91
|
function injectAnnotationsIntoState(state, options) {
|
|
92
92
|
return require_internal_annotations.injectAnnotations(state, options?.annotations);
|
|
93
93
|
}
|
|
94
|
+
function getFailureProgress(args, buffer, consumedInStep) {
|
|
95
|
+
return {
|
|
96
|
+
remainingArgs: buffer.slice(consumedInStep),
|
|
97
|
+
consumedCount: args.length - buffer.length + consumedInStep
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function createParseExec(parser) {
|
|
101
|
+
return {
|
|
102
|
+
usage: parser.usage,
|
|
103
|
+
phase: "parse",
|
|
104
|
+
path: [],
|
|
105
|
+
commandPath: [],
|
|
106
|
+
trace: require_input_trace.createInputTrace()
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function getCommandPath(exec) {
|
|
110
|
+
return [...exec?.commandPath ?? []];
|
|
111
|
+
}
|
|
112
|
+
function createCompleteExec(exec, context, session) {
|
|
113
|
+
const runtime = require_dependency_runtime.createDependencyRuntimeContext();
|
|
114
|
+
return {
|
|
115
|
+
...exec,
|
|
116
|
+
phase: "complete",
|
|
117
|
+
dependencyRuntime: runtime,
|
|
118
|
+
dependencyRegistry: runtime.registry,
|
|
119
|
+
commandPath: context.exec?.commandPath ?? exec.commandPath,
|
|
120
|
+
trace: context.exec?.trace ?? context.trace ?? exec.trace,
|
|
121
|
+
effectfulCompletionSession: session ?? createEffectfulCompletionSession()
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function attemptParseSync(parser, args, options = {}) {
|
|
125
|
+
const initialState = injectAnnotationsIntoState(parser.initialState, options.parseOptions);
|
|
126
|
+
const shouldUnwrapAnnotatedValue = require_internal_annotations.hasMeaningfulAnnotations(options.parseOptions?.annotations) || require_internal_annotations.isInjectedAnnotationWrapper(parser.initialState);
|
|
127
|
+
const exec = createParseExec(parser);
|
|
128
|
+
let context = createParserContext({
|
|
129
|
+
buffer: [...args],
|
|
130
|
+
state: initialState,
|
|
131
|
+
optionsTerminated: false
|
|
132
|
+
}, exec);
|
|
133
|
+
do {
|
|
134
|
+
const result = parser.parse(context);
|
|
135
|
+
if (!result.success) {
|
|
136
|
+
const progress = getFailureProgress(args, context.buffer, result.consumed);
|
|
137
|
+
return {
|
|
138
|
+
kind: "failure",
|
|
139
|
+
error: result.error,
|
|
140
|
+
remainingArgs: progress.remainingArgs,
|
|
141
|
+
consumedCount: progress.consumedCount,
|
|
142
|
+
optionsTerminated: context.optionsTerminated,
|
|
143
|
+
commandPath: getCommandPath(context.exec)
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
const previousBuffer = context.buffer;
|
|
147
|
+
context = result.next;
|
|
148
|
+
if (isBufferUnchanged(previousBuffer, context.buffer)) {
|
|
149
|
+
const progress = getFailureProgress(args, previousBuffer, result.consumed.length);
|
|
150
|
+
return {
|
|
151
|
+
kind: "failure",
|
|
152
|
+
error: require_message.message`Unexpected option or argument: ${context.buffer[0]}.`,
|
|
153
|
+
remainingArgs: progress.remainingArgs,
|
|
154
|
+
consumedCount: progress.consumedCount,
|
|
155
|
+
optionsTerminated: context.optionsTerminated,
|
|
156
|
+
commandPath: getCommandPath(context.exec)
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
} while (context.buffer.length > 0);
|
|
160
|
+
if (options.mode === "parse-only") return {
|
|
161
|
+
kind: "success",
|
|
162
|
+
result: {
|
|
163
|
+
success: true,
|
|
164
|
+
value: void 0
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
const endResult = parser.complete(context.state, createCompleteExec(exec, context, options.session));
|
|
168
|
+
if (!endResult.success) return {
|
|
169
|
+
kind: "failure",
|
|
170
|
+
error: endResult.error,
|
|
171
|
+
remainingArgs: [],
|
|
172
|
+
consumedCount: args.length,
|
|
173
|
+
optionsTerminated: context.optionsTerminated,
|
|
174
|
+
commandPath: getCommandPath(context.exec)
|
|
175
|
+
};
|
|
176
|
+
return {
|
|
177
|
+
kind: "success",
|
|
178
|
+
result: {
|
|
179
|
+
success: true,
|
|
180
|
+
value: shouldUnwrapAnnotatedValue ? require_internal_annotations.unwrapInjectedAnnotationWrapper(endResult.value) : endResult.value,
|
|
181
|
+
...endResult.deferred ? { deferred: true } : {},
|
|
182
|
+
...endResult.deferredKeys ? { deferredKeys: endResult.deferredKeys } : {}
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
async function attemptParseAsync(parser, args, options = {}) {
|
|
187
|
+
const initialState = injectAnnotationsIntoState(parser.initialState, options.parseOptions);
|
|
188
|
+
const shouldUnwrapAnnotatedValue = require_internal_annotations.hasMeaningfulAnnotations(options.parseOptions?.annotations) || require_internal_annotations.isInjectedAnnotationWrapper(parser.initialState);
|
|
189
|
+
const exec = createParseExec(parser);
|
|
190
|
+
let context = createParserContext({
|
|
191
|
+
buffer: [...args],
|
|
192
|
+
state: initialState,
|
|
193
|
+
optionsTerminated: false
|
|
194
|
+
}, exec);
|
|
195
|
+
do {
|
|
196
|
+
const result = await parser.parse(context);
|
|
197
|
+
if (!result.success) {
|
|
198
|
+
const progress = getFailureProgress(args, context.buffer, result.consumed);
|
|
199
|
+
return {
|
|
200
|
+
kind: "failure",
|
|
201
|
+
error: result.error,
|
|
202
|
+
remainingArgs: progress.remainingArgs,
|
|
203
|
+
consumedCount: progress.consumedCount,
|
|
204
|
+
optionsTerminated: context.optionsTerminated,
|
|
205
|
+
commandPath: getCommandPath(context.exec)
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
const previousBuffer = context.buffer;
|
|
209
|
+
context = result.next;
|
|
210
|
+
if (isBufferUnchanged(previousBuffer, context.buffer)) {
|
|
211
|
+
const progress = getFailureProgress(args, previousBuffer, result.consumed.length);
|
|
212
|
+
return {
|
|
213
|
+
kind: "failure",
|
|
214
|
+
error: require_message.message`Unexpected option or argument: ${context.buffer[0]}.`,
|
|
215
|
+
remainingArgs: progress.remainingArgs,
|
|
216
|
+
consumedCount: progress.consumedCount,
|
|
217
|
+
optionsTerminated: context.optionsTerminated,
|
|
218
|
+
commandPath: getCommandPath(context.exec)
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
} while (context.buffer.length > 0);
|
|
222
|
+
if (options.mode === "parse-only") return {
|
|
223
|
+
kind: "success",
|
|
224
|
+
result: {
|
|
225
|
+
success: true,
|
|
226
|
+
value: void 0
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
const endResult = await parser.complete(context.state, createCompleteExec(exec, context, options.session));
|
|
230
|
+
if (!endResult.success) return {
|
|
231
|
+
kind: "failure",
|
|
232
|
+
error: endResult.error,
|
|
233
|
+
remainingArgs: [],
|
|
234
|
+
consumedCount: args.length,
|
|
235
|
+
optionsTerminated: context.optionsTerminated,
|
|
236
|
+
commandPath: getCommandPath(context.exec)
|
|
237
|
+
};
|
|
238
|
+
return {
|
|
239
|
+
kind: "success",
|
|
240
|
+
result: {
|
|
241
|
+
success: true,
|
|
242
|
+
value: shouldUnwrapAnnotatedValue ? require_internal_annotations.unwrapInjectedAnnotationWrapper(endResult.value) : endResult.value,
|
|
243
|
+
...endResult.deferred ? { deferred: true } : {},
|
|
244
|
+
...endResult.deferredKeys ? { deferredKeys: endResult.deferredKeys } : {}
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
}
|
|
94
248
|
/**
|
|
95
249
|
* Parses an array of command-line arguments using the provided combined parser.
|
|
96
250
|
* This function processes the input arguments, applying the parser to each
|
|
@@ -116,51 +270,10 @@ function injectAnnotationsIntoState(state, options) {
|
|
|
116
270
|
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
117
271
|
*/
|
|
118
272
|
function parseSync(parser, args, options) {
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
const exec = {
|
|
122
|
-
usage: parser.usage,
|
|
123
|
-
phase: "parse",
|
|
124
|
-
path: [],
|
|
125
|
-
trace: require_input_trace.createInputTrace()
|
|
126
|
-
};
|
|
127
|
-
let context = createParserContext({
|
|
128
|
-
buffer: args,
|
|
129
|
-
state: initialState,
|
|
130
|
-
optionsTerminated: false
|
|
131
|
-
}, exec);
|
|
132
|
-
do {
|
|
133
|
-
const result = parser.parse(context);
|
|
134
|
-
if (!result.success) return {
|
|
135
|
-
success: false,
|
|
136
|
-
error: result.error
|
|
137
|
-
};
|
|
138
|
-
const previousBuffer = context.buffer;
|
|
139
|
-
context = result.next;
|
|
140
|
-
if (isBufferUnchanged(previousBuffer, context.buffer)) return {
|
|
141
|
-
success: false,
|
|
142
|
-
error: require_message.message`Unexpected option or argument: ${context.buffer[0]}.`
|
|
143
|
-
};
|
|
144
|
-
} while (context.buffer.length > 0);
|
|
145
|
-
const runtime = require_dependency_runtime.createDependencyRuntimeContext();
|
|
146
|
-
const completeExec = {
|
|
147
|
-
...exec,
|
|
148
|
-
phase: "complete",
|
|
149
|
-
dependencyRuntime: runtime,
|
|
150
|
-
dependencyRegistry: runtime.registry,
|
|
151
|
-
commandPath: context.exec?.commandPath ?? exec.commandPath,
|
|
152
|
-
trace: context.exec?.trace ?? context.trace ?? exec.trace,
|
|
153
|
-
effectfulCompletionSession: createEffectfulCompletionSession()
|
|
154
|
-
};
|
|
155
|
-
const endResult = parser.complete(context.state, completeExec);
|
|
156
|
-
return endResult.success ? {
|
|
157
|
-
success: true,
|
|
158
|
-
value: shouldUnwrapAnnotatedValue ? require_internal_annotations.unwrapInjectedAnnotationWrapper(endResult.value) : endResult.value,
|
|
159
|
-
...endResult.deferred ? { deferred: true } : {},
|
|
160
|
-
...endResult.deferredKeys ? { deferredKeys: endResult.deferredKeys } : {}
|
|
161
|
-
} : {
|
|
273
|
+
const attempted = attemptParseSync(parser, args, { parseOptions: options });
|
|
274
|
+
return attempted.kind === "success" ? attempted.result : {
|
|
162
275
|
success: false,
|
|
163
|
-
error:
|
|
276
|
+
error: attempted.error
|
|
164
277
|
};
|
|
165
278
|
}
|
|
166
279
|
/**
|
|
@@ -190,52 +303,47 @@ function isBufferUnchanged(previous, current) {
|
|
|
190
303
|
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
191
304
|
*/
|
|
192
305
|
async function parseAsync(parser, args, options) {
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
phase: "parse",
|
|
198
|
-
path: [],
|
|
199
|
-
trace: require_input_trace.createInputTrace()
|
|
306
|
+
const attempted = await attemptParseAsync(parser, args, { parseOptions: options });
|
|
307
|
+
return attempted.kind === "success" ? attempted.result : {
|
|
308
|
+
success: false,
|
|
309
|
+
error: attempted.error
|
|
200
310
|
};
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Parses a complete argument list while preserving failure progress.
|
|
314
|
+
*
|
|
315
|
+
* The return mode follows the parser: synchronous parsers return immediately,
|
|
316
|
+
* while asynchronous parsers return a promise. Use this lower-level API when
|
|
317
|
+
* a caller needs the unconsumed argument suffix or matched command path.
|
|
318
|
+
*
|
|
319
|
+
* @template M The execution mode of the parser.
|
|
320
|
+
* @template T The type of the value produced by the parser.
|
|
321
|
+
* @param parser The parser to run.
|
|
322
|
+
* @param args The complete argument list to parse.
|
|
323
|
+
* @param options Optional parsing annotations.
|
|
324
|
+
* @returns A detailed success or failure result in the parser's mode.
|
|
325
|
+
* @throws {TypeError} When a synchronous dependency source extractor returns a
|
|
326
|
+
* thenable during completion-time dependency seeding.
|
|
327
|
+
* @since 1.3.0
|
|
328
|
+
*/
|
|
329
|
+
function parseDetailed(parser, args, options) {
|
|
330
|
+
return require_mode_dispatch.dispatchParserByMode(parser, (parser$1) => {
|
|
331
|
+
const attempted = attemptParseSync(parser$1, args, { parseOptions: options });
|
|
332
|
+
return attempted.kind === "success" ? attempted.result : {
|
|
209
333
|
success: false,
|
|
210
|
-
error:
|
|
334
|
+
error: attempted.error,
|
|
335
|
+
remainingArgs: attempted.remainingArgs,
|
|
336
|
+
commandPath: attempted.commandPath
|
|
211
337
|
};
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
338
|
+
}, async (parser$1) => {
|
|
339
|
+
const attempted = await attemptParseAsync(parser$1, args, { parseOptions: options });
|
|
340
|
+
return attempted.kind === "success" ? attempted.result : {
|
|
215
341
|
success: false,
|
|
216
|
-
error:
|
|
342
|
+
error: attempted.error,
|
|
343
|
+
remainingArgs: attempted.remainingArgs,
|
|
344
|
+
commandPath: attempted.commandPath
|
|
217
345
|
};
|
|
218
|
-
}
|
|
219
|
-
const runtime = require_dependency_runtime.createDependencyRuntimeContext();
|
|
220
|
-
const completeExec = {
|
|
221
|
-
...exec,
|
|
222
|
-
phase: "complete",
|
|
223
|
-
dependencyRuntime: runtime,
|
|
224
|
-
dependencyRegistry: runtime.registry,
|
|
225
|
-
commandPath: context.exec?.commandPath ?? exec.commandPath,
|
|
226
|
-
trace: context.exec?.trace ?? context.trace ?? exec.trace,
|
|
227
|
-
effectfulCompletionSession: createEffectfulCompletionSession()
|
|
228
|
-
};
|
|
229
|
-
const endResult = await parser.complete(context.state, completeExec);
|
|
230
|
-
return endResult.success ? {
|
|
231
|
-
success: true,
|
|
232
|
-
value: shouldUnwrapAnnotatedValue ? require_internal_annotations.unwrapInjectedAnnotationWrapper(endResult.value) : endResult.value,
|
|
233
|
-
...endResult.deferred ? { deferred: true } : {},
|
|
234
|
-
...endResult.deferredKeys ? { deferredKeys: endResult.deferredKeys } : {}
|
|
235
|
-
} : {
|
|
236
|
-
success: false,
|
|
237
|
-
error: endResult.error
|
|
238
|
-
};
|
|
346
|
+
});
|
|
239
347
|
}
|
|
240
348
|
/**
|
|
241
349
|
* Parses an array of command-line arguments using the provided combined parser.
|
|
@@ -904,6 +1012,8 @@ function findNextMatchedCommandArgIndex(args, matchedCommandArgIndices, start) {
|
|
|
904
1012
|
|
|
905
1013
|
//#endregion
|
|
906
1014
|
exports.annotationWrapperRequiresSourceBindingKey = annotationWrapperRequiresSourceBindingKey;
|
|
1015
|
+
exports.attemptParseAsync = attemptParseAsync;
|
|
1016
|
+
exports.attemptParseSync = attemptParseSync;
|
|
907
1017
|
exports.composeWrappedSourceMetadata = composeWrappedSourceMetadata;
|
|
908
1018
|
exports.createEffectfulCompletionSession = createEffectfulCompletionSession;
|
|
909
1019
|
exports.createParserContext = createParserContext;
|
|
@@ -919,6 +1029,7 @@ exports.getParserSuggestRuntimeNodes = getParserSuggestRuntimeNodes;
|
|
|
919
1029
|
exports.inheritParentAnnotationsKey = inheritParentAnnotationsKey;
|
|
920
1030
|
exports.parse = parse;
|
|
921
1031
|
exports.parseAsync = parseAsync;
|
|
1032
|
+
exports.parseDetailed = parseDetailed;
|
|
922
1033
|
exports.parseLanesKey = parseLanesKey;
|
|
923
1034
|
exports.parseSync = parseSync;
|
|
924
1035
|
exports.suggest = suggest;
|
|
@@ -885,6 +885,59 @@ type Result<T> = {
|
|
|
885
885
|
*/
|
|
886
886
|
readonly error: Message;
|
|
887
887
|
};
|
|
888
|
+
/**
|
|
889
|
+
* The result of a whole parser operation with failure progress preserved.
|
|
890
|
+
*
|
|
891
|
+
* Successful results have the same shape as {@link Result}. Failures also
|
|
892
|
+
* identify the unconsumed argument suffix and the canonical command path
|
|
893
|
+
* matched before the failure.
|
|
894
|
+
*
|
|
895
|
+
* @template T The type of the value produced by the parser.
|
|
896
|
+
* @since 1.3.0
|
|
897
|
+
*/
|
|
898
|
+
type DetailedParseResult<T> = Extract<Result<T>, {
|
|
899
|
+
readonly success: true;
|
|
900
|
+
}> | {
|
|
901
|
+
/** Indicates that the parsing operation failed. */
|
|
902
|
+
readonly success: false;
|
|
903
|
+
/** The error message describing why parsing failed. */
|
|
904
|
+
readonly error: Message;
|
|
905
|
+
/** The arguments that remained at the point of failure. */
|
|
906
|
+
readonly remainingArgs: readonly string[];
|
|
907
|
+
/** The canonical names of commands matched before the failure. */
|
|
908
|
+
readonly commandPath: readonly string[];
|
|
909
|
+
};
|
|
910
|
+
/** @internal */
|
|
911
|
+
type ParseAttempt<T> = {
|
|
912
|
+
readonly kind: "success";
|
|
913
|
+
readonly result: Extract<Result<T>, {
|
|
914
|
+
readonly success: true;
|
|
915
|
+
}>;
|
|
916
|
+
} | {
|
|
917
|
+
readonly kind: "failure";
|
|
918
|
+
readonly error: Message;
|
|
919
|
+
readonly remainingArgs: readonly string[];
|
|
920
|
+
readonly consumedCount: number;
|
|
921
|
+
readonly optionsTerminated: boolean;
|
|
922
|
+
readonly commandPath: readonly string[];
|
|
923
|
+
};
|
|
924
|
+
interface ParseAttemptOptions {
|
|
925
|
+
readonly mode?: "complete" | "parse-only";
|
|
926
|
+
readonly session?: EffectfulCompletionSession;
|
|
927
|
+
readonly parseOptions?: ParseOptions;
|
|
928
|
+
}
|
|
929
|
+
/** @internal */
|
|
930
|
+
declare function attemptParseSync<T>(parser: Parser<"sync", T, unknown>, args: readonly string[], options?: ParseAttemptOptions): ParseAttempt<T>;
|
|
931
|
+
/** @internal */
|
|
932
|
+
declare function attemptParseSync(parser: Parser<"sync", unknown, unknown>, args: readonly string[], options: ParseAttemptOptions & {
|
|
933
|
+
readonly mode: "parse-only";
|
|
934
|
+
}): ParseAttempt<undefined>;
|
|
935
|
+
/** @internal */
|
|
936
|
+
declare function attemptParseAsync<T>(parser: Parser<Mode, T, unknown>, args: readonly string[], options?: ParseAttemptOptions): Promise<ParseAttempt<T>>;
|
|
937
|
+
/** @internal */
|
|
938
|
+
declare function attemptParseAsync(parser: Parser<Mode, unknown, unknown>, args: readonly string[], options: ParseAttemptOptions & {
|
|
939
|
+
readonly mode: "parse-only";
|
|
940
|
+
}): Promise<ParseAttempt<undefined>>;
|
|
888
941
|
/**
|
|
889
942
|
* Parses an array of command-line arguments using the provided combined parser.
|
|
890
943
|
* This function processes the input arguments, applying the parser to each
|
|
@@ -930,6 +983,24 @@ declare function parseSync<T>(parser: Parser<"sync", T, unknown>, args: readonly
|
|
|
930
983
|
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
931
984
|
*/
|
|
932
985
|
declare function parseAsync<T>(parser: Parser<Mode, T, unknown>, args: readonly string[], options?: ParseOptions): Promise<Result<T>>;
|
|
986
|
+
/**
|
|
987
|
+
* Parses a complete argument list while preserving failure progress.
|
|
988
|
+
*
|
|
989
|
+
* The return mode follows the parser: synchronous parsers return immediately,
|
|
990
|
+
* while asynchronous parsers return a promise. Use this lower-level API when
|
|
991
|
+
* a caller needs the unconsumed argument suffix or matched command path.
|
|
992
|
+
*
|
|
993
|
+
* @template M The execution mode of the parser.
|
|
994
|
+
* @template T The type of the value produced by the parser.
|
|
995
|
+
* @param parser The parser to run.
|
|
996
|
+
* @param args The complete argument list to parse.
|
|
997
|
+
* @param options Optional parsing annotations.
|
|
998
|
+
* @returns A detailed success or failure result in the parser's mode.
|
|
999
|
+
* @throws {TypeError} When a synchronous dependency source extractor returns a
|
|
1000
|
+
* thenable during completion-time dependency seeding.
|
|
1001
|
+
* @since 1.3.0
|
|
1002
|
+
*/
|
|
1003
|
+
declare function parseDetailed<M extends Mode, T>(parser: Parser<M, T, unknown>, args: readonly string[], options?: ParseOptions): ModeValue<M, DetailedParseResult<T>>;
|
|
933
1004
|
/**
|
|
934
1005
|
* Parses an array of command-line arguments using the provided combined parser.
|
|
935
1006
|
* This function processes the input arguments, applying the parser to each
|
|
@@ -1188,4 +1259,4 @@ declare function getDocPage(parser: Parser<"sync", unknown, unknown>, argsOrOpti
|
|
|
1188
1259
|
declare function getDocPage(parser: Parser<"async", unknown, unknown>, argsOrOptions?: readonly string[] | ParseOptions, options?: ParseOptions): Promise<DocPage | undefined>;
|
|
1189
1260
|
declare function getDocPage<M extends Mode>(parser: Parser<M, unknown, unknown>, argsOrOptions?: readonly string[] | ParseOptions, options?: ParseOptions): ModeValue<M, DocPage | undefined>;
|
|
1190
1261
|
//#endregion
|
|
1191
|
-
export { CombineModes, DocState, EffectfulCompletionSession, ExecutionContext, ExecutionPhase, InferMode, InferValue, Mode, ModeIterable, ModeValue, ParseFrame, ParseLane, ParseLaneConsumptionGroup, type ParseOptions, Parser, ParserContext, ParserResult, Result, Suggestion, annotationWrapperRequiresSourceBindingKey, composeWrappedSourceMetadata, createEffectfulCompletionSession, createParserContext, defineInheritedAnnotationParser, defineParseLanes, defineSourceBindingOnlyAnnotationCompletionParser, getDelegatingSuggestRuntimeNodes, getDocPage, getDocPageAsync, getDocPageSync, getOwnParseLanes, getParserSuggestRuntimeNodes, inheritParentAnnotationsKey, parse, parseAsync, parseLanesKey, parseSync, suggest, suggestAsync, suggestSync, unmatchedNonCliDependencySourceStateMarker };
|
|
1262
|
+
export { CombineModes, DetailedParseResult, DocState, EffectfulCompletionSession, ExecutionContext, ExecutionPhase, InferMode, InferValue, Mode, ModeIterable, ModeValue, ParseAttempt, ParseFrame, ParseLane, ParseLaneConsumptionGroup, type ParseOptions, Parser, ParserContext, ParserResult, Result, Suggestion, annotationWrapperRequiresSourceBindingKey, attemptParseAsync, attemptParseSync, composeWrappedSourceMetadata, createEffectfulCompletionSession, createParserContext, defineInheritedAnnotationParser, defineParseLanes, defineSourceBindingOnlyAnnotationCompletionParser, getDelegatingSuggestRuntimeNodes, getDocPage, getDocPageAsync, getDocPageSync, getOwnParseLanes, getParserSuggestRuntimeNodes, inheritParentAnnotationsKey, parse, parseAsync, parseDetailed, parseLanesKey, parseSync, suggest, suggestAsync, suggestSync, unmatchedNonCliDependencySourceStateMarker };
|
|
@@ -885,6 +885,59 @@ type Result<T> = {
|
|
|
885
885
|
*/
|
|
886
886
|
readonly error: Message;
|
|
887
887
|
};
|
|
888
|
+
/**
|
|
889
|
+
* The result of a whole parser operation with failure progress preserved.
|
|
890
|
+
*
|
|
891
|
+
* Successful results have the same shape as {@link Result}. Failures also
|
|
892
|
+
* identify the unconsumed argument suffix and the canonical command path
|
|
893
|
+
* matched before the failure.
|
|
894
|
+
*
|
|
895
|
+
* @template T The type of the value produced by the parser.
|
|
896
|
+
* @since 1.3.0
|
|
897
|
+
*/
|
|
898
|
+
type DetailedParseResult<T> = Extract<Result<T>, {
|
|
899
|
+
readonly success: true;
|
|
900
|
+
}> | {
|
|
901
|
+
/** Indicates that the parsing operation failed. */
|
|
902
|
+
readonly success: false;
|
|
903
|
+
/** The error message describing why parsing failed. */
|
|
904
|
+
readonly error: Message;
|
|
905
|
+
/** The arguments that remained at the point of failure. */
|
|
906
|
+
readonly remainingArgs: readonly string[];
|
|
907
|
+
/** The canonical names of commands matched before the failure. */
|
|
908
|
+
readonly commandPath: readonly string[];
|
|
909
|
+
};
|
|
910
|
+
/** @internal */
|
|
911
|
+
type ParseAttempt<T> = {
|
|
912
|
+
readonly kind: "success";
|
|
913
|
+
readonly result: Extract<Result<T>, {
|
|
914
|
+
readonly success: true;
|
|
915
|
+
}>;
|
|
916
|
+
} | {
|
|
917
|
+
readonly kind: "failure";
|
|
918
|
+
readonly error: Message;
|
|
919
|
+
readonly remainingArgs: readonly string[];
|
|
920
|
+
readonly consumedCount: number;
|
|
921
|
+
readonly optionsTerminated: boolean;
|
|
922
|
+
readonly commandPath: readonly string[];
|
|
923
|
+
};
|
|
924
|
+
interface ParseAttemptOptions {
|
|
925
|
+
readonly mode?: "complete" | "parse-only";
|
|
926
|
+
readonly session?: EffectfulCompletionSession;
|
|
927
|
+
readonly parseOptions?: ParseOptions;
|
|
928
|
+
}
|
|
929
|
+
/** @internal */
|
|
930
|
+
declare function attemptParseSync<T>(parser: Parser<"sync", T, unknown>, args: readonly string[], options?: ParseAttemptOptions): ParseAttempt<T>;
|
|
931
|
+
/** @internal */
|
|
932
|
+
declare function attemptParseSync(parser: Parser<"sync", unknown, unknown>, args: readonly string[], options: ParseAttemptOptions & {
|
|
933
|
+
readonly mode: "parse-only";
|
|
934
|
+
}): ParseAttempt<undefined>;
|
|
935
|
+
/** @internal */
|
|
936
|
+
declare function attemptParseAsync<T>(parser: Parser<Mode, T, unknown>, args: readonly string[], options?: ParseAttemptOptions): Promise<ParseAttempt<T>>;
|
|
937
|
+
/** @internal */
|
|
938
|
+
declare function attemptParseAsync(parser: Parser<Mode, unknown, unknown>, args: readonly string[], options: ParseAttemptOptions & {
|
|
939
|
+
readonly mode: "parse-only";
|
|
940
|
+
}): Promise<ParseAttempt<undefined>>;
|
|
888
941
|
/**
|
|
889
942
|
* Parses an array of command-line arguments using the provided combined parser.
|
|
890
943
|
* This function processes the input arguments, applying the parser to each
|
|
@@ -930,6 +983,24 @@ declare function parseSync<T>(parser: Parser<"sync", T, unknown>, args: readonly
|
|
|
930
983
|
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
931
984
|
*/
|
|
932
985
|
declare function parseAsync<T>(parser: Parser<Mode, T, unknown>, args: readonly string[], options?: ParseOptions): Promise<Result<T>>;
|
|
986
|
+
/**
|
|
987
|
+
* Parses a complete argument list while preserving failure progress.
|
|
988
|
+
*
|
|
989
|
+
* The return mode follows the parser: synchronous parsers return immediately,
|
|
990
|
+
* while asynchronous parsers return a promise. Use this lower-level API when
|
|
991
|
+
* a caller needs the unconsumed argument suffix or matched command path.
|
|
992
|
+
*
|
|
993
|
+
* @template M The execution mode of the parser.
|
|
994
|
+
* @template T The type of the value produced by the parser.
|
|
995
|
+
* @param parser The parser to run.
|
|
996
|
+
* @param args The complete argument list to parse.
|
|
997
|
+
* @param options Optional parsing annotations.
|
|
998
|
+
* @returns A detailed success or failure result in the parser's mode.
|
|
999
|
+
* @throws {TypeError} When a synchronous dependency source extractor returns a
|
|
1000
|
+
* thenable during completion-time dependency seeding.
|
|
1001
|
+
* @since 1.3.0
|
|
1002
|
+
*/
|
|
1003
|
+
declare function parseDetailed<M extends Mode, T>(parser: Parser<M, T, unknown>, args: readonly string[], options?: ParseOptions): ModeValue<M, DetailedParseResult<T>>;
|
|
933
1004
|
/**
|
|
934
1005
|
* Parses an array of command-line arguments using the provided combined parser.
|
|
935
1006
|
* This function processes the input arguments, applying the parser to each
|
|
@@ -1188,4 +1259,4 @@ declare function getDocPage(parser: Parser<"sync", unknown, unknown>, argsOrOpti
|
|
|
1188
1259
|
declare function getDocPage(parser: Parser<"async", unknown, unknown>, argsOrOptions?: readonly string[] | ParseOptions, options?: ParseOptions): Promise<DocPage | undefined>;
|
|
1189
1260
|
declare function getDocPage<M extends Mode>(parser: Parser<M, unknown, unknown>, argsOrOptions?: readonly string[] | ParseOptions, options?: ParseOptions): ModeValue<M, DocPage | undefined>;
|
|
1190
1261
|
//#endregion
|
|
1191
|
-
export { CombineModes, DocState, EffectfulCompletionSession, ExecutionContext, ExecutionPhase, InferMode, InferValue, Mode, ModeIterable, ModeValue, ParseFrame, ParseLane, ParseLaneConsumptionGroup, type ParseOptions, Parser, ParserContext, ParserResult, Result, Suggestion, annotationWrapperRequiresSourceBindingKey, composeWrappedSourceMetadata, createEffectfulCompletionSession, createParserContext, defineInheritedAnnotationParser, defineParseLanes, defineSourceBindingOnlyAnnotationCompletionParser, getDelegatingSuggestRuntimeNodes, getDocPage, getDocPageAsync, getDocPageSync, getOwnParseLanes, getParserSuggestRuntimeNodes, inheritParentAnnotationsKey, parse, parseAsync, parseLanesKey, parseSync, suggest, suggestAsync, suggestSync, unmatchedNonCliDependencySourceStateMarker };
|
|
1262
|
+
export { CombineModes, DetailedParseResult, DocState, EffectfulCompletionSession, ExecutionContext, ExecutionPhase, InferMode, InferValue, Mode, ModeIterable, ModeValue, ParseAttempt, ParseFrame, ParseLane, ParseLaneConsumptionGroup, type ParseOptions, Parser, ParserContext, ParserResult, Result, Suggestion, annotationWrapperRequiresSourceBindingKey, attemptParseAsync, attemptParseSync, composeWrappedSourceMetadata, createEffectfulCompletionSession, createParserContext, defineInheritedAnnotationParser, defineParseLanes, defineSourceBindingOnlyAnnotationCompletionParser, getDelegatingSuggestRuntimeNodes, getDocPage, getDocPageAsync, getDocPageSync, getOwnParseLanes, getParserSuggestRuntimeNodes, inheritParentAnnotationsKey, parse, parseAsync, parseDetailed, parseLanesKey, parseSync, suggest, suggestAsync, suggestSync, unmatchedNonCliDependencySourceStateMarker };
|