@optique/core 0.9.5 → 0.9.7

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 CHANGED
@@ -284,9 +284,26 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers, com
284
284
  completion: require_primitives.constant(false),
285
285
  result: originalParser
286
286
  }));
287
+ const mainParserIndex = parsers.length - 1;
287
288
  if (parsers.length === 1) return parsers[0];
288
- else if (parsers.length === 2) return require_constructs.longestMatch(parsers[0], parsers[1]);
289
- else return require_constructs.longestMatch(...parsers);
289
+ let combined;
290
+ if (parsers.length === 2) combined = require_constructs.longestMatch(parsers[0], parsers[1]);
291
+ else combined = require_constructs.longestMatch(...parsers);
292
+ const topUsage = combined.usage[0];
293
+ if (topUsage?.type === "exclusive" && mainParserIndex > 0) {
294
+ const terms = [...topUsage.terms];
295
+ const [mainTerm] = terms.splice(mainParserIndex, 1);
296
+ const lenientCount = (helpParsers.helpOption ? 1 : 0) + (versionParsers.versionOption ? 1 : 0);
297
+ terms.splice(lenientCount, 0, mainTerm);
298
+ combined = {
299
+ ...combined,
300
+ usage: [{
301
+ ...topUsage,
302
+ terms
303
+ }]
304
+ };
305
+ }
306
+ return combined;
290
307
  }
291
308
  /**
292
309
  * Classifies the parsing result into a discriminated union for cleaner handling.
package/dist/facade.js CHANGED
@@ -284,9 +284,26 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers, com
284
284
  completion: constant(false),
285
285
  result: originalParser
286
286
  }));
287
+ const mainParserIndex = parsers.length - 1;
287
288
  if (parsers.length === 1) return parsers[0];
288
- else if (parsers.length === 2) return longestMatch(parsers[0], parsers[1]);
289
- else return longestMatch(...parsers);
289
+ let combined;
290
+ if (parsers.length === 2) combined = longestMatch(parsers[0], parsers[1]);
291
+ else combined = longestMatch(...parsers);
292
+ const topUsage = combined.usage[0];
293
+ if (topUsage?.type === "exclusive" && mainParserIndex > 0) {
294
+ const terms = [...topUsage.terms];
295
+ const [mainTerm] = terms.splice(mainParserIndex, 1);
296
+ const lenientCount = (helpParsers.helpOption ? 1 : 0) + (versionParsers.versionOption ? 1 : 0);
297
+ terms.splice(lenientCount, 0, mainTerm);
298
+ combined = {
299
+ ...combined,
300
+ usage: [{
301
+ ...topUsage,
302
+ terms
303
+ }]
304
+ };
305
+ }
306
+ return combined;
290
307
  }
291
308
  /**
292
309
  * Classifies the parsing result into a discriminated union for cleaner handling.
package/dist/usage.cjs CHANGED
@@ -194,8 +194,10 @@ function normalizeUsageTerm(term) {
194
194
  const terms = [];
195
195
  for (const usage of term.terms) {
196
196
  const normalized = normalizeUsage(usage);
197
- if (normalized.length === 1 && normalized[0].type === "exclusive") for (const subUsage of normalized[0].terms) terms.push(subUsage);
198
- else terms.push(normalized);
197
+ if (normalized.length >= 1 && normalized[0].type === "exclusive") {
198
+ const rest = normalized.slice(1);
199
+ for (const subUsage of normalized[0].terms) terms.push([...subUsage, ...rest]);
200
+ } else terms.push(normalized);
199
201
  }
200
202
  return {
201
203
  type: "exclusive",
package/dist/usage.js CHANGED
@@ -193,8 +193,10 @@ function normalizeUsageTerm(term) {
193
193
  const terms = [];
194
194
  for (const usage of term.terms) {
195
195
  const normalized = normalizeUsage(usage);
196
- if (normalized.length === 1 && normalized[0].type === "exclusive") for (const subUsage of normalized[0].terms) terms.push(subUsage);
197
- else terms.push(normalized);
196
+ if (normalized.length >= 1 && normalized[0].type === "exclusive") {
197
+ const rest = normalized.slice(1);
198
+ for (const subUsage of normalized[0].terms) terms.push([...subUsage, ...rest]);
199
+ } else terms.push(normalized);
198
200
  }
199
201
  return {
200
202
  type: "exclusive",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "0.9.5",
3
+ "version": "0.9.7",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",