@optique/core 1.0.15-dev.2809 → 1.0.15-dev.2813
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 +266 -38
- package/dist/completion.js +266 -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
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
|
});
|