@optique/core 0.10.0-dev.295 → 0.10.0-dev.297
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/constructs.cjs +200 -45
- package/dist/constructs.js +200 -45
- package/dist/dependency.cjs +163 -7
- package/dist/dependency.d.cts +58 -2
- package/dist/dependency.d.ts +58 -2
- package/dist/dependency.js +160 -7
- package/dist/index.cjs +4 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/modifiers.cjs +133 -27
- package/dist/modifiers.js +134 -28
- package/dist/parser.d.cts +9 -0
- package/dist/parser.d.ts +9 -0
- package/dist/primitives.cjs +76 -4
- package/dist/primitives.js +77 -5
- package/package.json +1 -1
package/dist/modifiers.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { formatMessage, message, text } from "./message.js";
|
|
2
|
-
import { DependencyId, WrappedDependencySourceMarker, createDependencySourceState, isPendingDependencySourceState } from "./dependency.js";
|
|
2
|
+
import { DependencyId, TransformsDependencyValueMarker, WrappedDependencySourceMarker, createDependencySourceState, isDependencySourceState, isPendingDependencySourceState, isWrappedDependencySource, transformsDependencyValue } from "./dependency.js";
|
|
3
3
|
|
|
4
4
|
//#region src/modifiers.ts
|
|
5
5
|
/**
|
|
@@ -90,6 +90,11 @@ function optional(parser) {
|
|
|
90
90
|
}, prefix);
|
|
91
91
|
for await (const s of suggestions) yield s;
|
|
92
92
|
}
|
|
93
|
+
const innerHasWrappedDependency = isWrappedDependencySource(parser);
|
|
94
|
+
const innerHasDirectDependency = isPendingDependencySourceState(syncParser.initialState);
|
|
95
|
+
const wrappedDependencyMarker = innerHasWrappedDependency ? { [WrappedDependencySourceMarker]: parser[WrappedDependencySourceMarker] } : innerHasDirectDependency ? { [WrappedDependencySourceMarker]: syncParser.initialState } : {};
|
|
96
|
+
const hasWrappedDependencySource = WrappedDependencySourceMarker in wrappedDependencyMarker;
|
|
97
|
+
const wrappedPendingState = hasWrappedDependencySource ? wrappedDependencyMarker[WrappedDependencySourceMarker] : void 0;
|
|
93
98
|
return {
|
|
94
99
|
$mode: parser.$mode,
|
|
95
100
|
$valueType: [],
|
|
@@ -100,15 +105,32 @@ function optional(parser) {
|
|
|
100
105
|
terms: parser.usage
|
|
101
106
|
}],
|
|
102
107
|
initialState: void 0,
|
|
108
|
+
...wrappedDependencyMarker,
|
|
103
109
|
parse(context) {
|
|
104
110
|
if (isAsync) return parseOptionalStyleAsync(context, parser);
|
|
105
111
|
return parseOptionalStyleSync(context, syncParser);
|
|
106
112
|
},
|
|
107
113
|
complete(state) {
|
|
108
|
-
if (typeof state === "undefined")
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
114
|
+
if (typeof state === "undefined") {
|
|
115
|
+
if (innerHasWrappedDependency && wrappedPendingState) {
|
|
116
|
+
if (!isAsync) return syncParser.complete([wrappedPendingState]);
|
|
117
|
+
return parser.complete([wrappedPendingState]);
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
success: true,
|
|
121
|
+
value: void 0
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
if (Array.isArray(state) && state.length === 1 && isPendingDependencySourceState(state[0])) {
|
|
125
|
+
if (innerHasWrappedDependency) {
|
|
126
|
+
if (!isAsync) return syncParser.complete(state);
|
|
127
|
+
return parser.complete(state);
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
success: true,
|
|
131
|
+
value: void 0
|
|
132
|
+
};
|
|
133
|
+
}
|
|
112
134
|
if (!isAsync) return syncParser.complete(state[0]);
|
|
113
135
|
return parser.complete(state[0]);
|
|
114
136
|
},
|
|
@@ -178,7 +200,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
178
200
|
for await (const s of suggestions) yield s;
|
|
179
201
|
}
|
|
180
202
|
const innerInitialState = syncParser.initialState;
|
|
181
|
-
const wrappedDependencyMarker = isPendingDependencySourceState(innerInitialState) ? { [WrappedDependencySourceMarker]: innerInitialState } : {};
|
|
203
|
+
const wrappedDependencyMarker = isPendingDependencySourceState(innerInitialState) ? { [WrappedDependencySourceMarker]: innerInitialState } : isWrappedDependencySource(parser) ? { [WrappedDependencySourceMarker]: parser[WrappedDependencySourceMarker] } : {};
|
|
182
204
|
return {
|
|
183
205
|
$mode: parser.$mode,
|
|
184
206
|
$valueType: [],
|
|
@@ -195,29 +217,108 @@ function withDefault(parser, defaultValue, options) {
|
|
|
195
217
|
return parseOptionalStyleSync(context, syncParser);
|
|
196
218
|
},
|
|
197
219
|
complete(state) {
|
|
198
|
-
if (typeof state === "undefined")
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
220
|
+
if (typeof state === "undefined") {
|
|
221
|
+
if (transformsDependencyValue(parser)) {
|
|
222
|
+
const innerResult = !isAsync ? syncParser.complete(void 0) : parser.complete(void 0);
|
|
223
|
+
const handleInnerResult = (res) => {
|
|
224
|
+
if (isDependencySourceState(res)) try {
|
|
225
|
+
const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
226
|
+
return createDependencySourceState({
|
|
227
|
+
success: true,
|
|
228
|
+
value
|
|
229
|
+
}, res[DependencyId]);
|
|
230
|
+
} catch (error) {
|
|
231
|
+
return {
|
|
232
|
+
success: false,
|
|
233
|
+
error: error instanceof WithDefaultError ? error.errorMessage : message`${text(String(error))}`
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
try {
|
|
237
|
+
const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
238
|
+
return {
|
|
239
|
+
success: true,
|
|
240
|
+
value
|
|
241
|
+
};
|
|
242
|
+
} catch (error) {
|
|
243
|
+
return {
|
|
244
|
+
success: false,
|
|
245
|
+
error: error instanceof WithDefaultError ? error.errorMessage : message`${text(String(error))}`
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
if (innerResult instanceof Promise) return innerResult.then(handleInnerResult);
|
|
250
|
+
return handleInnerResult(innerResult);
|
|
251
|
+
}
|
|
252
|
+
if (isWrappedDependencySource(parser)) try {
|
|
253
|
+
const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
254
|
+
const pendingState = parser[WrappedDependencySourceMarker];
|
|
255
|
+
return createDependencySourceState({
|
|
256
|
+
success: true,
|
|
257
|
+
value
|
|
258
|
+
}, pendingState[DependencyId]);
|
|
259
|
+
} catch (error) {
|
|
260
|
+
return {
|
|
261
|
+
success: false,
|
|
262
|
+
error: error instanceof WithDefaultError ? error.errorMessage : message`${text(String(error))}`
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
try {
|
|
266
|
+
const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
267
|
+
return {
|
|
268
|
+
success: true,
|
|
269
|
+
value
|
|
270
|
+
};
|
|
271
|
+
} catch (error) {
|
|
272
|
+
return {
|
|
273
|
+
success: false,
|
|
274
|
+
error: error instanceof WithDefaultError ? error.errorMessage : message`${text(String(error))}`
|
|
275
|
+
};
|
|
276
|
+
}
|
|
209
277
|
}
|
|
210
|
-
if (isPendingDependencySourceState(state[0]))
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
278
|
+
if (isPendingDependencySourceState(state[0])) {
|
|
279
|
+
if (transformsDependencyValue(parser)) {
|
|
280
|
+
const innerResult = !isAsync ? syncParser.complete(state) : parser.complete(state);
|
|
281
|
+
const handleInnerResult = (res) => {
|
|
282
|
+
if (isDependencySourceState(res)) try {
|
|
283
|
+
const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
284
|
+
return createDependencySourceState({
|
|
285
|
+
success: true,
|
|
286
|
+
value
|
|
287
|
+
}, res[DependencyId]);
|
|
288
|
+
} catch (error) {
|
|
289
|
+
return {
|
|
290
|
+
success: false,
|
|
291
|
+
error: error instanceof WithDefaultError ? error.errorMessage : message`${text(String(error))}`
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
try {
|
|
295
|
+
const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
296
|
+
return {
|
|
297
|
+
success: true,
|
|
298
|
+
value
|
|
299
|
+
};
|
|
300
|
+
} catch (error) {
|
|
301
|
+
return {
|
|
302
|
+
success: false,
|
|
303
|
+
error: error instanceof WithDefaultError ? error.errorMessage : message`${text(String(error))}`
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
if (innerResult instanceof Promise) return innerResult.then(handleInnerResult);
|
|
308
|
+
return handleInnerResult(innerResult);
|
|
309
|
+
}
|
|
310
|
+
try {
|
|
311
|
+
const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
312
|
+
return createDependencySourceState({
|
|
313
|
+
success: true,
|
|
314
|
+
value
|
|
315
|
+
}, state[0][DependencyId]);
|
|
316
|
+
} catch (error) {
|
|
317
|
+
return {
|
|
318
|
+
success: false,
|
|
319
|
+
error: error instanceof WithDefaultError ? error.errorMessage : message`${text(String(error))}`
|
|
320
|
+
};
|
|
321
|
+
}
|
|
221
322
|
}
|
|
222
323
|
if (!isAsync) return syncParser.complete(state[0]);
|
|
223
324
|
return parser.complete(state[0]);
|
|
@@ -300,10 +401,15 @@ function map(parser, transform) {
|
|
|
300
401
|
};
|
|
301
402
|
return res;
|
|
302
403
|
};
|
|
404
|
+
const dependencyMarkers = isWrappedDependencySource(parser) ? {
|
|
405
|
+
[WrappedDependencySourceMarker]: parser[WrappedDependencySourceMarker],
|
|
406
|
+
[TransformsDependencyValueMarker]: true
|
|
407
|
+
} : {};
|
|
303
408
|
return {
|
|
304
409
|
...parser,
|
|
305
410
|
$valueType: [],
|
|
306
411
|
complete,
|
|
412
|
+
...dependencyMarkers,
|
|
307
413
|
getDocFragments(state, _defaultValue) {
|
|
308
414
|
return parser.getDocFragments(state, void 0);
|
|
309
415
|
}
|
package/dist/parser.d.cts
CHANGED
|
@@ -187,6 +187,15 @@ interface ParserContext<TState> {
|
|
|
187
187
|
* @since 0.7.0
|
|
188
188
|
*/
|
|
189
189
|
readonly usage: Usage;
|
|
190
|
+
/**
|
|
191
|
+
* A registry containing resolved dependency values from DependencySource parsers.
|
|
192
|
+
* This is used during shell completion to provide suggestions based on
|
|
193
|
+
* the actual dependency values that have been parsed, rather than defaults.
|
|
194
|
+
* The type is `unknown` to avoid circular dependency issues; the actual type
|
|
195
|
+
* is `DependencyRegistry` from `./dependency.ts`.
|
|
196
|
+
* @since 0.10.0
|
|
197
|
+
*/
|
|
198
|
+
readonly dependencyRegistry?: unknown;
|
|
190
199
|
}
|
|
191
200
|
/**
|
|
192
201
|
* Represents a suggestion for command-line completion or guidance.
|
package/dist/parser.d.ts
CHANGED
|
@@ -187,6 +187,15 @@ interface ParserContext<TState> {
|
|
|
187
187
|
* @since 0.7.0
|
|
188
188
|
*/
|
|
189
189
|
readonly usage: Usage;
|
|
190
|
+
/**
|
|
191
|
+
* A registry containing resolved dependency values from DependencySource parsers.
|
|
192
|
+
* This is used during shell completion to provide suggestions based on
|
|
193
|
+
* the actual dependency values that have been parsed, rather than defaults.
|
|
194
|
+
* The type is `unknown` to avoid circular dependency issues; the actual type
|
|
195
|
+
* is `DependencyRegistry` from `./dependency.ts`.
|
|
196
|
+
* @since 0.10.0
|
|
197
|
+
*/
|
|
198
|
+
readonly dependencyRegistry?: unknown;
|
|
190
199
|
}
|
|
191
200
|
/**
|
|
192
201
|
* Represents a suggestion for command-line completion or guidance.
|
package/dist/primitives.cjs
CHANGED
|
@@ -53,6 +53,42 @@ function constant(value) {
|
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
|
+
* Internal helper to get suggestions from a value parser, using dependency values
|
|
57
|
+
* if the parser is a derived parser and dependency values are available.
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
function* getSuggestionsWithDependency(valueParser, prefix, dependencyRegistry) {
|
|
61
|
+
if (!valueParser.suggest) return;
|
|
62
|
+
if (require_dependency.isDerivedValueParser(valueParser) && require_dependency.SuggestWithDependency in valueParser) {
|
|
63
|
+
const derived = valueParser;
|
|
64
|
+
const suggestWithDep = derived[require_dependency.SuggestWithDependency];
|
|
65
|
+
if (suggestWithDep && dependencyRegistry) {
|
|
66
|
+
const depIds = require_dependency.DependencyIds in derived ? derived[require_dependency.DependencyIds] : [derived[require_dependency.DependencyId]];
|
|
67
|
+
const defaults = require_dependency.DefaultValues in derived ? derived[require_dependency.DefaultValues]?.() : void 0;
|
|
68
|
+
const registry = dependencyRegistry;
|
|
69
|
+
const dependencyValues = [];
|
|
70
|
+
let hasAnyValue = false;
|
|
71
|
+
for (let i = 0; i < depIds.length; i++) {
|
|
72
|
+
const depId = depIds[i];
|
|
73
|
+
if (registry.has(depId)) {
|
|
74
|
+
dependencyValues.push(registry.get(depId));
|
|
75
|
+
hasAnyValue = true;
|
|
76
|
+
} else if (defaults && i < defaults.length) dependencyValues.push(defaults[i]);
|
|
77
|
+
else {
|
|
78
|
+
yield* valueParser.suggest(prefix);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (hasAnyValue) {
|
|
83
|
+
const depValue = depIds.length === 1 ? dependencyValues[0] : dependencyValues;
|
|
84
|
+
yield* suggestWithDep(prefix, depValue);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
yield* valueParser.suggest(prefix);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
56
92
|
* Internal sync helper for option suggest functionality.
|
|
57
93
|
* @internal
|
|
58
94
|
*/
|
|
@@ -64,7 +100,7 @@ function* suggestOptionSync(optionNames$1, valueParser, hidden, context, prefix)
|
|
|
64
100
|
const valuePart = prefix.slice(equalsIndex + 1);
|
|
65
101
|
if (optionNames$1.includes(optionPart)) {
|
|
66
102
|
if (valueParser && valueParser.suggest) {
|
|
67
|
-
const valueSuggestions = valueParser.
|
|
103
|
+
const valueSuggestions = getSuggestionsWithDependency(valueParser, valuePart, context.dependencyRegistry);
|
|
68
104
|
for (const suggestion of valueSuggestions) if (suggestion.kind === "literal") yield {
|
|
69
105
|
kind: "literal",
|
|
70
106
|
text: `${optionPart}=${suggestion.text}`,
|
|
@@ -93,9 +129,45 @@ function* suggestOptionSync(optionNames$1, valueParser, hidden, context, prefix)
|
|
|
93
129
|
const lastToken = context.buffer[context.buffer.length - 1];
|
|
94
130
|
if (optionNames$1.includes(lastToken)) shouldSuggestValues = true;
|
|
95
131
|
} else if (context.state === void 0 && context.buffer.length === 0) shouldSuggestValues = true;
|
|
96
|
-
if (shouldSuggestValues) yield* valueParser.
|
|
132
|
+
if (shouldSuggestValues) yield* getSuggestionsWithDependency(valueParser, prefix, context.dependencyRegistry);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Internal async helper to get suggestions from a value parser, using dependency values
|
|
138
|
+
* if the parser is a derived parser and dependency values are available.
|
|
139
|
+
* @internal
|
|
140
|
+
*/
|
|
141
|
+
async function* getSuggestionsWithDependencyAsync(valueParser, prefix, dependencyRegistry) {
|
|
142
|
+
if (!valueParser.suggest) return;
|
|
143
|
+
if (require_dependency.isDerivedValueParser(valueParser) && require_dependency.SuggestWithDependency in valueParser) {
|
|
144
|
+
const derived = valueParser;
|
|
145
|
+
const suggestWithDep = derived[require_dependency.SuggestWithDependency];
|
|
146
|
+
if (suggestWithDep && dependencyRegistry) {
|
|
147
|
+
const depIds = require_dependency.DependencyIds in derived ? derived[require_dependency.DependencyIds] : [derived[require_dependency.DependencyId]];
|
|
148
|
+
const defaults = require_dependency.DefaultValues in derived ? derived[require_dependency.DefaultValues]?.() : void 0;
|
|
149
|
+
const registry = dependencyRegistry;
|
|
150
|
+
const dependencyValues = [];
|
|
151
|
+
let hasAnyValue = false;
|
|
152
|
+
for (let i = 0; i < depIds.length; i++) {
|
|
153
|
+
const depId = depIds[i];
|
|
154
|
+
if (registry.has(depId)) {
|
|
155
|
+
dependencyValues.push(registry.get(depId));
|
|
156
|
+
hasAnyValue = true;
|
|
157
|
+
} else if (defaults && i < defaults.length) dependencyValues.push(defaults[i]);
|
|
158
|
+
else {
|
|
159
|
+
for await (const suggestion of valueParser.suggest(prefix)) yield suggestion;
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (hasAnyValue) {
|
|
164
|
+
const depValue = depIds.length === 1 ? dependencyValues[0] : dependencyValues;
|
|
165
|
+
for await (const suggestion of suggestWithDep(prefix, depValue)) yield suggestion;
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
97
168
|
}
|
|
98
169
|
}
|
|
170
|
+
for await (const suggestion of valueParser.suggest(prefix)) yield suggestion;
|
|
99
171
|
}
|
|
100
172
|
/**
|
|
101
173
|
* Internal async helper for option suggest functionality.
|
|
@@ -109,7 +181,7 @@ async function* suggestOptionAsync(optionNames$1, valueParser, hidden, context,
|
|
|
109
181
|
const valuePart = prefix.slice(equalsIndex + 1);
|
|
110
182
|
if (optionNames$1.includes(optionPart)) {
|
|
111
183
|
if (valueParser && valueParser.suggest) {
|
|
112
|
-
const valueSuggestions = valueParser.
|
|
184
|
+
const valueSuggestions = getSuggestionsWithDependencyAsync(valueParser, valuePart, context.dependencyRegistry);
|
|
113
185
|
for await (const suggestion of valueSuggestions) if (suggestion.kind === "literal") yield {
|
|
114
186
|
kind: "literal",
|
|
115
187
|
text: `${optionPart}=${suggestion.text}`,
|
|
@@ -138,7 +210,7 @@ async function* suggestOptionAsync(optionNames$1, valueParser, hidden, context,
|
|
|
138
210
|
const lastToken = context.buffer[context.buffer.length - 1];
|
|
139
211
|
if (optionNames$1.includes(lastToken)) shouldSuggestValues = true;
|
|
140
212
|
} else if (context.state === void 0 && context.buffer.length === 0) shouldSuggestValues = true;
|
|
141
|
-
if (shouldSuggestValues) for await (const suggestion of valueParser.
|
|
213
|
+
if (shouldSuggestValues) for await (const suggestion of getSuggestionsWithDependencyAsync(valueParser, prefix, context.dependencyRegistry)) yield suggestion;
|
|
142
214
|
}
|
|
143
215
|
}
|
|
144
216
|
}
|
package/dist/primitives.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { message, metavar, optionName, optionNames } from "./message.js";
|
|
2
|
-
import { DependencyId, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState } from "./dependency.js";
|
|
2
|
+
import { DefaultValues, DependencyId, DependencyIds, SuggestWithDependency, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState } from "./dependency.js";
|
|
3
3
|
import { extractCommandNames, extractOptionNames } from "./usage.js";
|
|
4
4
|
import { DEFAULT_FIND_SIMILAR_OPTIONS, createErrorWithSuggestions, findSimilar } from "./suggestion.js";
|
|
5
5
|
import { isValueParser } from "./valueparser.js";
|
|
@@ -53,6 +53,42 @@ function constant(value) {
|
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
|
+
* Internal helper to get suggestions from a value parser, using dependency values
|
|
57
|
+
* if the parser is a derived parser and dependency values are available.
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
function* getSuggestionsWithDependency(valueParser, prefix, dependencyRegistry) {
|
|
61
|
+
if (!valueParser.suggest) return;
|
|
62
|
+
if (isDerivedValueParser(valueParser) && SuggestWithDependency in valueParser) {
|
|
63
|
+
const derived = valueParser;
|
|
64
|
+
const suggestWithDep = derived[SuggestWithDependency];
|
|
65
|
+
if (suggestWithDep && dependencyRegistry) {
|
|
66
|
+
const depIds = DependencyIds in derived ? derived[DependencyIds] : [derived[DependencyId]];
|
|
67
|
+
const defaults = DefaultValues in derived ? derived[DefaultValues]?.() : void 0;
|
|
68
|
+
const registry = dependencyRegistry;
|
|
69
|
+
const dependencyValues = [];
|
|
70
|
+
let hasAnyValue = false;
|
|
71
|
+
for (let i = 0; i < depIds.length; i++) {
|
|
72
|
+
const depId = depIds[i];
|
|
73
|
+
if (registry.has(depId)) {
|
|
74
|
+
dependencyValues.push(registry.get(depId));
|
|
75
|
+
hasAnyValue = true;
|
|
76
|
+
} else if (defaults && i < defaults.length) dependencyValues.push(defaults[i]);
|
|
77
|
+
else {
|
|
78
|
+
yield* valueParser.suggest(prefix);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (hasAnyValue) {
|
|
83
|
+
const depValue = depIds.length === 1 ? dependencyValues[0] : dependencyValues;
|
|
84
|
+
yield* suggestWithDep(prefix, depValue);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
yield* valueParser.suggest(prefix);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
56
92
|
* Internal sync helper for option suggest functionality.
|
|
57
93
|
* @internal
|
|
58
94
|
*/
|
|
@@ -64,7 +100,7 @@ function* suggestOptionSync(optionNames$1, valueParser, hidden, context, prefix)
|
|
|
64
100
|
const valuePart = prefix.slice(equalsIndex + 1);
|
|
65
101
|
if (optionNames$1.includes(optionPart)) {
|
|
66
102
|
if (valueParser && valueParser.suggest) {
|
|
67
|
-
const valueSuggestions = valueParser.
|
|
103
|
+
const valueSuggestions = getSuggestionsWithDependency(valueParser, valuePart, context.dependencyRegistry);
|
|
68
104
|
for (const suggestion of valueSuggestions) if (suggestion.kind === "literal") yield {
|
|
69
105
|
kind: "literal",
|
|
70
106
|
text: `${optionPart}=${suggestion.text}`,
|
|
@@ -93,9 +129,45 @@ function* suggestOptionSync(optionNames$1, valueParser, hidden, context, prefix)
|
|
|
93
129
|
const lastToken = context.buffer[context.buffer.length - 1];
|
|
94
130
|
if (optionNames$1.includes(lastToken)) shouldSuggestValues = true;
|
|
95
131
|
} else if (context.state === void 0 && context.buffer.length === 0) shouldSuggestValues = true;
|
|
96
|
-
if (shouldSuggestValues) yield* valueParser.
|
|
132
|
+
if (shouldSuggestValues) yield* getSuggestionsWithDependency(valueParser, prefix, context.dependencyRegistry);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Internal async helper to get suggestions from a value parser, using dependency values
|
|
138
|
+
* if the parser is a derived parser and dependency values are available.
|
|
139
|
+
* @internal
|
|
140
|
+
*/
|
|
141
|
+
async function* getSuggestionsWithDependencyAsync(valueParser, prefix, dependencyRegistry) {
|
|
142
|
+
if (!valueParser.suggest) return;
|
|
143
|
+
if (isDerivedValueParser(valueParser) && SuggestWithDependency in valueParser) {
|
|
144
|
+
const derived = valueParser;
|
|
145
|
+
const suggestWithDep = derived[SuggestWithDependency];
|
|
146
|
+
if (suggestWithDep && dependencyRegistry) {
|
|
147
|
+
const depIds = DependencyIds in derived ? derived[DependencyIds] : [derived[DependencyId]];
|
|
148
|
+
const defaults = DefaultValues in derived ? derived[DefaultValues]?.() : void 0;
|
|
149
|
+
const registry = dependencyRegistry;
|
|
150
|
+
const dependencyValues = [];
|
|
151
|
+
let hasAnyValue = false;
|
|
152
|
+
for (let i = 0; i < depIds.length; i++) {
|
|
153
|
+
const depId = depIds[i];
|
|
154
|
+
if (registry.has(depId)) {
|
|
155
|
+
dependencyValues.push(registry.get(depId));
|
|
156
|
+
hasAnyValue = true;
|
|
157
|
+
} else if (defaults && i < defaults.length) dependencyValues.push(defaults[i]);
|
|
158
|
+
else {
|
|
159
|
+
for await (const suggestion of valueParser.suggest(prefix)) yield suggestion;
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (hasAnyValue) {
|
|
164
|
+
const depValue = depIds.length === 1 ? dependencyValues[0] : dependencyValues;
|
|
165
|
+
for await (const suggestion of suggestWithDep(prefix, depValue)) yield suggestion;
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
97
168
|
}
|
|
98
169
|
}
|
|
170
|
+
for await (const suggestion of valueParser.suggest(prefix)) yield suggestion;
|
|
99
171
|
}
|
|
100
172
|
/**
|
|
101
173
|
* Internal async helper for option suggest functionality.
|
|
@@ -109,7 +181,7 @@ async function* suggestOptionAsync(optionNames$1, valueParser, hidden, context,
|
|
|
109
181
|
const valuePart = prefix.slice(equalsIndex + 1);
|
|
110
182
|
if (optionNames$1.includes(optionPart)) {
|
|
111
183
|
if (valueParser && valueParser.suggest) {
|
|
112
|
-
const valueSuggestions = valueParser.
|
|
184
|
+
const valueSuggestions = getSuggestionsWithDependencyAsync(valueParser, valuePart, context.dependencyRegistry);
|
|
113
185
|
for await (const suggestion of valueSuggestions) if (suggestion.kind === "literal") yield {
|
|
114
186
|
kind: "literal",
|
|
115
187
|
text: `${optionPart}=${suggestion.text}`,
|
|
@@ -138,7 +210,7 @@ async function* suggestOptionAsync(optionNames$1, valueParser, hidden, context,
|
|
|
138
210
|
const lastToken = context.buffer[context.buffer.length - 1];
|
|
139
211
|
if (optionNames$1.includes(lastToken)) shouldSuggestValues = true;
|
|
140
212
|
} else if (context.state === void 0 && context.buffer.length === 0) shouldSuggestValues = true;
|
|
141
|
-
if (shouldSuggestValues) for await (const suggestion of valueParser.
|
|
213
|
+
if (shouldSuggestValues) for await (const suggestion of getSuggestionsWithDependencyAsync(valueParser, prefix, context.dependencyRegistry)) yield suggestion;
|
|
142
214
|
}
|
|
143
215
|
}
|
|
144
216
|
}
|