@optique/core 1.0.0-dev.1267 → 1.0.0-dev.1288
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 +43 -16
- package/dist/facade.js +43 -16
- package/package.json +1 -1
package/dist/facade.cjs
CHANGED
|
@@ -875,23 +875,48 @@ 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
|
-
|
|
881
|
-
const
|
|
882
|
-
|
|
883
|
-
if (
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
882
|
+
const hasMetaEntryBefore = (endIndex) => {
|
|
883
|
+
const argsBefore = args.slice(0, endIndex);
|
|
884
|
+
if (helpOptionConfig && helpOptionNames.some((n) => argsBefore.includes(n))) return true;
|
|
885
|
+
if (versionOptionConfig && versionOptionNames.some((n) => argsBefore.includes(n))) return true;
|
|
886
|
+
if (endIndex > 0) {
|
|
887
|
+
if (helpCommandConfig && helpCommandNames.includes(args[0])) return true;
|
|
888
|
+
if (versionCommandConfig && versionCommandNames.includes(args[0])) return true;
|
|
887
889
|
}
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
890
|
+
return false;
|
|
891
|
+
};
|
|
892
|
+
let completionOptionIndex = -1;
|
|
893
|
+
if (completionOptionConfig) {
|
|
894
|
+
const loopBound = helpTerminatorIndex >= 0 ? helpTerminatorIndex : args.length;
|
|
895
|
+
for (let i = 0; i < loopBound; i++) {
|
|
896
|
+
const arg = args[i];
|
|
897
|
+
const equalsMatch = completionOptionNames.find((n) => arg.startsWith(n + "="));
|
|
898
|
+
if (equalsMatch) {
|
|
899
|
+
if (hasMetaEntryBefore(i)) {
|
|
900
|
+
completionOptionIndex = i;
|
|
901
|
+
break;
|
|
902
|
+
}
|
|
903
|
+
const shell = arg.slice(equalsMatch.length + 1);
|
|
904
|
+
const completionArgs = args.slice(i + 1);
|
|
905
|
+
return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionOption, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, completionCommandNames[0], completionOptionNames[0], true, sectionOrder);
|
|
906
|
+
}
|
|
907
|
+
const exactMatch = completionOptionNames.includes(arg);
|
|
908
|
+
if (exactMatch) {
|
|
909
|
+
if (hasMetaEntryBefore(i)) {
|
|
910
|
+
completionOptionIndex = i;
|
|
911
|
+
break;
|
|
912
|
+
}
|
|
913
|
+
const shell = i + 1 < args.length ? args[i + 1] : "";
|
|
914
|
+
const completionArgs = i + 1 < args.length ? args.slice(i + 2) : [];
|
|
915
|
+
return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionOption, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, completionCommandNames[0], completionOptionNames[0], true, sectionOrder);
|
|
916
|
+
}
|
|
893
917
|
}
|
|
894
918
|
}
|
|
919
|
+
if (completionOptionIndex >= 0) args = args.slice(0, completionOptionIndex);
|
|
895
920
|
}
|
|
896
921
|
const augmentedParser = !options.help && !options.version && !options.completion ? parser : combineWithHelpVersion(parser, helpParsers, versionParsers, completionParsers, {
|
|
897
922
|
helpCommandGroup: helpCommandConfig?.group,
|
|
@@ -1160,12 +1185,14 @@ function indentLines(text$1, indent) {
|
|
|
1160
1185
|
*/
|
|
1161
1186
|
function needsEarlyExit(args, options) {
|
|
1162
1187
|
const norm = (c) => c === true ? {} : c;
|
|
1188
|
+
const terminatorIndex = args.indexOf("--");
|
|
1189
|
+
const optionArgs = terminatorIndex >= 0 ? args.slice(0, terminatorIndex) : args;
|
|
1163
1190
|
if (options.help) {
|
|
1164
1191
|
const helpOptionConfig = norm(options.help.option);
|
|
1165
1192
|
const helpCommandConfig = norm(options.help.command);
|
|
1166
1193
|
const helpOptionNames = helpOptionConfig?.names ?? ["--help"];
|
|
1167
1194
|
const helpCommandNames = helpCommandConfig?.names ?? ["help"];
|
|
1168
|
-
if (helpOptionConfig && helpOptionNames.some((n) =>
|
|
1195
|
+
if (helpOptionConfig && helpOptionNames.some((n) => optionArgs.includes(n))) return true;
|
|
1169
1196
|
if (helpCommandConfig && helpCommandNames.includes(args[0])) return true;
|
|
1170
1197
|
}
|
|
1171
1198
|
if (options.version) {
|
|
@@ -1173,7 +1200,7 @@ function needsEarlyExit(args, options) {
|
|
|
1173
1200
|
const versionCommandConfig = norm(options.version.command);
|
|
1174
1201
|
const versionOptionNames = versionOptionConfig?.names ?? ["--version"];
|
|
1175
1202
|
const versionCommandNames = versionCommandConfig?.names ?? ["version"];
|
|
1176
|
-
if (versionOptionConfig && versionOptionNames.some((n) =>
|
|
1203
|
+
if (versionOptionConfig && versionOptionNames.some((n) => optionArgs.includes(n))) return true;
|
|
1177
1204
|
if (versionCommandConfig && versionCommandNames.includes(args[0])) return true;
|
|
1178
1205
|
}
|
|
1179
1206
|
if (options.completion) {
|
|
@@ -1183,7 +1210,7 @@ function needsEarlyExit(args, options) {
|
|
|
1183
1210
|
const completionOptionNames = completionOptionConfig?.names ?? ["--completion"];
|
|
1184
1211
|
if (completionCommandConfig && completionCommandNames.includes(args[0])) return true;
|
|
1185
1212
|
if (completionOptionConfig) {
|
|
1186
|
-
for (const arg of
|
|
1213
|
+
for (const arg of optionArgs) for (const name of completionOptionNames) if (arg === name || arg.startsWith(name + "=")) return true;
|
|
1187
1214
|
}
|
|
1188
1215
|
}
|
|
1189
1216
|
return false;
|
package/dist/facade.js
CHANGED
|
@@ -875,23 +875,48 @@ 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
|
-
|
|
881
|
-
const
|
|
882
|
-
|
|
883
|
-
if (
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
882
|
+
const hasMetaEntryBefore = (endIndex) => {
|
|
883
|
+
const argsBefore = args.slice(0, endIndex);
|
|
884
|
+
if (helpOptionConfig && helpOptionNames.some((n) => argsBefore.includes(n))) return true;
|
|
885
|
+
if (versionOptionConfig && versionOptionNames.some((n) => argsBefore.includes(n))) return true;
|
|
886
|
+
if (endIndex > 0) {
|
|
887
|
+
if (helpCommandConfig && helpCommandNames.includes(args[0])) return true;
|
|
888
|
+
if (versionCommandConfig && versionCommandNames.includes(args[0])) return true;
|
|
887
889
|
}
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
890
|
+
return false;
|
|
891
|
+
};
|
|
892
|
+
let completionOptionIndex = -1;
|
|
893
|
+
if (completionOptionConfig) {
|
|
894
|
+
const loopBound = helpTerminatorIndex >= 0 ? helpTerminatorIndex : args.length;
|
|
895
|
+
for (let i = 0; i < loopBound; i++) {
|
|
896
|
+
const arg = args[i];
|
|
897
|
+
const equalsMatch = completionOptionNames.find((n) => arg.startsWith(n + "="));
|
|
898
|
+
if (equalsMatch) {
|
|
899
|
+
if (hasMetaEntryBefore(i)) {
|
|
900
|
+
completionOptionIndex = i;
|
|
901
|
+
break;
|
|
902
|
+
}
|
|
903
|
+
const shell = arg.slice(equalsMatch.length + 1);
|
|
904
|
+
const completionArgs = args.slice(i + 1);
|
|
905
|
+
return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionOption, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, completionCommandNames[0], completionOptionNames[0], true, sectionOrder);
|
|
906
|
+
}
|
|
907
|
+
const exactMatch = completionOptionNames.includes(arg);
|
|
908
|
+
if (exactMatch) {
|
|
909
|
+
if (hasMetaEntryBefore(i)) {
|
|
910
|
+
completionOptionIndex = i;
|
|
911
|
+
break;
|
|
912
|
+
}
|
|
913
|
+
const shell = i + 1 < args.length ? args[i + 1] : "";
|
|
914
|
+
const completionArgs = i + 1 < args.length ? args.slice(i + 2) : [];
|
|
915
|
+
return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionOption, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, completionCommandNames[0], completionOptionNames[0], true, sectionOrder);
|
|
916
|
+
}
|
|
893
917
|
}
|
|
894
918
|
}
|
|
919
|
+
if (completionOptionIndex >= 0) args = args.slice(0, completionOptionIndex);
|
|
895
920
|
}
|
|
896
921
|
const augmentedParser = !options.help && !options.version && !options.completion ? parser : combineWithHelpVersion(parser, helpParsers, versionParsers, completionParsers, {
|
|
897
922
|
helpCommandGroup: helpCommandConfig?.group,
|
|
@@ -1160,12 +1185,14 @@ function indentLines(text$1, indent) {
|
|
|
1160
1185
|
*/
|
|
1161
1186
|
function needsEarlyExit(args, options) {
|
|
1162
1187
|
const norm = (c) => c === true ? {} : c;
|
|
1188
|
+
const terminatorIndex = args.indexOf("--");
|
|
1189
|
+
const optionArgs = terminatorIndex >= 0 ? args.slice(0, terminatorIndex) : args;
|
|
1163
1190
|
if (options.help) {
|
|
1164
1191
|
const helpOptionConfig = norm(options.help.option);
|
|
1165
1192
|
const helpCommandConfig = norm(options.help.command);
|
|
1166
1193
|
const helpOptionNames = helpOptionConfig?.names ?? ["--help"];
|
|
1167
1194
|
const helpCommandNames = helpCommandConfig?.names ?? ["help"];
|
|
1168
|
-
if (helpOptionConfig && helpOptionNames.some((n) =>
|
|
1195
|
+
if (helpOptionConfig && helpOptionNames.some((n) => optionArgs.includes(n))) return true;
|
|
1169
1196
|
if (helpCommandConfig && helpCommandNames.includes(args[0])) return true;
|
|
1170
1197
|
}
|
|
1171
1198
|
if (options.version) {
|
|
@@ -1173,7 +1200,7 @@ function needsEarlyExit(args, options) {
|
|
|
1173
1200
|
const versionCommandConfig = norm(options.version.command);
|
|
1174
1201
|
const versionOptionNames = versionOptionConfig?.names ?? ["--version"];
|
|
1175
1202
|
const versionCommandNames = versionCommandConfig?.names ?? ["version"];
|
|
1176
|
-
if (versionOptionConfig && versionOptionNames.some((n) =>
|
|
1203
|
+
if (versionOptionConfig && versionOptionNames.some((n) => optionArgs.includes(n))) return true;
|
|
1177
1204
|
if (versionCommandConfig && versionCommandNames.includes(args[0])) return true;
|
|
1178
1205
|
}
|
|
1179
1206
|
if (options.completion) {
|
|
@@ -1183,7 +1210,7 @@ function needsEarlyExit(args, options) {
|
|
|
1183
1210
|
const completionOptionNames = completionOptionConfig?.names ?? ["--completion"];
|
|
1184
1211
|
if (completionCommandConfig && completionCommandNames.includes(args[0])) return true;
|
|
1185
1212
|
if (completionOptionConfig) {
|
|
1186
|
-
for (const arg of
|
|
1213
|
+
for (const arg of optionArgs) for (const name of completionOptionNames) if (arg === name || arg.startsWith(name + "=")) return true;
|
|
1187
1214
|
}
|
|
1188
1215
|
}
|
|
1189
1216
|
return false;
|