@optique/core 1.0.0-dev.1267 → 1.0.0-dev.1279
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/facade.cjs +24 -17
- package/dist/facade.js +24 -17
- package/package.json +1 -1
package/dist/facade.cjs
CHANGED
|
@@ -875,21 +875,26 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
875
875
|
completionOption: null
|
|
876
876
|
};
|
|
877
877
|
if (options.completion) {
|
|
878
|
-
const
|
|
878
|
+
const helpTerminatorIndex = args.indexOf("--");
|
|
879
|
+
const helpOptionArgs = helpTerminatorIndex >= 0 ? args.slice(0, helpTerminatorIndex) : args;
|
|
880
|
+
const hasHelpOption = helpOptionConfig ? completionCommandConfig && completionCommandNames.includes(args[0]) ? args.length >= 2 && helpOptionNames.includes(args[1]) : helpOptionNames.some((n) => helpOptionArgs.includes(n)) : false;
|
|
879
881
|
if (completionCommandConfig && args.length >= 1 && completionCommandNames.includes(args[0]) && !hasHelpOption) return handleCompletion(args.slice(1), programName, parser, completionParsers.completionCommand, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, completionCommandNames[0], completionOptionNames[0], false, sectionOrder);
|
|
880
|
-
if (completionOptionConfig)
|
|
881
|
-
const
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
const
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
const
|
|
891
|
-
|
|
892
|
-
|
|
882
|
+
if (completionOptionConfig) {
|
|
883
|
+
const loopBound = helpTerminatorIndex >= 0 ? helpTerminatorIndex : args.length;
|
|
884
|
+
for (let i = 0; i < loopBound; i++) {
|
|
885
|
+
const arg = args[i];
|
|
886
|
+
const equalsMatch = completionOptionNames.find((n) => arg.startsWith(n + "="));
|
|
887
|
+
if (equalsMatch) {
|
|
888
|
+
const shell = arg.slice(equalsMatch.length + 1);
|
|
889
|
+
const completionArgs = args.slice(i + 1);
|
|
890
|
+
return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionOption, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, completionCommandNames[0], completionOptionNames[0], true, sectionOrder);
|
|
891
|
+
}
|
|
892
|
+
const exactMatch = completionOptionNames.includes(arg);
|
|
893
|
+
if (exactMatch) {
|
|
894
|
+
const shell = i + 1 < args.length ? args[i + 1] : "";
|
|
895
|
+
const completionArgs = i + 1 < args.length ? args.slice(i + 2) : [];
|
|
896
|
+
return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionOption, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, completionCommandNames[0], completionOptionNames[0], true, sectionOrder);
|
|
897
|
+
}
|
|
893
898
|
}
|
|
894
899
|
}
|
|
895
900
|
}
|
|
@@ -1160,12 +1165,14 @@ function indentLines(text$1, indent) {
|
|
|
1160
1165
|
*/
|
|
1161
1166
|
function needsEarlyExit(args, options) {
|
|
1162
1167
|
const norm = (c) => c === true ? {} : c;
|
|
1168
|
+
const terminatorIndex = args.indexOf("--");
|
|
1169
|
+
const optionArgs = terminatorIndex >= 0 ? args.slice(0, terminatorIndex) : args;
|
|
1163
1170
|
if (options.help) {
|
|
1164
1171
|
const helpOptionConfig = norm(options.help.option);
|
|
1165
1172
|
const helpCommandConfig = norm(options.help.command);
|
|
1166
1173
|
const helpOptionNames = helpOptionConfig?.names ?? ["--help"];
|
|
1167
1174
|
const helpCommandNames = helpCommandConfig?.names ?? ["help"];
|
|
1168
|
-
if (helpOptionConfig && helpOptionNames.some((n) =>
|
|
1175
|
+
if (helpOptionConfig && helpOptionNames.some((n) => optionArgs.includes(n))) return true;
|
|
1169
1176
|
if (helpCommandConfig && helpCommandNames.includes(args[0])) return true;
|
|
1170
1177
|
}
|
|
1171
1178
|
if (options.version) {
|
|
@@ -1173,7 +1180,7 @@ function needsEarlyExit(args, options) {
|
|
|
1173
1180
|
const versionCommandConfig = norm(options.version.command);
|
|
1174
1181
|
const versionOptionNames = versionOptionConfig?.names ?? ["--version"];
|
|
1175
1182
|
const versionCommandNames = versionCommandConfig?.names ?? ["version"];
|
|
1176
|
-
if (versionOptionConfig && versionOptionNames.some((n) =>
|
|
1183
|
+
if (versionOptionConfig && versionOptionNames.some((n) => optionArgs.includes(n))) return true;
|
|
1177
1184
|
if (versionCommandConfig && versionCommandNames.includes(args[0])) return true;
|
|
1178
1185
|
}
|
|
1179
1186
|
if (options.completion) {
|
|
@@ -1183,7 +1190,7 @@ function needsEarlyExit(args, options) {
|
|
|
1183
1190
|
const completionOptionNames = completionOptionConfig?.names ?? ["--completion"];
|
|
1184
1191
|
if (completionCommandConfig && completionCommandNames.includes(args[0])) return true;
|
|
1185
1192
|
if (completionOptionConfig) {
|
|
1186
|
-
for (const arg of
|
|
1193
|
+
for (const arg of optionArgs) for (const name of completionOptionNames) if (arg === name || arg.startsWith(name + "=")) return true;
|
|
1187
1194
|
}
|
|
1188
1195
|
}
|
|
1189
1196
|
return false;
|
package/dist/facade.js
CHANGED
|
@@ -875,21 +875,26 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
875
875
|
completionOption: null
|
|
876
876
|
};
|
|
877
877
|
if (options.completion) {
|
|
878
|
-
const
|
|
878
|
+
const helpTerminatorIndex = args.indexOf("--");
|
|
879
|
+
const helpOptionArgs = helpTerminatorIndex >= 0 ? args.slice(0, helpTerminatorIndex) : args;
|
|
880
|
+
const hasHelpOption = helpOptionConfig ? completionCommandConfig && completionCommandNames.includes(args[0]) ? args.length >= 2 && helpOptionNames.includes(args[1]) : helpOptionNames.some((n) => helpOptionArgs.includes(n)) : false;
|
|
879
881
|
if (completionCommandConfig && args.length >= 1 && completionCommandNames.includes(args[0]) && !hasHelpOption) return handleCompletion(args.slice(1), programName, parser, completionParsers.completionCommand, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, completionCommandNames[0], completionOptionNames[0], false, sectionOrder);
|
|
880
|
-
if (completionOptionConfig)
|
|
881
|
-
const
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
const
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
const
|
|
891
|
-
|
|
892
|
-
|
|
882
|
+
if (completionOptionConfig) {
|
|
883
|
+
const loopBound = helpTerminatorIndex >= 0 ? helpTerminatorIndex : args.length;
|
|
884
|
+
for (let i = 0; i < loopBound; i++) {
|
|
885
|
+
const arg = args[i];
|
|
886
|
+
const equalsMatch = completionOptionNames.find((n) => arg.startsWith(n + "="));
|
|
887
|
+
if (equalsMatch) {
|
|
888
|
+
const shell = arg.slice(equalsMatch.length + 1);
|
|
889
|
+
const completionArgs = args.slice(i + 1);
|
|
890
|
+
return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionOption, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, completionCommandNames[0], completionOptionNames[0], true, sectionOrder);
|
|
891
|
+
}
|
|
892
|
+
const exactMatch = completionOptionNames.includes(arg);
|
|
893
|
+
if (exactMatch) {
|
|
894
|
+
const shell = i + 1 < args.length ? args[i + 1] : "";
|
|
895
|
+
const completionArgs = i + 1 < args.length ? args.slice(i + 2) : [];
|
|
896
|
+
return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionOption, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, completionCommandNames[0], completionOptionNames[0], true, sectionOrder);
|
|
897
|
+
}
|
|
893
898
|
}
|
|
894
899
|
}
|
|
895
900
|
}
|
|
@@ -1160,12 +1165,14 @@ function indentLines(text$1, indent) {
|
|
|
1160
1165
|
*/
|
|
1161
1166
|
function needsEarlyExit(args, options) {
|
|
1162
1167
|
const norm = (c) => c === true ? {} : c;
|
|
1168
|
+
const terminatorIndex = args.indexOf("--");
|
|
1169
|
+
const optionArgs = terminatorIndex >= 0 ? args.slice(0, terminatorIndex) : args;
|
|
1163
1170
|
if (options.help) {
|
|
1164
1171
|
const helpOptionConfig = norm(options.help.option);
|
|
1165
1172
|
const helpCommandConfig = norm(options.help.command);
|
|
1166
1173
|
const helpOptionNames = helpOptionConfig?.names ?? ["--help"];
|
|
1167
1174
|
const helpCommandNames = helpCommandConfig?.names ?? ["help"];
|
|
1168
|
-
if (helpOptionConfig && helpOptionNames.some((n) =>
|
|
1175
|
+
if (helpOptionConfig && helpOptionNames.some((n) => optionArgs.includes(n))) return true;
|
|
1169
1176
|
if (helpCommandConfig && helpCommandNames.includes(args[0])) return true;
|
|
1170
1177
|
}
|
|
1171
1178
|
if (options.version) {
|
|
@@ -1173,7 +1180,7 @@ function needsEarlyExit(args, options) {
|
|
|
1173
1180
|
const versionCommandConfig = norm(options.version.command);
|
|
1174
1181
|
const versionOptionNames = versionOptionConfig?.names ?? ["--version"];
|
|
1175
1182
|
const versionCommandNames = versionCommandConfig?.names ?? ["version"];
|
|
1176
|
-
if (versionOptionConfig && versionOptionNames.some((n) =>
|
|
1183
|
+
if (versionOptionConfig && versionOptionNames.some((n) => optionArgs.includes(n))) return true;
|
|
1177
1184
|
if (versionCommandConfig && versionCommandNames.includes(args[0])) return true;
|
|
1178
1185
|
}
|
|
1179
1186
|
if (options.completion) {
|
|
@@ -1183,7 +1190,7 @@ function needsEarlyExit(args, options) {
|
|
|
1183
1190
|
const completionOptionNames = completionOptionConfig?.names ?? ["--completion"];
|
|
1184
1191
|
if (completionCommandConfig && completionCommandNames.includes(args[0])) return true;
|
|
1185
1192
|
if (completionOptionConfig) {
|
|
1186
|
-
for (const arg of
|
|
1193
|
+
for (const arg of optionArgs) for (const name of completionOptionNames) if (arg === name || arg.startsWith(name + "=")) return true;
|
|
1187
1194
|
}
|
|
1188
1195
|
}
|
|
1189
1196
|
return false;
|