@optique/core 1.4.0-dev.2618 → 1.4.0-dev.2619
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 +146 -87
- package/dist/constructs.js +146 -87
- package/dist/execution-context.cjs +2 -1
- package/dist/execution-context.js +3 -1
- package/dist/extension.cjs +15 -0
- package/dist/extension.d.cts +12 -1
- package/dist/extension.d.ts +12 -1
- package/dist/extension.js +15 -1
- package/dist/facade.cjs +6 -140
- package/dist/facade.d.cts +2 -32
- package/dist/facade.d.ts +2 -32
- package/dist/facade.js +7 -141
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/modifiers.cjs +5 -4
- package/dist/modifiers.js +5 -4
- package/dist/primitives.cjs +69 -27
- package/dist/primitives.d.cts +3 -3
- package/dist/primitives.d.ts +3 -3
- package/dist/primitives.js +69 -27
- package/dist/short-option.cjs +311 -0
- package/dist/short-option.js +297 -0
- package/dist/usage-internals.cjs +73 -0
- package/dist/usage-internals.js +71 -1
- package/package.json +2 -2
- package/skills/optique/SKILL.md +12 -12
package/dist/facade.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { injectAnnotations } from "./internal/annotations.js";
|
|
2
2
|
import { cacheTerminalTheme, renderTerminalTerm } from "./terminal-internal.js";
|
|
3
3
|
import { measureText, spaceAfterLabel } from "./text-layout.js";
|
|
4
|
-
import { validateCommandNames, validateContextIds,
|
|
5
|
-
import { cloneUsage, formatUsage,
|
|
4
|
+
import { validateCommandNames, validateContextIds, validateMetaNameCollisions, validateOptionNames, validateProgramName } from "./validate.js";
|
|
5
|
+
import { cloneUsage, formatUsage, isSuggestionHidden, normalizeUsage } from "./usage.js";
|
|
6
6
|
import { hasAutomaticWidth, minimumUsageWidth, withAutomaticWidth } from "./terminal-width.js";
|
|
7
7
|
import { commandLine, lineBreak, message, optionName, text, value } from "./message.js";
|
|
8
8
|
import { renderErrorMessage } from "./message-renderer.js";
|
|
9
|
-
import { formatDocPage
|
|
9
|
+
import { formatDocPage } from "./doc.js";
|
|
10
10
|
import { dispatchByMode } from "./internal/mode-dispatch.js";
|
|
11
11
|
import { collectExplicitSourceValues, collectExplicitSourceValuesAsync, createDependencyRuntimeContext } from "./dependency-runtime.js";
|
|
12
12
|
import { createInputTrace } from "./input-trace.js";
|
|
13
13
|
import { attemptParseAsync, attemptParseSync, createEffectfulCompletionSession, createParserContext, getDocPage } from "./internal/parser.js";
|
|
14
14
|
import { bash, fish, nu, pwsh, zsh } from "./completion.js";
|
|
15
|
+
import { collectActiveOptionNames, collectRootOptionNames } from "./usage-internals.js";
|
|
15
16
|
import { allowDuplicateLeadingCommandNamesKey, hiddenCommandAliasesKey } from "./internal/command-alias.js";
|
|
16
17
|
import { completeOrExtractPhase2Seed } from "./phase2-seed.js";
|
|
17
18
|
import { multiple, optional, withDefault } from "./modifiers.js";
|
|
@@ -757,76 +758,9 @@ function collectActiveValueOptionNames(usage, commandPath, includeDirectAfterCom
|
|
|
757
758
|
for (const name of optionNames.flag) names.delete(name);
|
|
758
759
|
return names;
|
|
759
760
|
}
|
|
760
|
-
function collectRootOptionNames(usage, names, rootLeadingNames) {
|
|
761
|
-
for (const term of usage) collectRootOptionNamesFromTerm(term, names, rootLeadingNames);
|
|
762
|
-
}
|
|
763
|
-
function collectRootOptionNamesFromTerm(term, names, rootLeadingNames) {
|
|
764
|
-
switch (term.type) {
|
|
765
|
-
case "option":
|
|
766
|
-
for (const name of term.names) {
|
|
767
|
-
if (!rootLeadingNames.has(name)) continue;
|
|
768
|
-
if (term.metavar != null) names.value.add(name);
|
|
769
|
-
else names.flag.add(name);
|
|
770
|
-
}
|
|
771
|
-
return;
|
|
772
|
-
case "optional":
|
|
773
|
-
case "multiple":
|
|
774
|
-
case "sequence":
|
|
775
|
-
collectRootOptionNames(term.terms, names, rootLeadingNames);
|
|
776
|
-
return;
|
|
777
|
-
case "exclusive":
|
|
778
|
-
for (const branch of term.terms) collectRootOptionNames(branch, names, rootLeadingNames);
|
|
779
|
-
return;
|
|
780
|
-
case "argument":
|
|
781
|
-
case "command":
|
|
782
|
-
case "literal":
|
|
783
|
-
case "passthrough":
|
|
784
|
-
case "ellipsis": return;
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
function collectActiveOptionNames(usage, commandPath, names, fromExclusive, includeDirectAfterCommandOptions) {
|
|
788
|
-
if (commandPath.length === 0) {
|
|
789
|
-
collectOptionNamesAtCurrentCommandDepth(usage, names, false);
|
|
790
|
-
return;
|
|
791
|
-
}
|
|
792
|
-
const [commandName, ...rest] = commandPath;
|
|
793
|
-
for (let i = 0; i < usage.length; i++) {
|
|
794
|
-
const term = usage[i];
|
|
795
|
-
if (term.type === "command" && term.name === commandName) {
|
|
796
|
-
const remainingUsage = usage.slice(i + 1);
|
|
797
|
-
if (rest.length === 0) collectOptionNamesAtCurrentCommandDepth(remainingUsage, names, !fromExclusive && includeDirectAfterCommandOptions);
|
|
798
|
-
else collectActiveOptionNames(remainingUsage, rest, names, fromExclusive, includeDirectAfterCommandOptions);
|
|
799
|
-
} else if (term.type === "exclusive") for (const branch of term.terms) collectActiveOptionNames(branch, commandPath, names, true, includeDirectAfterCommandOptions);
|
|
800
|
-
else if (term.type === "optional" || term.type === "multiple" || term.type === "sequence") collectActiveOptionNames(term.terms, commandPath, names, fromExclusive, includeDirectAfterCommandOptions);
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
761
|
function isRootOptionToken(token, rootOptionSuggestions) {
|
|
804
762
|
return token != null && rootOptionSuggestions.some((suggestion) => token === suggestion.text || token.startsWith(`${suggestion.text}=`));
|
|
805
763
|
}
|
|
806
|
-
function collectOptionNamesAtCurrentCommandDepth(usage, names, afterMatchedCommand) {
|
|
807
|
-
for (const term of usage) if (collectOptionNamesAtCurrentCommandDepthFromTerm(term, names, afterMatchedCommand)) return;
|
|
808
|
-
}
|
|
809
|
-
function collectOptionNamesAtCurrentCommandDepthFromTerm(term, names, afterMatchedCommand) {
|
|
810
|
-
switch (term.type) {
|
|
811
|
-
case "command": return !afterMatchedCommand;
|
|
812
|
-
case "option":
|
|
813
|
-
if (term.metavar != null) for (const name of term.names) names.value.add(name);
|
|
814
|
-
else for (const name of term.names) names.flag.add(name);
|
|
815
|
-
return false;
|
|
816
|
-
case "optional":
|
|
817
|
-
case "multiple":
|
|
818
|
-
case "sequence":
|
|
819
|
-
collectOptionNamesAtCurrentCommandDepth(term.terms, names, afterMatchedCommand);
|
|
820
|
-
return false;
|
|
821
|
-
case "exclusive":
|
|
822
|
-
for (const branch of term.terms) collectOptionNamesAtCurrentCommandDepth(branch, names, false);
|
|
823
|
-
return false;
|
|
824
|
-
case "argument":
|
|
825
|
-
case "literal":
|
|
826
|
-
case "passthrough":
|
|
827
|
-
case "ellipsis": return false;
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
764
|
function getRootMetaOptionSuggestions(helpOptionConfig, helpOptionNames, versionOptionConfig, versionOptionNames) {
|
|
831
765
|
const suggestions = [];
|
|
832
766
|
if (helpOptionConfig != null && !isSuggestionHidden(helpOptionConfig.hidden)) suggestions.push(...helpOptionNames.map((name) => ({
|
|
@@ -884,7 +818,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
884
818
|
options = optionsParam ?? {};
|
|
885
819
|
}
|
|
886
820
|
validateProgramName(programName);
|
|
887
|
-
const { colors, messageFormatter, theme: requestedTheme, maxWidth: requestedMaxWidth, termWidth, showDefault, showChoices, sectionOrder,
|
|
821
|
+
const { colors, messageFormatter, theme: requestedTheme, maxWidth: requestedMaxWidth, termWidth, showDefault, showChoices, sectionOrder, showUsage, usageLine, commandList = "recursive", aboveError = "usage", onError = () => {
|
|
888
822
|
throw new RunParserError("Failed to parse command line arguments.");
|
|
889
823
|
}, stderr = console.error, stdout = console.log, brief, description, examples, author, bugs, footer } = options;
|
|
890
824
|
let maxWidth = requestedMaxWidth;
|
|
@@ -916,7 +850,6 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
916
850
|
const onCompletion = options.completion?.onShow ?? (() => ({}));
|
|
917
851
|
const onCompletionResult = (code) => onCompletion(code);
|
|
918
852
|
const onErrorResult = (code, error) => onError(code, error);
|
|
919
|
-
for (const label of [helpSections?.commands, helpSections?.options]) if (label !== void 0) validateLabel(label);
|
|
920
853
|
if (helpOptionConfig?.names) validateOptionNames(helpOptionConfig.names, "Help option");
|
|
921
854
|
if (helpCommandConfig?.names) validateCommandNames(helpCommandConfig.names, "Help command");
|
|
922
855
|
if (versionOptionConfig?.names) validateOptionNames(versionOptionConfig.names, "Version option");
|
|
@@ -1089,8 +1022,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1089
1022
|
bugs: isTopLevel && !isMetaCommandHelp ? bugs ?? doc.bugs : void 0,
|
|
1090
1023
|
footer: shouldOverride ? footer ?? doc.footer : doc.footer ?? footer
|
|
1091
1024
|
}, commandList, isTopLevel);
|
|
1092
|
-
const
|
|
1093
|
-
const renderedDoc = isTopLevel && usageLine != null ? applyUsageLine(groupedDoc, usageLine) : groupedDoc;
|
|
1025
|
+
const renderedDoc = isTopLevel && usageLine != null ? applyUsageLine(augmentedDoc, usageLine) : augmentedDoc;
|
|
1094
1026
|
stdout(formatDocPage(programName, renderedDoc, formatOptions({
|
|
1095
1027
|
messageFormatter,
|
|
1096
1028
|
theme,
|
|
@@ -1166,8 +1098,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1166
1098
|
footer: footer ?? doc.footer
|
|
1167
1099
|
}, commandList, isTopLevel);
|
|
1168
1100
|
const defaultRootUsage = typeof usageLine === "function" && (options.help || options.version || options.completion) ? normalizeUsage(getRootHelpGeneratorParser().usage) : augmentedDoc.usage ?? [];
|
|
1169
|
-
const
|
|
1170
|
-
const renderedDoc = isTopLevel && usageLine != null ? applyUsageLine(groupedDoc, usageLine, defaultRootUsage) : groupedDoc;
|
|
1101
|
+
const renderedDoc = isTopLevel && usageLine != null ? applyUsageLine(augmentedDoc, usageLine, defaultRootUsage) : augmentedDoc;
|
|
1171
1102
|
stderr(formatDocPage(programName, renderedDoc, formatOptions({
|
|
1172
1103
|
messageFormatter,
|
|
1173
1104
|
theme,
|
|
@@ -1254,7 +1185,6 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1254
1185
|
* @returns The parsed result if successful.
|
|
1255
1186
|
* @throws {TypeError} If an async parser is passed at runtime. Use
|
|
1256
1187
|
* {@link runParser} or {@link runParserAsync} for async parsers.
|
|
1257
|
-
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
1258
1188
|
* @since 0.9.0
|
|
1259
1189
|
*/
|
|
1260
1190
|
function runParserSync(parser, programName, args, options) {
|
|
@@ -1277,7 +1207,6 @@ function runParserSync(parser, programName, args, options) {
|
|
|
1277
1207
|
* @param options Configuration options for customizing behavior.
|
|
1278
1208
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
1279
1209
|
* color, even when colors are disabled.
|
|
1280
|
-
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
1281
1210
|
* @returns A Promise of the parsed result if successful.
|
|
1282
1211
|
* @since 0.9.0
|
|
1283
1212
|
*/
|
|
@@ -1292,66 +1221,6 @@ function applyUsageLine(doc, usageLine, defaultUsageLine = doc.usage ?? []) {
|
|
|
1292
1221
|
usage: normalizeUsage(customUsageLine)
|
|
1293
1222
|
};
|
|
1294
1223
|
}
|
|
1295
|
-
/** Prepares the runner's final page without changing parser documentation. */
|
|
1296
|
-
function applyHelpSections(doc, labels) {
|
|
1297
|
-
if (labels == null || labels.commands == null && labels.options == null) return doc;
|
|
1298
|
-
const visible = (entry) => !isDocEntryHidden(entry) && formatUsageTerm(entry.term, { context: "doc" }).trim() !== "";
|
|
1299
|
-
if (!doc.sections.some((section) => section.entries.some((entry) => entry.term.type === "command" && visible(entry)))) return doc;
|
|
1300
|
-
const existingTitles = new Set(doc.sections.flatMap((section) => section.title == null ? [] : [section.title]));
|
|
1301
|
-
const additions = /* @__PURE__ */ new Map();
|
|
1302
|
-
const residuals = /* @__PURE__ */ new Map();
|
|
1303
|
-
const newSections = /* @__PURE__ */ new Map();
|
|
1304
|
-
for (const section of doc.sections) {
|
|
1305
|
-
if (section.title != null) continue;
|
|
1306
|
-
const commands = [];
|
|
1307
|
-
const options = [];
|
|
1308
|
-
const remaining = [];
|
|
1309
|
-
for (const entry of section.entries) if (entry.term.type === "command" && labels.commands != null && visible(entry)) commands.push(entry);
|
|
1310
|
-
else if (entry.term.type === "option" && labels.options != null && visible(entry)) options.push(entry);
|
|
1311
|
-
else remaining.push(entry);
|
|
1312
|
-
if (commands.length === 0 && options.length === 0) continue;
|
|
1313
|
-
residuals.set(section, remaining);
|
|
1314
|
-
for (const [label, entries] of [[labels.commands, commands], [labels.options, options]]) {
|
|
1315
|
-
if (label == null || entries.length === 0) continue;
|
|
1316
|
-
const previous = additions.get(label);
|
|
1317
|
-
if (previous != null) previous.push(...entries);
|
|
1318
|
-
else {
|
|
1319
|
-
additions.set(label, entries);
|
|
1320
|
-
if (!existingTitles.has(label)) {
|
|
1321
|
-
const titles = newSections.get(section) ?? [];
|
|
1322
|
-
titles.push(label);
|
|
1323
|
-
newSections.set(section, titles);
|
|
1324
|
-
}
|
|
1325
|
-
}
|
|
1326
|
-
}
|
|
1327
|
-
}
|
|
1328
|
-
if (additions.size === 0) return doc;
|
|
1329
|
-
const sections = [];
|
|
1330
|
-
for (const section of doc.sections) {
|
|
1331
|
-
if (section.title != null) {
|
|
1332
|
-
const entries$1 = additions.get(section.title);
|
|
1333
|
-
sections.push(entries$1 == null ? section : {
|
|
1334
|
-
...section,
|
|
1335
|
-
entries: [...section.entries, ...entries$1]
|
|
1336
|
-
});
|
|
1337
|
-
continue;
|
|
1338
|
-
}
|
|
1339
|
-
for (const title of newSections.get(section) ?? []) sections.push({
|
|
1340
|
-
title,
|
|
1341
|
-
entries: additions.get(title) ?? []
|
|
1342
|
-
});
|
|
1343
|
-
const entries = residuals.get(section);
|
|
1344
|
-
if (entries == null) sections.push(section);
|
|
1345
|
-
else if (entries.length > 0) sections.push({
|
|
1346
|
-
...section,
|
|
1347
|
-
entries
|
|
1348
|
-
});
|
|
1349
|
-
}
|
|
1350
|
-
return {
|
|
1351
|
-
...doc,
|
|
1352
|
-
sections
|
|
1353
|
-
};
|
|
1354
|
-
}
|
|
1355
1224
|
function maybeCollapseCommandList(doc, commandList, isTopLevel) {
|
|
1356
1225
|
if (commandList !== "top-level" || !isTopLevel) return doc;
|
|
1357
1226
|
return {
|
|
@@ -1687,7 +1556,6 @@ async function runWithBody(parser, programName, contexts, args, options) {
|
|
|
1687
1556
|
* @param programName Name of the program for help/error output.
|
|
1688
1557
|
* @param contexts Source contexts to use (priority: earlier overrides later).
|
|
1689
1558
|
* @param options Run options including args, help, version, etc.
|
|
1690
|
-
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
1691
1559
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
1692
1560
|
* color, even when colors are disabled.
|
|
1693
1561
|
* @returns Promise that resolves to the parsed result.
|
|
@@ -1788,7 +1656,6 @@ function runWithSyncBody(parser, programName, contexts, args, options) {
|
|
|
1788
1656
|
* @param programName Name of the program for help/error output.
|
|
1789
1657
|
* @param contexts Source contexts to use (priority: earlier overrides later).
|
|
1790
1658
|
* @param options Run options including args, help, version, etc.
|
|
1791
|
-
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
1792
1659
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
1793
1660
|
* color, even when colors are disabled.
|
|
1794
1661
|
* @returns The parsed result.
|
|
@@ -1840,7 +1707,6 @@ function runWithSync(parser, programName, contexts, options) {
|
|
|
1840
1707
|
* @param programName Name of the program for help/error output.
|
|
1841
1708
|
* @param contexts Source contexts to use (priority: earlier overrides later).
|
|
1842
1709
|
* @param options Run options including args, help, version, etc.
|
|
1843
|
-
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
1844
1710
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
1845
1711
|
* color, even when colors are disabled.
|
|
1846
1712
|
* @returns Promise that resolves to the parsed result.
|
package/dist/index.d.cts
CHANGED
|
@@ -11,6 +11,6 @@ import { DeferredValue, DeferredValueOptions, DeferredValueSource, FluentParser,
|
|
|
11
11
|
import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, GroupOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, SeqOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, seq, tuple } from "./constructs.cjs";
|
|
12
12
|
import { ParserValuePlaceholder, SourceContext, SourceContextRequest } from "./context.cjs";
|
|
13
13
|
import { AnyDependencySource, CombineMode, CombinedDependencyMode, DependencyMode, DependencySource, DependencySourceInfo, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, dependency, deriveFrom, deriveFromAsync, deriveFromSync, getDependencySourceInfo, isDependencySource, isDerivedValueParser } from "./internal/dependency.cjs";
|
|
14
|
-
import { CommandListMode, CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions,
|
|
14
|
+
import { CommandListMode, CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions, OptionSubConfig, RunOptions, RunParserError, RunWithOptions, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.cjs";
|
|
15
15
|
import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, NegatableFlagErrorOptions, NegatableFlagNameList, NegatableFlagNames, NegatableFlagOptions, NegatableFlagState, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, fail, flag, negatableFlag, option, passThrough } from "./primitives.cjs";
|
|
16
|
-
export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandListMode, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, CronExpression, CronExpressionForOptions, CronOptions, DeferredMap, DeferredValue, DeferredValueOptions, DeferredValueSource, DependencyMode, DependencySource, DependencySourceInfo, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DetailedParseResult, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EffectfulCompletionSession, EmailOptions, ErrorLabelTerm, ExecutionContext, ExecutionPhase, ExtractRequiredOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FirstOfOptions, FlagErrorOptions, FlagOptions, FloatOptions, FluentParser, GroupOptions,
|
|
16
|
+
export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandListMode, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, CronExpression, CronExpressionForOptions, CronOptions, DeferredMap, DeferredValue, DeferredValueOptions, DeferredValueSource, DependencyMode, DependencySource, DependencySourceInfo, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DetailedParseResult, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EffectfulCompletionSession, EmailOptions, ErrorLabelTerm, ExecutionContext, ExecutionPhase, ExtractRequiredOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FirstOfOptions, FlagErrorOptions, FlagOptions, FloatOptions, FluentParser, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, KeyValueOptions, LabelTerm, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageFormatter, type MessageFormatterOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NegatableFlagErrorOptions, NegatableFlagNameList, NegatableFlagNames, NegatableFlagOptions, NegatableFlagState, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, OriginOptions, ParseFrame, type ParseOptions, Parser, ParserContext, ParserModifiers, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ProgramNameTerm, RegExpOptions, Result, RunOptions, RunParserError, RunWithOptions, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SeqOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, SourceContextRequest, StringOptions, SubstituteParserValue, Suggestion, SyntaxPunctuationTerm, TerminalColor, TerminalFormatContext, TerminalFormatter, TerminalFragment, TerminalStyle, TerminalTerm, TerminalTheme, TransformMapping, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, biject, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, color, command, commandLine, concat, conditional, constant, createMessageFormatter, createParserContext, cron, deduplicateDocEntries, deduplicateDocFragments, defaultTerminalTheme, deferredValue, dependency, deriveFrom, deriveFromAsync, deriveFromSync, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fileSize, firstOf, fish, flag, float, fluent, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDependencySourceInfo, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredValue, isDependencySource, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isSuggestionHidden, isUsageHidden, isValueParser, json, keyValue, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, negatableFlag, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, origin, parse, parseAsync, parseDetailed, parseSync, passThrough, port, portRange, pwsh, regExp, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, semVer, seq, socketAddress, string, suggest, suggestAsync, suggestSync, text, transform, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,6 @@ import { DeferredValue, DeferredValueOptions, DeferredValueSource, FluentParser,
|
|
|
11
11
|
import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, GroupOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, SeqOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, seq, tuple } from "./constructs.js";
|
|
12
12
|
import { ParserValuePlaceholder, SourceContext, SourceContextRequest } from "./context.js";
|
|
13
13
|
import { AnyDependencySource, CombineMode, CombinedDependencyMode, DependencyMode, DependencySource, DependencySourceInfo, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, dependency, deriveFrom, deriveFromAsync, deriveFromSync, getDependencySourceInfo, isDependencySource, isDerivedValueParser } from "./internal/dependency.js";
|
|
14
|
-
import { CommandListMode, CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions,
|
|
14
|
+
import { CommandListMode, CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions, OptionSubConfig, RunOptions, RunParserError, RunWithOptions, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.js";
|
|
15
15
|
import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, NegatableFlagErrorOptions, NegatableFlagNameList, NegatableFlagNames, NegatableFlagOptions, NegatableFlagState, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, fail, flag, negatableFlag, option, passThrough } from "./primitives.js";
|
|
16
|
-
export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandListMode, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, CronExpression, CronExpressionForOptions, CronOptions, DeferredMap, DeferredValue, DeferredValueOptions, DeferredValueSource, DependencyMode, DependencySource, DependencySourceInfo, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DetailedParseResult, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EffectfulCompletionSession, EmailOptions, ErrorLabelTerm, ExecutionContext, ExecutionPhase, ExtractRequiredOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FirstOfOptions, FlagErrorOptions, FlagOptions, FloatOptions, FluentParser, GroupOptions,
|
|
16
|
+
export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandListMode, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, CronExpression, CronExpressionForOptions, CronOptions, DeferredMap, DeferredValue, DeferredValueOptions, DeferredValueSource, DependencyMode, DependencySource, DependencySourceInfo, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DetailedParseResult, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EffectfulCompletionSession, EmailOptions, ErrorLabelTerm, ExecutionContext, ExecutionPhase, ExtractRequiredOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FirstOfOptions, FlagErrorOptions, FlagOptions, FloatOptions, FluentParser, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, KeyValueOptions, LabelTerm, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageFormatter, type MessageFormatterOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NegatableFlagErrorOptions, NegatableFlagNameList, NegatableFlagNames, NegatableFlagOptions, NegatableFlagState, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, OriginOptions, ParseFrame, type ParseOptions, Parser, ParserContext, ParserModifiers, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ProgramNameTerm, RegExpOptions, Result, RunOptions, RunParserError, RunWithOptions, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SeqOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, SourceContextRequest, StringOptions, SubstituteParserValue, Suggestion, SyntaxPunctuationTerm, TerminalColor, TerminalFormatContext, TerminalFormatter, TerminalFragment, TerminalStyle, TerminalTerm, TerminalTheme, TransformMapping, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, biject, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, color, command, commandLine, concat, conditional, constant, createMessageFormatter, createParserContext, cron, deduplicateDocEntries, deduplicateDocFragments, defaultTerminalTheme, deferredValue, dependency, deriveFrom, deriveFromAsync, deriveFromSync, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fileSize, firstOf, fish, flag, float, fluent, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDependencySourceInfo, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredValue, isDependencySource, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isSuggestionHidden, isUsageHidden, isValueParser, json, keyValue, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, negatableFlag, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, origin, parse, parseAsync, parseDetailed, parseSync, passThrough, port, portRange, pwsh, regExp, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, semVer, seq, socketAddress, string, suggest, suggestAsync, suggestSync, text, transform, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
|
package/dist/modifiers.cjs
CHANGED
|
@@ -5,6 +5,7 @@ const require_dependency_runtime = require('./dependency-runtime.cjs');
|
|
|
5
5
|
const require_internal_parser = require('./internal/parser.cjs');
|
|
6
6
|
const require_annotation_state = require('./annotation-state.cjs');
|
|
7
7
|
const require_execution_context = require('./execution-context.cjs');
|
|
8
|
+
const require_short_option = require('./short-option.cjs');
|
|
8
9
|
const require_phase2_seed = require('./phase2-seed.cjs');
|
|
9
10
|
const require_dependency_metadata = require('./dependency-metadata.cjs');
|
|
10
11
|
|
|
@@ -478,7 +479,7 @@ function optional(parser) {
|
|
|
478
479
|
require_internal_parser.defineParseLanes(optionalParser, adaptOptionalStyleParseLanes(parser));
|
|
479
480
|
require_internal_parser.defineInheritedAnnotationParser(optionalParser);
|
|
480
481
|
require_internal_parser.defineSourceBindingOnlyAnnotationCompletionParser(optionalParser);
|
|
481
|
-
return fluent(optionalParser);
|
|
482
|
+
return fluent(require_short_option.scopeParser(optionalParser, require_short_option.combinedOptionScope([parser])));
|
|
482
483
|
}
|
|
483
484
|
/**
|
|
484
485
|
* Error type for structured error messages in {@link withDefault} default value callbacks.
|
|
@@ -729,7 +730,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
729
730
|
require_internal_parser.defineParseLanes(withDefaultParser, adaptOptionalStyleParseLanes(parser));
|
|
730
731
|
require_internal_parser.defineInheritedAnnotationParser(withDefaultParser);
|
|
731
732
|
require_internal_parser.defineSourceBindingOnlyAnnotationCompletionParser(withDefaultParser);
|
|
732
|
-
return fluent(withDefaultParser);
|
|
733
|
+
return fluent(require_short_option.scopeParser(withDefaultParser, require_short_option.combinedOptionScope([parser])));
|
|
733
734
|
}
|
|
734
735
|
/**
|
|
735
736
|
* Creates a parser that transforms the result value of another parser using
|
|
@@ -1714,7 +1715,7 @@ function multiple(parser, options = {}) {
|
|
|
1714
1715
|
enumerable: false
|
|
1715
1716
|
});
|
|
1716
1717
|
}
|
|
1717
|
-
return fluent(resultParser);
|
|
1718
|
+
return fluent(require_short_option.scopeParser(resultParser, require_short_option.repeatedOptionScope(parser)));
|
|
1718
1719
|
}
|
|
1719
1720
|
/**
|
|
1720
1721
|
* Creates a parser that requires the wrapped parser to consume at least one
|
|
@@ -1850,7 +1851,7 @@ function nonEmpty(parser) {
|
|
|
1850
1851
|
enumerable: false
|
|
1851
1852
|
});
|
|
1852
1853
|
require_dependency_runtime.defineForwardedEffectfulSchedulingNodes(nonEmptyParser, parser);
|
|
1853
|
-
return fluent(nonEmptyParser);
|
|
1854
|
+
return fluent(require_short_option.scopeParser(nonEmptyParser, require_short_option.combinedOptionScope([parser])));
|
|
1854
1855
|
}
|
|
1855
1856
|
const fluentParserMarker = Symbol.for("@optique/core/fluent");
|
|
1856
1857
|
/**
|
package/dist/modifiers.js
CHANGED
|
@@ -5,6 +5,7 @@ import { defineForwardedEffectfulSchedulingNodes } from "./dependency-runtime.js
|
|
|
5
5
|
import { defineInheritedAnnotationParser, defineParseLanes, defineSourceBindingOnlyAnnotationCompletionParser, getOwnParseLanes, unmatchedNonCliDependencySourceStateMarker } from "./internal/parser.js";
|
|
6
6
|
import { getDelegatedAnnotationState, hasDelegatedAnnotationCarrier, isAnnotationWrappedInitialState, normalizeDelegatedAnnotationState, normalizeNestedDelegatedAnnotationState } from "./annotation-state.js";
|
|
7
7
|
import { mergeChildExec, withChildContext, withChildExecPath } from "./execution-context.js";
|
|
8
|
+
import { combinedOptionScope, repeatedOptionScope, scopeParser } from "./short-option.js";
|
|
8
9
|
import { completeOrExtractPhase2Seed, extractPhase2Seed, extractPhase2SeedKey, phase2SeedFromValueResult } from "./phase2-seed.js";
|
|
9
10
|
import { composeDependencyMetadata } from "./dependency-metadata.js";
|
|
10
11
|
|
|
@@ -478,7 +479,7 @@ function optional(parser) {
|
|
|
478
479
|
defineParseLanes(optionalParser, adaptOptionalStyleParseLanes(parser));
|
|
479
480
|
defineInheritedAnnotationParser(optionalParser);
|
|
480
481
|
defineSourceBindingOnlyAnnotationCompletionParser(optionalParser);
|
|
481
|
-
return fluent(optionalParser);
|
|
482
|
+
return fluent(scopeParser(optionalParser, combinedOptionScope([parser])));
|
|
482
483
|
}
|
|
483
484
|
/**
|
|
484
485
|
* Error type for structured error messages in {@link withDefault} default value callbacks.
|
|
@@ -729,7 +730,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
729
730
|
defineParseLanes(withDefaultParser, adaptOptionalStyleParseLanes(parser));
|
|
730
731
|
defineInheritedAnnotationParser(withDefaultParser);
|
|
731
732
|
defineSourceBindingOnlyAnnotationCompletionParser(withDefaultParser);
|
|
732
|
-
return fluent(withDefaultParser);
|
|
733
|
+
return fluent(scopeParser(withDefaultParser, combinedOptionScope([parser])));
|
|
733
734
|
}
|
|
734
735
|
/**
|
|
735
736
|
* Creates a parser that transforms the result value of another parser using
|
|
@@ -1714,7 +1715,7 @@ function multiple(parser, options = {}) {
|
|
|
1714
1715
|
enumerable: false
|
|
1715
1716
|
});
|
|
1716
1717
|
}
|
|
1717
|
-
return fluent(resultParser);
|
|
1718
|
+
return fluent(scopeParser(resultParser, repeatedOptionScope(parser)));
|
|
1718
1719
|
}
|
|
1719
1720
|
/**
|
|
1720
1721
|
* Creates a parser that requires the wrapped parser to consume at least one
|
|
@@ -1850,7 +1851,7 @@ function nonEmpty(parser) {
|
|
|
1850
1851
|
enumerable: false
|
|
1851
1852
|
});
|
|
1852
1853
|
defineForwardedEffectfulSchedulingNodes(nonEmptyParser, parser);
|
|
1853
|
-
return fluent(nonEmptyParser);
|
|
1854
|
+
return fluent(scopeParser(nonEmptyParser, combinedOptionScope([parser])));
|
|
1854
1855
|
}
|
|
1855
1856
|
const fluentParserMarker = Symbol.for("@optique/core/fluent");
|
|
1856
1857
|
/**
|
package/dist/primitives.cjs
CHANGED
|
@@ -6,13 +6,14 @@ const require_mode_dispatch = require('./internal/mode-dispatch.cjs');
|
|
|
6
6
|
const require_internal_dependency = require('./internal/dependency.cjs');
|
|
7
7
|
const require_dependency_runtime = require('./dependency-runtime.cjs');
|
|
8
8
|
const require_annotation_state = require('./annotation-state.cjs');
|
|
9
|
-
const require_command_alias = require('./internal/command-alias.cjs');
|
|
10
9
|
const require_execution_context = require('./execution-context.cjs');
|
|
10
|
+
const require_usage_internals = require('./usage-internals.cjs');
|
|
11
|
+
const require_short_option = require('./short-option.cjs');
|
|
12
|
+
const require_command_alias = require('./internal/command-alias.cjs');
|
|
11
13
|
const require_phase2_seed = require('./phase2-seed.cjs');
|
|
12
14
|
const require_dependency_metadata = require('./dependency-metadata.cjs');
|
|
13
15
|
const require_modifiers = require('./modifiers.cjs');
|
|
14
16
|
const require_suggestion = require('./suggestion.cjs');
|
|
15
|
-
const require_usage_internals = require('./usage-internals.cjs');
|
|
16
17
|
const require_valueparser = require('./valueparser.cjs');
|
|
17
18
|
|
|
18
19
|
//#region src/primitives.ts
|
|
@@ -256,11 +257,25 @@ function* getSuggestionsWithDependency(valueParser, prefix, dependencyRegistry,
|
|
|
256
257
|
*/
|
|
257
258
|
function* suggestOptionSync(optionNames$1, valueParser, hidden, description, context, prefix) {
|
|
258
259
|
if (hidden) return;
|
|
260
|
+
if (context.optionsTerminated) return;
|
|
261
|
+
const waitingForValue = context.buffer.length > 0 && optionNames$1.includes(context.buffer[context.buffer.length - 1]);
|
|
262
|
+
if (valueParser != null && !waitingForValue && !isTerminalValueState(context.state)) {
|
|
263
|
+
const attached = require_short_option.attachedValuePrefix(context, prefix, optionNames$1);
|
|
264
|
+
if (attached != null) {
|
|
265
|
+
if (attached.value.length === 0 && optionNames$1.includes(prefix)) yield {
|
|
266
|
+
kind: "literal",
|
|
267
|
+
text: prefix,
|
|
268
|
+
...description != null ? { description } : {}
|
|
269
|
+
};
|
|
270
|
+
if (valueParser.suggest != null) for (const suggestion of getSuggestionsWithDependency(valueParser, attached.value, context.dependencyRegistry, context.exec)) yield require_short_option.prefixSuggestion(attached.head, suggestion);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
259
274
|
const equalsIndex = prefix.indexOf("=");
|
|
260
|
-
if (equalsIndex >= 0) {
|
|
275
|
+
if (equalsIndex >= 0 && !waitingForValue) {
|
|
261
276
|
const optionPart = prefix.slice(0, equalsIndex);
|
|
262
277
|
const valuePart = prefix.slice(equalsIndex + 1);
|
|
263
|
-
if (optionNames$1.includes(optionPart)) {
|
|
278
|
+
if (optionNames$1.includes(optionPart) && !/^-[^-]$/u.test(optionPart)) {
|
|
264
279
|
if (valueParser && valueParser.suggest) {
|
|
265
280
|
const valueSuggestions = getSuggestionsWithDependency(valueParser, valuePart, context.dependencyRegistry, context.exec);
|
|
266
281
|
for (const suggestion of valueSuggestions) if (suggestion.kind === "literal") yield {
|
|
@@ -279,7 +294,7 @@ function* suggestOptionSync(optionNames$1, valueParser, hidden, description, con
|
|
|
279
294
|
const expectingValue = context.buffer.length > 0 && optionNames$1.includes(context.buffer[context.buffer.length - 1]);
|
|
280
295
|
if (!expectingValue && (prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/") || prefix.startsWith("+"))) {
|
|
281
296
|
for (const optionName$1 of optionNames$1) if (optionName$1.startsWith(prefix)) {
|
|
282
|
-
if (prefix === "-" && optionName$1
|
|
297
|
+
if (prefix === "-" && !/^-[^-]$/u.test(optionName$1)) continue;
|
|
283
298
|
yield {
|
|
284
299
|
kind: "literal",
|
|
285
300
|
text: optionName$1,
|
|
@@ -341,11 +356,25 @@ async function* getSuggestionsWithDependencyAsync(valueParser, prefix, dependenc
|
|
|
341
356
|
*/
|
|
342
357
|
async function* suggestOptionAsync(optionNames$1, valueParser, hidden, description, context, prefix) {
|
|
343
358
|
if (hidden) return;
|
|
359
|
+
if (context.optionsTerminated) return;
|
|
360
|
+
const waitingForValue = context.buffer.length > 0 && optionNames$1.includes(context.buffer[context.buffer.length - 1]);
|
|
361
|
+
if (valueParser != null && !waitingForValue && !isTerminalValueState(context.state)) {
|
|
362
|
+
const attached = require_short_option.attachedValuePrefix(context, prefix, optionNames$1);
|
|
363
|
+
if (attached != null) {
|
|
364
|
+
if (attached.value.length === 0 && optionNames$1.includes(prefix)) yield {
|
|
365
|
+
kind: "literal",
|
|
366
|
+
text: prefix,
|
|
367
|
+
...description != null ? { description } : {}
|
|
368
|
+
};
|
|
369
|
+
if (valueParser.suggest != null) for await (const suggestion of getSuggestionsWithDependencyAsync(valueParser, attached.value, context.dependencyRegistry, context.exec)) yield require_short_option.prefixSuggestion(attached.head, suggestion);
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
344
373
|
const equalsIndex = prefix.indexOf("=");
|
|
345
|
-
if (equalsIndex >= 0) {
|
|
374
|
+
if (equalsIndex >= 0 && !waitingForValue) {
|
|
346
375
|
const optionPart = prefix.slice(0, equalsIndex);
|
|
347
376
|
const valuePart = prefix.slice(equalsIndex + 1);
|
|
348
|
-
if (optionNames$1.includes(optionPart)) {
|
|
377
|
+
if (optionNames$1.includes(optionPart) && !/^-[^-]$/u.test(optionPart)) {
|
|
349
378
|
if (valueParser && valueParser.suggest) {
|
|
350
379
|
const valueSuggestions = getSuggestionsWithDependencyAsync(valueParser, valuePart, context.dependencyRegistry, context.exec);
|
|
351
380
|
for await (const suggestion of valueSuggestions) if (suggestion.kind === "literal") yield {
|
|
@@ -364,7 +393,7 @@ async function* suggestOptionAsync(optionNames$1, valueParser, hidden, descripti
|
|
|
364
393
|
const expectingValue = context.buffer.length > 0 && optionNames$1.includes(context.buffer[context.buffer.length - 1]);
|
|
365
394
|
if (!expectingValue && (prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/") || prefix.startsWith("+"))) {
|
|
366
395
|
for (const optionName$1 of optionNames$1) if (optionName$1.startsWith(prefix)) {
|
|
367
|
-
if (prefix === "-" && optionName$1
|
|
396
|
+
if (prefix === "-" && !/^-[^-]$/u.test(optionName$1)) continue;
|
|
368
397
|
yield {
|
|
369
398
|
kind: "literal",
|
|
370
399
|
text: optionName$1,
|
|
@@ -524,10 +553,18 @@ function option(...args) {
|
|
|
524
553
|
};
|
|
525
554
|
});
|
|
526
555
|
}
|
|
527
|
-
const prefixes = optionNames$1.filter((name) => name.startsWith("--") || name.startsWith("/") || name.startsWith("-") && name.length > 2).map((name) =>
|
|
528
|
-
|
|
556
|
+
const prefixes = optionNames$1.filter((name) => name.startsWith("--") || name.startsWith("/") || name.startsWith("-") && name.length > 2 && !/^-[^-]$/u.test(name)).map((name) => ({
|
|
557
|
+
optionName: name,
|
|
558
|
+
prefix: name.startsWith("/") ? `${name}:` : `${name}=`
|
|
559
|
+
}));
|
|
560
|
+
if (valueParser != null && optionNames$1.some((name) => /^-[^-]$/u.test(name) && context.buffer[0].startsWith(name)) && !require_short_option.fullNameOwnsToken(context, context.buffer[0])) {
|
|
561
|
+
for (const name of optionNames$1) if (/^-[^-]$/u.test(name)) prefixes.push({
|
|
562
|
+
optionName: name,
|
|
563
|
+
prefix: name
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
for (const { prefix, optionName: optionName$1 } of prefixes) {
|
|
529
567
|
if (!context.buffer[0].startsWith(prefix)) continue;
|
|
530
|
-
const optionName$1 = prefix.slice(0, -1);
|
|
531
568
|
if (hasParsedOptionValue(context.state, valueParser)) return {
|
|
532
569
|
success: false,
|
|
533
570
|
consumed: 1,
|
|
@@ -566,9 +603,9 @@ function option(...args) {
|
|
|
566
603
|
});
|
|
567
604
|
}
|
|
568
605
|
if (valueParser == null) {
|
|
569
|
-
const shortOptions = optionNames$1.filter((name) => name.match(/^-[^-]$/));
|
|
606
|
+
const shortOptions = optionNames$1.filter((name) => name.match(/^-[^-]$/u));
|
|
570
607
|
for (const shortOption of shortOptions) {
|
|
571
|
-
if (!context.buffer[0].startsWith(shortOption)) continue;
|
|
608
|
+
if (!context.buffer[0].startsWith(shortOption) || require_short_option.fullNameOwnsToken(context, context.buffer[0])) continue;
|
|
572
609
|
if (hasParsedOptionValue(context.state, valueParser)) return {
|
|
573
610
|
success: false,
|
|
574
611
|
consumed: 1,
|
|
@@ -582,9 +619,9 @@ function option(...args) {
|
|
|
582
619
|
success: true,
|
|
583
620
|
value: true
|
|
584
621
|
},
|
|
585
|
-
buffer: [`-${context.buffer[0].slice(
|
|
622
|
+
buffer: [`-${context.buffer[0].slice(shortOption.length)}`, ...context.buffer.slice(1)]
|
|
586
623
|
},
|
|
587
|
-
consumed: [context.buffer[0].slice(0,
|
|
624
|
+
consumed: [context.buffer[0].slice(0, shortOption.length)]
|
|
588
625
|
};
|
|
589
626
|
}
|
|
590
627
|
}
|
|
@@ -846,7 +883,7 @@ function flag(...args) {
|
|
|
846
883
|
consumed: context.buffer.slice(0, 1)
|
|
847
884
|
};
|
|
848
885
|
}
|
|
849
|
-
const prefixes = optionNames$1.filter((name) => name.startsWith("--") || name.startsWith("/") || name.startsWith("-") && name.length > 2).map((name) => name.startsWith("/") ? `${name}:` : `${name}=`);
|
|
886
|
+
const prefixes = optionNames$1.filter((name) => name.startsWith("--") || name.startsWith("/") || name.startsWith("-") && name.length > 2 && !/^-[^-]$/u.test(name)).map((name) => name.startsWith("/") ? `${name}:` : `${name}=`);
|
|
850
887
|
for (const prefix of prefixes) if (context.buffer[0].startsWith(prefix)) {
|
|
851
888
|
const value = context.buffer[0].slice(prefix.length);
|
|
852
889
|
return {
|
|
@@ -855,9 +892,9 @@ function flag(...args) {
|
|
|
855
892
|
error: require_message.message`Flag ${require_message.optionName(prefix.slice(0, -1))} does not accept a value, but got: ${value}.`
|
|
856
893
|
};
|
|
857
894
|
}
|
|
858
|
-
const shortOptions = optionNames$1.filter((name) => name.match(/^-[^-]$/));
|
|
895
|
+
const shortOptions = optionNames$1.filter((name) => name.match(/^-[^-]$/u));
|
|
859
896
|
for (const shortOption of shortOptions) {
|
|
860
|
-
if (!context.buffer[0].startsWith(shortOption)) continue;
|
|
897
|
+
if (!context.buffer[0].startsWith(shortOption) || require_short_option.fullNameOwnsToken(context, context.buffer[0])) continue;
|
|
861
898
|
if (context.state?.success) return {
|
|
862
899
|
success: false,
|
|
863
900
|
consumed: 1,
|
|
@@ -871,9 +908,9 @@ function flag(...args) {
|
|
|
871
908
|
success: true,
|
|
872
909
|
value: true
|
|
873
910
|
},
|
|
874
|
-
buffer: [`-${context.buffer[0].slice(
|
|
911
|
+
buffer: [`-${context.buffer[0].slice(shortOption.length)}`, ...context.buffer.slice(1)]
|
|
875
912
|
},
|
|
876
|
-
consumed: [context.buffer[0].slice(0,
|
|
913
|
+
consumed: [context.buffer[0].slice(0, shortOption.length)]
|
|
877
914
|
};
|
|
878
915
|
}
|
|
879
916
|
const invalidOption = context.buffer[0];
|
|
@@ -914,7 +951,7 @@ function flag(...args) {
|
|
|
914
951
|
const suggestions = [];
|
|
915
952
|
if (prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/") || prefix.startsWith("+")) {
|
|
916
953
|
for (const optionName$1 of optionNames$1) if (optionName$1.startsWith(prefix)) {
|
|
917
|
-
if (prefix === "-" && optionName$1
|
|
954
|
+
if (prefix === "-" && !/^-[^-]$/u.test(optionName$1)) continue;
|
|
918
955
|
suggestions.push({
|
|
919
956
|
kind: "literal",
|
|
920
957
|
text: optionName$1,
|
|
@@ -1065,7 +1102,7 @@ function negatableFlag(names, options = {}) {
|
|
|
1065
1102
|
const directValue = valueByName.get(context.buffer[0]);
|
|
1066
1103
|
if (directValue != null) return parseMatchedNegatableFlag(context, context.buffer[0], directValue, context.buffer.slice(0, 1), 1, context.buffer.slice(1), options);
|
|
1067
1104
|
for (const name of optionNames$1) {
|
|
1068
|
-
if (!name.startsWith("--") && !name.startsWith("/") && !name.startsWith("+") && !(name.startsWith("-") && name.length > 2)) continue;
|
|
1105
|
+
if (!name.startsWith("--") && !name.startsWith("/") && !name.startsWith("+") && !(name.startsWith("-") && name.length > 2 && !/^-[^-]$/u.test(name))) continue;
|
|
1069
1106
|
const prefix = name.startsWith("/") ? `${name}:` : `${name}=`;
|
|
1070
1107
|
if (context.buffer[0].startsWith(prefix)) {
|
|
1071
1108
|
const value = context.buffer[0].slice(prefix.length);
|
|
@@ -1077,9 +1114,9 @@ function negatableFlag(names, options = {}) {
|
|
|
1077
1114
|
}
|
|
1078
1115
|
}
|
|
1079
1116
|
for (const shortOption of optionNames$1) {
|
|
1080
|
-
if (!shortOption.match(/^-[^-]$/)) continue;
|
|
1081
|
-
if (!context.buffer[0].startsWith(shortOption)) continue;
|
|
1082
|
-
return parseMatchedNegatableFlag(context, shortOption, valueByName.get(shortOption), [context.buffer[0].slice(0,
|
|
1117
|
+
if (!shortOption.match(/^-[^-]$/u)) continue;
|
|
1118
|
+
if (!context.buffer[0].startsWith(shortOption) || require_short_option.fullNameOwnsToken(context, context.buffer[0])) continue;
|
|
1119
|
+
return parseMatchedNegatableFlag(context, shortOption, valueByName.get(shortOption), [context.buffer[0].slice(0, shortOption.length)], 1, [`-${context.buffer[0].slice(shortOption.length)}`, ...context.buffer.slice(1)], options);
|
|
1083
1120
|
}
|
|
1084
1121
|
const invalidOption = context.buffer[0];
|
|
1085
1122
|
if (options.errors?.noMatch) {
|
|
@@ -1114,7 +1151,7 @@ function negatableFlag(names, options = {}) {
|
|
|
1114
1151
|
const suggestions = [];
|
|
1115
1152
|
if (prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/") || prefix.startsWith("+")) {
|
|
1116
1153
|
for (const optionName$1 of optionNames$1) if (optionName$1.startsWith(prefix)) {
|
|
1117
|
-
if (prefix === "-" && optionName$1
|
|
1154
|
+
if (prefix === "-" && !/^-[^-]$/u.test(optionName$1)) continue;
|
|
1118
1155
|
suggestions.push({
|
|
1119
1156
|
kind: "literal",
|
|
1120
1157
|
text: optionName$1
|
|
@@ -1487,6 +1524,8 @@ function command(name, parser, options = {}) {
|
|
|
1487
1524
|
const isAsync = parser.mode === "async";
|
|
1488
1525
|
const syncInnerParser = parser;
|
|
1489
1526
|
const asyncInnerParser = parser;
|
|
1527
|
+
const commandScope = require_short_option.selectableOptionScope(() => new Set(commandNames));
|
|
1528
|
+
const enteredScope = require_short_option.combinedOptionScope([parser], [name]);
|
|
1490
1529
|
const result = {
|
|
1491
1530
|
[Symbol.for("@optique/core/commandParser")]: true,
|
|
1492
1531
|
mode: parser.mode,
|
|
@@ -1554,6 +1593,7 @@ function command(name, parser, options = {}) {
|
|
|
1554
1593
|
] : baseError
|
|
1555
1594
|
};
|
|
1556
1595
|
}
|
|
1596
|
+
commandScope.select(context, enteredScope);
|
|
1557
1597
|
return {
|
|
1558
1598
|
success: true,
|
|
1559
1599
|
next: {
|
|
@@ -1734,7 +1774,9 @@ function command(name, parser, options = {}) {
|
|
|
1734
1774
|
configurable: true,
|
|
1735
1775
|
enumerable: false
|
|
1736
1776
|
});
|
|
1737
|
-
return require_modifiers.fluent(result)
|
|
1777
|
+
return require_modifiers.fluent(require_short_option.scopeParser(result, commandScope.source, (context) => {
|
|
1778
|
+
if (normalizeCommandState(context.state) != null) commandScope.select(context, enteredScope);
|
|
1779
|
+
}));
|
|
1738
1780
|
}
|
|
1739
1781
|
/**
|
|
1740
1782
|
* Creates a parser that collects unrecognized options and passes them through.
|