@optique/core 1.0.15-dev.2812 → 1.0.15-dev.2816
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/completion.cjs +352 -38
- package/dist/completion.js +352 -38
- package/dist/internal/joined-file-suggestion.cjs +69 -0
- package/dist/internal/joined-file-suggestion.js +66 -0
- package/dist/modifiers.cjs +13 -8
- package/dist/modifiers.js +13 -8
- package/dist/primitives.cjs +23 -26
- package/dist/primitives.js +23 -26
- package/dist/suggestion.cjs +3 -1
- package/dist/suggestion.js +3 -1
- package/package.json +1 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
//#region src/internal/joined-file-suggestion.ts
|
|
2
|
+
const joinedFiles = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
/**
|
|
4
|
+
* Keeps a joined file fallback's origin available to the Bash encoder.
|
|
5
|
+
* Other shells retain the existing literal representation.
|
|
6
|
+
* @param prefix The option name and delimiter.
|
|
7
|
+
* @param file The original file suggestion.
|
|
8
|
+
* @param value The value prefix being completed.
|
|
9
|
+
* @returns The literal fallback with private file metadata.
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
function joinedFileSuggestion(prefix, file, value) {
|
|
13
|
+
const literal = {
|
|
14
|
+
kind: "literal",
|
|
15
|
+
text: prefix + (file.pattern ?? ""),
|
|
16
|
+
description: file.description
|
|
17
|
+
};
|
|
18
|
+
if (file.pattern === void 0 || file.pattern === value) joinedFiles.set(literal, {
|
|
19
|
+
files: [{
|
|
20
|
+
prefix,
|
|
21
|
+
file
|
|
22
|
+
}],
|
|
23
|
+
literal: false
|
|
24
|
+
});
|
|
25
|
+
return literal;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Retrieves the originating file suggestion for a joined literal fallback.
|
|
29
|
+
* @param suggestion The suggestion to inspect.
|
|
30
|
+
* @returns Its private file metadata, if present.
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
function getJoinedFileSuggestion(suggestion) {
|
|
34
|
+
return joinedFiles.get(suggestion);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Preserves file origins when equal literal fallbacks are deduplicated.
|
|
38
|
+
* @param target The retained suggestion.
|
|
39
|
+
* @param source The duplicate suggestion.
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
42
|
+
function mergeJoinedFileSuggestions(target, source) {
|
|
43
|
+
const a = joinedFiles.get(target);
|
|
44
|
+
const b = joinedFiles.get(source);
|
|
45
|
+
if (a === void 0 && b === void 0) return;
|
|
46
|
+
const files = [...a?.files ?? [], ...b?.files ?? []];
|
|
47
|
+
const seen = /* @__PURE__ */ new Set();
|
|
48
|
+
joinedFiles.set(target, {
|
|
49
|
+
literal: (a?.literal ?? true) || (b?.literal ?? true),
|
|
50
|
+
files: files.filter(({ prefix, file }) => {
|
|
51
|
+
const key = JSON.stringify([
|
|
52
|
+
prefix,
|
|
53
|
+
file.type,
|
|
54
|
+
file.pattern,
|
|
55
|
+
file.includeHidden === true,
|
|
56
|
+
file.extensions?.toSorted()
|
|
57
|
+
]);
|
|
58
|
+
if (seen.has(key)) return false;
|
|
59
|
+
seen.add(key);
|
|
60
|
+
return true;
|
|
61
|
+
})
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
export { getJoinedFileSuggestion, joinedFileSuggestion, mergeJoinedFileSuggestions };
|
package/dist/modifiers.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const require_annotations = require('./internal/annotations.cjs');
|
|
2
|
+
const require_joined_file_suggestion = require('./internal/joined-file-suggestion.cjs');
|
|
2
3
|
const require_message = require('./message.cjs');
|
|
3
4
|
const require_command_doc_metadata = require('./internal/command-doc-metadata.cjs');
|
|
4
5
|
const require_passthrough = require('./internal/passthrough.cjs');
|
|
@@ -1294,14 +1295,16 @@ function multiple(parser, options = {}) {
|
|
|
1294
1295
|
};
|
|
1295
1296
|
return require_mode_dispatch.dispatchIterableByMode(parser.mode, function* () {
|
|
1296
1297
|
const selectedValues = collectSelectedValuesSync();
|
|
1297
|
-
const emitted = /* @__PURE__ */ new
|
|
1298
|
+
const emitted = /* @__PURE__ */ new Map();
|
|
1298
1299
|
const yieldUnique = function* (suggestions) {
|
|
1299
1300
|
for (const s of suggestions) {
|
|
1300
1301
|
const key = suggestionKey(s);
|
|
1301
|
-
if (shouldInclude(selectedValues, s)
|
|
1302
|
-
|
|
1302
|
+
if (!shouldInclude(selectedValues, s)) continue;
|
|
1303
|
+
const existing = emitted.get(key);
|
|
1304
|
+
if (existing === void 0) {
|
|
1305
|
+
emitted.set(key, s);
|
|
1303
1306
|
yield s;
|
|
1304
|
-
}
|
|
1307
|
+
} else require_joined_file_suggestion.mergeJoinedFileSuggestions(existing, s);
|
|
1305
1308
|
}
|
|
1306
1309
|
};
|
|
1307
1310
|
let shouldTryFallback = false;
|
|
@@ -1314,14 +1317,16 @@ function multiple(parser, options = {}) {
|
|
|
1314
1317
|
if (shouldTryFallback) yield* yieldUnique(syncParser.suggest(require_execution_context.withChildContext(context, itemIndex, suggestFallbackState), prefix));
|
|
1315
1318
|
}, async function* () {
|
|
1316
1319
|
const selectedValues = await collectSelectedValuesAsync();
|
|
1317
|
-
const emitted = /* @__PURE__ */ new
|
|
1320
|
+
const emitted = /* @__PURE__ */ new Map();
|
|
1318
1321
|
const yieldUnique = async function* (suggestions) {
|
|
1319
1322
|
for await (const s of suggestions) {
|
|
1320
1323
|
const key = suggestionKey(s);
|
|
1321
|
-
if (shouldInclude(selectedValues, s)
|
|
1322
|
-
|
|
1324
|
+
if (!shouldInclude(selectedValues, s)) continue;
|
|
1325
|
+
const existing = emitted.get(key);
|
|
1326
|
+
if (existing === void 0) {
|
|
1327
|
+
emitted.set(key, s);
|
|
1323
1328
|
yield s;
|
|
1324
|
-
}
|
|
1329
|
+
} else require_joined_file_suggestion.mergeJoinedFileSuggestions(existing, s);
|
|
1325
1330
|
}
|
|
1326
1331
|
};
|
|
1327
1332
|
let shouldTryFallback = false;
|
package/dist/modifiers.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { annotateFreshArray, annotationKey, getAnnotations, inheritAnnotations, isInjectedAnnotationWrapper, unwrapInjectedAnnotationWrapper } from "./internal/annotations.js";
|
|
2
|
+
import { mergeJoinedFileSuggestions } from "./internal/joined-file-suggestion.js";
|
|
2
3
|
import { formatMessage, message, text } from "./message.js";
|
|
3
4
|
import { getCommandDocMetadata, withCommandDocMetadata } from "./internal/command-doc-metadata.js";
|
|
4
5
|
import { defineKnownCompletionLookup, defineOptionMatch, definePassThroughPriority, getKnownCompletion, getOptionMatch, getPassThroughPriority } from "./internal/passthrough.js";
|
|
@@ -1294,14 +1295,16 @@ function multiple(parser, options = {}) {
|
|
|
1294
1295
|
};
|
|
1295
1296
|
return dispatchIterableByMode(parser.mode, function* () {
|
|
1296
1297
|
const selectedValues = collectSelectedValuesSync();
|
|
1297
|
-
const emitted = /* @__PURE__ */ new
|
|
1298
|
+
const emitted = /* @__PURE__ */ new Map();
|
|
1298
1299
|
const yieldUnique = function* (suggestions) {
|
|
1299
1300
|
for (const s of suggestions) {
|
|
1300
1301
|
const key = suggestionKey(s);
|
|
1301
|
-
if (shouldInclude(selectedValues, s)
|
|
1302
|
-
|
|
1302
|
+
if (!shouldInclude(selectedValues, s)) continue;
|
|
1303
|
+
const existing = emitted.get(key);
|
|
1304
|
+
if (existing === void 0) {
|
|
1305
|
+
emitted.set(key, s);
|
|
1303
1306
|
yield s;
|
|
1304
|
-
}
|
|
1307
|
+
} else mergeJoinedFileSuggestions(existing, s);
|
|
1305
1308
|
}
|
|
1306
1309
|
};
|
|
1307
1310
|
let shouldTryFallback = false;
|
|
@@ -1314,14 +1317,16 @@ function multiple(parser, options = {}) {
|
|
|
1314
1317
|
if (shouldTryFallback) yield* yieldUnique(syncParser.suggest(withChildContext(context, itemIndex, suggestFallbackState), prefix));
|
|
1315
1318
|
}, async function* () {
|
|
1316
1319
|
const selectedValues = await collectSelectedValuesAsync();
|
|
1317
|
-
const emitted = /* @__PURE__ */ new
|
|
1320
|
+
const emitted = /* @__PURE__ */ new Map();
|
|
1318
1321
|
const yieldUnique = async function* (suggestions) {
|
|
1319
1322
|
for await (const s of suggestions) {
|
|
1320
1323
|
const key = suggestionKey(s);
|
|
1321
|
-
if (shouldInclude(selectedValues, s)
|
|
1322
|
-
|
|
1324
|
+
if (!shouldInclude(selectedValues, s)) continue;
|
|
1325
|
+
const existing = emitted.get(key);
|
|
1326
|
+
if (existing === void 0) {
|
|
1327
|
+
emitted.set(key, s);
|
|
1323
1328
|
yield s;
|
|
1324
|
-
}
|
|
1329
|
+
} else mergeJoinedFileSuggestions(existing, s);
|
|
1325
1330
|
}
|
|
1326
1331
|
};
|
|
1327
1332
|
let shouldTryFallback = false;
|
package/dist/primitives.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const require_annotations = require('./internal/annotations.cjs');
|
|
2
|
+
const require_joined_file_suggestion = require('./internal/joined-file-suggestion.cjs');
|
|
2
3
|
const require_message = require('./message.cjs');
|
|
3
4
|
const require_command_doc_metadata = require('./internal/command-doc-metadata.cjs');
|
|
4
5
|
const require_passthrough = require('./internal/passthrough.cjs');
|
|
@@ -236,34 +237,34 @@ function* getSuggestionsWithDependency(valueParser, prefix, dependencyRegistry,
|
|
|
236
237
|
}
|
|
237
238
|
yield* valueParser.suggest(prefix);
|
|
238
239
|
}
|
|
240
|
+
/** Returns the joined prefix accepted by option parsing. */
|
|
241
|
+
function joinedOptionPrefix(names, input) {
|
|
242
|
+
return names.filter((name) => name.startsWith("--") || name.startsWith("/") || name.startsWith("-") && name.length > 2).map((name) => name + (name.startsWith("/") ? ":" : "=")).find((prefix) => input.startsWith(prefix));
|
|
243
|
+
}
|
|
239
244
|
/**
|
|
240
245
|
* Internal sync helper for option suggest functionality.
|
|
241
246
|
* @internal
|
|
242
247
|
*/
|
|
243
248
|
function* suggestOptionSync(optionNames$1, valueParser, hidden, description, context, prefix) {
|
|
244
249
|
if (hidden || context.optionsTerminated) return;
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
const
|
|
250
|
+
const expectingValue = context.buffer.length > 0 && optionNames$1.includes(context.buffer[context.buffer.length - 1]);
|
|
251
|
+
const joinedPrefix = joinedOptionPrefix(optionNames$1, prefix);
|
|
252
|
+
if (joinedPrefix !== void 0 && !expectingValue) {
|
|
253
|
+
const optionPart = joinedPrefix.slice(0, -1);
|
|
254
|
+
const valuePart = prefix.slice(joinedPrefix.length);
|
|
249
255
|
if (optionNames$1.includes(optionPart)) {
|
|
250
256
|
if (valueParser && valueParser.suggest) {
|
|
251
257
|
const valueSuggestions = getSuggestionsWithDependency(valueParser, valuePart, context.dependencyRegistry, context.exec);
|
|
252
258
|
for (const suggestion of valueSuggestions) if (suggestion.kind === "literal") yield {
|
|
253
259
|
kind: "literal",
|
|
254
|
-
text: `${
|
|
255
|
-
description: suggestion.description
|
|
256
|
-
};
|
|
257
|
-
else yield {
|
|
258
|
-
kind: "literal",
|
|
259
|
-
text: `${optionPart}=${suggestion.pattern || ""}`,
|
|
260
|
+
text: `${joinedPrefix}${suggestion.text}`,
|
|
260
261
|
description: suggestion.description
|
|
261
262
|
};
|
|
263
|
+
else yield require_joined_file_suggestion.joinedFileSuggestion(joinedPrefix, suggestion, valuePart);
|
|
262
264
|
}
|
|
263
265
|
}
|
|
264
266
|
} else {
|
|
265
|
-
|
|
266
|
-
if (!expectingValue && (prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/"))) {
|
|
267
|
+
if (!expectingValue && (prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/") || prefix.startsWith("+"))) {
|
|
267
268
|
for (const optionName$1 of optionNames$1) if (optionName$1.startsWith(prefix)) {
|
|
268
269
|
if (prefix === "-" && optionName$1.length !== 2) continue;
|
|
269
270
|
yield {
|
|
@@ -278,7 +279,7 @@ function* suggestOptionSync(optionNames$1, valueParser, hidden, description, con
|
|
|
278
279
|
if (context.buffer.length > 0) {
|
|
279
280
|
const lastToken = context.buffer[context.buffer.length - 1];
|
|
280
281
|
if (optionNames$1.includes(lastToken)) shouldSuggestValues = true;
|
|
281
|
-
} else if (require_annotation_state.isAnnotationWrappedInitialState(context.state) && context.buffer.length === 0 && (context.exec?.path?.length ?? 0) === 0 && !(prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/"))) shouldSuggestValues = true;
|
|
282
|
+
} else if (require_annotation_state.isAnnotationWrappedInitialState(context.state) && context.buffer.length === 0 && (context.exec?.path?.length ?? 0) === 0 && !(prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/") || prefix.startsWith("+"))) shouldSuggestValues = true;
|
|
282
283
|
if (shouldSuggestValues) yield* getSuggestionsWithDependency(valueParser, prefix, context.dependencyRegistry, context.exec);
|
|
283
284
|
}
|
|
284
285
|
}
|
|
@@ -327,28 +328,24 @@ async function* getSuggestionsWithDependencyAsync(valueParser, prefix, dependenc
|
|
|
327
328
|
*/
|
|
328
329
|
async function* suggestOptionAsync(optionNames$1, valueParser, hidden, description, context, prefix) {
|
|
329
330
|
if (hidden || context.optionsTerminated) return;
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const
|
|
331
|
+
const expectingValue = context.buffer.length > 0 && optionNames$1.includes(context.buffer[context.buffer.length - 1]);
|
|
332
|
+
const joinedPrefix = joinedOptionPrefix(optionNames$1, prefix);
|
|
333
|
+
if (joinedPrefix !== void 0 && !expectingValue) {
|
|
334
|
+
const optionPart = joinedPrefix.slice(0, -1);
|
|
335
|
+
const valuePart = prefix.slice(joinedPrefix.length);
|
|
334
336
|
if (optionNames$1.includes(optionPart)) {
|
|
335
337
|
if (valueParser && valueParser.suggest) {
|
|
336
338
|
const valueSuggestions = getSuggestionsWithDependencyAsync(valueParser, valuePart, context.dependencyRegistry, context.exec);
|
|
337
339
|
for await (const suggestion of valueSuggestions) if (suggestion.kind === "literal") yield {
|
|
338
340
|
kind: "literal",
|
|
339
|
-
text: `${
|
|
340
|
-
description: suggestion.description
|
|
341
|
-
};
|
|
342
|
-
else yield {
|
|
343
|
-
kind: "literal",
|
|
344
|
-
text: `${optionPart}=${suggestion.pattern || ""}`,
|
|
341
|
+
text: `${joinedPrefix}${suggestion.text}`,
|
|
345
342
|
description: suggestion.description
|
|
346
343
|
};
|
|
344
|
+
else yield require_joined_file_suggestion.joinedFileSuggestion(joinedPrefix, suggestion, valuePart);
|
|
347
345
|
}
|
|
348
346
|
}
|
|
349
347
|
} else {
|
|
350
|
-
|
|
351
|
-
if (!expectingValue && (prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/"))) {
|
|
348
|
+
if (!expectingValue && (prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/") || prefix.startsWith("+"))) {
|
|
352
349
|
for (const optionName$1 of optionNames$1) if (optionName$1.startsWith(prefix)) {
|
|
353
350
|
if (prefix === "-" && optionName$1.length !== 2) continue;
|
|
354
351
|
yield {
|
|
@@ -363,7 +360,7 @@ async function* suggestOptionAsync(optionNames$1, valueParser, hidden, descripti
|
|
|
363
360
|
if (context.buffer.length > 0) {
|
|
364
361
|
const lastToken = context.buffer[context.buffer.length - 1];
|
|
365
362
|
if (optionNames$1.includes(lastToken)) shouldSuggestValues = true;
|
|
366
|
-
} else if (require_annotation_state.isAnnotationWrappedInitialState(context.state) && context.buffer.length === 0 && (context.exec?.path?.length ?? 0) === 0 && !(prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/"))) shouldSuggestValues = true;
|
|
363
|
+
} else if (require_annotation_state.isAnnotationWrappedInitialState(context.state) && context.buffer.length === 0 && (context.exec?.path?.length ?? 0) === 0 && !(prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/") || prefix.startsWith("+"))) shouldSuggestValues = true;
|
|
367
364
|
if (shouldSuggestValues) for await (const suggestion of getSuggestionsWithDependencyAsync(valueParser, prefix, context.dependencyRegistry, context.exec)) yield suggestion;
|
|
368
365
|
}
|
|
369
366
|
}
|
package/dist/primitives.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { annotateFreshArray, getAnnotations } from "./internal/annotations.js";
|
|
2
|
+
import { joinedFileSuggestion } from "./internal/joined-file-suggestion.js";
|
|
2
3
|
import { message, metavar, optionName, optionNames, text, valueSet } from "./message.js";
|
|
3
4
|
import { getCommandDocMetadata, withCommandDocMetadata } from "./internal/command-doc-metadata.js";
|
|
4
5
|
import { defineKnownCompletion, defineOptionMatch, definePassThroughPriority, getOptionMatch, getPassThroughFailure, getPassThroughPriority } from "./internal/passthrough.js";
|
|
@@ -236,34 +237,34 @@ function* getSuggestionsWithDependency(valueParser, prefix, dependencyRegistry,
|
|
|
236
237
|
}
|
|
237
238
|
yield* valueParser.suggest(prefix);
|
|
238
239
|
}
|
|
240
|
+
/** Returns the joined prefix accepted by option parsing. */
|
|
241
|
+
function joinedOptionPrefix(names, input) {
|
|
242
|
+
return names.filter((name) => name.startsWith("--") || name.startsWith("/") || name.startsWith("-") && name.length > 2).map((name) => name + (name.startsWith("/") ? ":" : "=")).find((prefix) => input.startsWith(prefix));
|
|
243
|
+
}
|
|
239
244
|
/**
|
|
240
245
|
* Internal sync helper for option suggest functionality.
|
|
241
246
|
* @internal
|
|
242
247
|
*/
|
|
243
248
|
function* suggestOptionSync(optionNames$1, valueParser, hidden, description, context, prefix) {
|
|
244
249
|
if (hidden || context.optionsTerminated) return;
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
const
|
|
250
|
+
const expectingValue = context.buffer.length > 0 && optionNames$1.includes(context.buffer[context.buffer.length - 1]);
|
|
251
|
+
const joinedPrefix = joinedOptionPrefix(optionNames$1, prefix);
|
|
252
|
+
if (joinedPrefix !== void 0 && !expectingValue) {
|
|
253
|
+
const optionPart = joinedPrefix.slice(0, -1);
|
|
254
|
+
const valuePart = prefix.slice(joinedPrefix.length);
|
|
249
255
|
if (optionNames$1.includes(optionPart)) {
|
|
250
256
|
if (valueParser && valueParser.suggest) {
|
|
251
257
|
const valueSuggestions = getSuggestionsWithDependency(valueParser, valuePart, context.dependencyRegistry, context.exec);
|
|
252
258
|
for (const suggestion of valueSuggestions) if (suggestion.kind === "literal") yield {
|
|
253
259
|
kind: "literal",
|
|
254
|
-
text: `${
|
|
255
|
-
description: suggestion.description
|
|
256
|
-
};
|
|
257
|
-
else yield {
|
|
258
|
-
kind: "literal",
|
|
259
|
-
text: `${optionPart}=${suggestion.pattern || ""}`,
|
|
260
|
+
text: `${joinedPrefix}${suggestion.text}`,
|
|
260
261
|
description: suggestion.description
|
|
261
262
|
};
|
|
263
|
+
else yield joinedFileSuggestion(joinedPrefix, suggestion, valuePart);
|
|
262
264
|
}
|
|
263
265
|
}
|
|
264
266
|
} else {
|
|
265
|
-
|
|
266
|
-
if (!expectingValue && (prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/"))) {
|
|
267
|
+
if (!expectingValue && (prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/") || prefix.startsWith("+"))) {
|
|
267
268
|
for (const optionName$1 of optionNames$1) if (optionName$1.startsWith(prefix)) {
|
|
268
269
|
if (prefix === "-" && optionName$1.length !== 2) continue;
|
|
269
270
|
yield {
|
|
@@ -278,7 +279,7 @@ function* suggestOptionSync(optionNames$1, valueParser, hidden, description, con
|
|
|
278
279
|
if (context.buffer.length > 0) {
|
|
279
280
|
const lastToken = context.buffer[context.buffer.length - 1];
|
|
280
281
|
if (optionNames$1.includes(lastToken)) shouldSuggestValues = true;
|
|
281
|
-
} else if (isAnnotationWrappedInitialState(context.state) && context.buffer.length === 0 && (context.exec?.path?.length ?? 0) === 0 && !(prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/"))) shouldSuggestValues = true;
|
|
282
|
+
} else if (isAnnotationWrappedInitialState(context.state) && context.buffer.length === 0 && (context.exec?.path?.length ?? 0) === 0 && !(prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/") || prefix.startsWith("+"))) shouldSuggestValues = true;
|
|
282
283
|
if (shouldSuggestValues) yield* getSuggestionsWithDependency(valueParser, prefix, context.dependencyRegistry, context.exec);
|
|
283
284
|
}
|
|
284
285
|
}
|
|
@@ -327,28 +328,24 @@ async function* getSuggestionsWithDependencyAsync(valueParser, prefix, dependenc
|
|
|
327
328
|
*/
|
|
328
329
|
async function* suggestOptionAsync(optionNames$1, valueParser, hidden, description, context, prefix) {
|
|
329
330
|
if (hidden || context.optionsTerminated) return;
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const
|
|
331
|
+
const expectingValue = context.buffer.length > 0 && optionNames$1.includes(context.buffer[context.buffer.length - 1]);
|
|
332
|
+
const joinedPrefix = joinedOptionPrefix(optionNames$1, prefix);
|
|
333
|
+
if (joinedPrefix !== void 0 && !expectingValue) {
|
|
334
|
+
const optionPart = joinedPrefix.slice(0, -1);
|
|
335
|
+
const valuePart = prefix.slice(joinedPrefix.length);
|
|
334
336
|
if (optionNames$1.includes(optionPart)) {
|
|
335
337
|
if (valueParser && valueParser.suggest) {
|
|
336
338
|
const valueSuggestions = getSuggestionsWithDependencyAsync(valueParser, valuePart, context.dependencyRegistry, context.exec);
|
|
337
339
|
for await (const suggestion of valueSuggestions) if (suggestion.kind === "literal") yield {
|
|
338
340
|
kind: "literal",
|
|
339
|
-
text: `${
|
|
340
|
-
description: suggestion.description
|
|
341
|
-
};
|
|
342
|
-
else yield {
|
|
343
|
-
kind: "literal",
|
|
344
|
-
text: `${optionPart}=${suggestion.pattern || ""}`,
|
|
341
|
+
text: `${joinedPrefix}${suggestion.text}`,
|
|
345
342
|
description: suggestion.description
|
|
346
343
|
};
|
|
344
|
+
else yield joinedFileSuggestion(joinedPrefix, suggestion, valuePart);
|
|
347
345
|
}
|
|
348
346
|
}
|
|
349
347
|
} else {
|
|
350
|
-
|
|
351
|
-
if (!expectingValue && (prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/"))) {
|
|
348
|
+
if (!expectingValue && (prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/") || prefix.startsWith("+"))) {
|
|
352
349
|
for (const optionName$1 of optionNames$1) if (optionName$1.startsWith(prefix)) {
|
|
353
350
|
if (prefix === "-" && optionName$1.length !== 2) continue;
|
|
354
351
|
yield {
|
|
@@ -363,7 +360,7 @@ async function* suggestOptionAsync(optionNames$1, valueParser, hidden, descripti
|
|
|
363
360
|
if (context.buffer.length > 0) {
|
|
364
361
|
const lastToken = context.buffer[context.buffer.length - 1];
|
|
365
362
|
if (optionNames$1.includes(lastToken)) shouldSuggestValues = true;
|
|
366
|
-
} else if (isAnnotationWrappedInitialState(context.state) && context.buffer.length === 0 && (context.exec?.path?.length ?? 0) === 0 && !(prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/"))) shouldSuggestValues = true;
|
|
363
|
+
} else if (isAnnotationWrappedInitialState(context.state) && context.buffer.length === 0 && (context.exec?.path?.length ?? 0) === 0 && !(prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/") || prefix.startsWith("+"))) shouldSuggestValues = true;
|
|
367
364
|
if (shouldSuggestValues) for await (const suggestion of getSuggestionsWithDependencyAsync(valueParser, prefix, context.dependencyRegistry, context.exec)) yield suggestion;
|
|
368
365
|
}
|
|
369
366
|
}
|
package/dist/suggestion.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const require_joined_file_suggestion = require('./internal/joined-file-suggestion.cjs');
|
|
1
2
|
const require_message = require('./message.cjs');
|
|
2
3
|
const require_usage = require('./usage.cjs');
|
|
3
4
|
|
|
@@ -237,7 +238,8 @@ function deduplicateSuggestions(suggestions) {
|
|
|
237
238
|
if (existing == null) {
|
|
238
239
|
entries.set(key, suggestion);
|
|
239
240
|
order.push(key);
|
|
240
|
-
} else if (suggestion.kind === "
|
|
241
|
+
} else if (suggestion.kind === "literal" && existing.kind === "literal") require_joined_file_suggestion.mergeJoinedFileSuggestions(existing, suggestion);
|
|
242
|
+
else if (suggestion.kind === "file" && existing.kind === "file" && suggestion.includeHidden === true && existing.includeHidden !== true) entries.set(key, {
|
|
241
243
|
...existing,
|
|
242
244
|
includeHidden: true
|
|
243
245
|
});
|
package/dist/suggestion.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { mergeJoinedFileSuggestions } from "./internal/joined-file-suggestion.js";
|
|
1
2
|
import { message, optionName, text } from "./message.js";
|
|
2
3
|
import { extractCommandNames, extractOptionNames } from "./usage.js";
|
|
3
4
|
|
|
@@ -237,7 +238,8 @@ function deduplicateSuggestions(suggestions) {
|
|
|
237
238
|
if (existing == null) {
|
|
238
239
|
entries.set(key, suggestion);
|
|
239
240
|
order.push(key);
|
|
240
|
-
} else if (suggestion.kind === "
|
|
241
|
+
} else if (suggestion.kind === "literal" && existing.kind === "literal") mergeJoinedFileSuggestions(existing, suggestion);
|
|
242
|
+
else if (suggestion.kind === "file" && existing.kind === "file" && suggestion.includeHidden === true && existing.includeHidden !== true) entries.set(key, {
|
|
241
243
|
...existing,
|
|
242
244
|
includeHidden: true
|
|
243
245
|
});
|