@optique/core 1.0.0-dev.1555 → 1.0.0-dev.1561

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/usage.cjs CHANGED
@@ -239,6 +239,9 @@ function formatUsage(programName, usage, options = {}) {
239
239
  * nested exclusive terms into their parent exclusive term to avoid
240
240
  * redundant nesting. For example, an exclusive term containing another
241
241
  * exclusive term will have its nested terms flattened into the parent.
242
+ * Similarly, nested optional terms are collapsed:
243
+ * `optional(optional(X))` becomes `optional(X)` when the outer optional
244
+ * contains only a single inner optional term.
242
245
  *
243
246
  * 3. *Sorting*: Reorders terms to improve readability by placing:
244
247
  * - Commands (subcommands) first
@@ -251,8 +254,8 @@ function formatUsage(programName, usage, options = {}) {
251
254
  *
252
255
  * @param usage The usage description to normalize.
253
256
  * @returns A normalized usage description with degenerate terms removed,
254
- * nested exclusive terms flattened, and remaining terms sorted for
255
- * optimal readability.
257
+ * nested exclusive and optional terms flattened, and remaining
258
+ * terms sorted for optimal readability.
256
259
  */
257
260
  function normalizeUsage(usage) {
258
261
  const terms = usage.map(normalizeUsageTerm).filter(isNonDegenerateTerm);
@@ -266,11 +269,14 @@ function normalizeUsage(usage) {
266
269
  return terms;
267
270
  }
268
271
  function normalizeUsageTerm(term) {
269
- if (term.type === "optional") return {
270
- type: "optional",
271
- terms: normalizeUsage(term.terms)
272
- };
273
- else if (term.type === "multiple") return {
272
+ if (term.type === "optional") {
273
+ const normalized = normalizeUsage(term.terms);
274
+ if (normalized.length === 1 && normalized[0].type === "optional") return normalized[0];
275
+ return {
276
+ type: "optional",
277
+ terms: normalized
278
+ };
279
+ } else if (term.type === "multiple") return {
274
280
  type: "multiple",
275
281
  terms: normalizeUsage(term.terms),
276
282
  min: term.min
package/dist/usage.d.cts CHANGED
@@ -379,6 +379,9 @@ declare function formatUsage(programName: string, usage: Usage, options?: UsageF
379
379
  * nested exclusive terms into their parent exclusive term to avoid
380
380
  * redundant nesting. For example, an exclusive term containing another
381
381
  * exclusive term will have its nested terms flattened into the parent.
382
+ * Similarly, nested optional terms are collapsed:
383
+ * `optional(optional(X))` becomes `optional(X)` when the outer optional
384
+ * contains only a single inner optional term.
382
385
  *
383
386
  * 3. *Sorting*: Reorders terms to improve readability by placing:
384
387
  * - Commands (subcommands) first
@@ -391,8 +394,8 @@ declare function formatUsage(programName: string, usage: Usage, options?: UsageF
391
394
  *
392
395
  * @param usage The usage description to normalize.
393
396
  * @returns A normalized usage description with degenerate terms removed,
394
- * nested exclusive terms flattened, and remaining terms sorted for
395
- * optimal readability.
397
+ * nested exclusive and optional terms flattened, and remaining
398
+ * terms sorted for optimal readability.
396
399
  */
397
400
  declare function normalizeUsage(usage: Usage): Usage;
398
401
  /**
package/dist/usage.d.ts CHANGED
@@ -379,6 +379,9 @@ declare function formatUsage(programName: string, usage: Usage, options?: UsageF
379
379
  * nested exclusive terms into their parent exclusive term to avoid
380
380
  * redundant nesting. For example, an exclusive term containing another
381
381
  * exclusive term will have its nested terms flattened into the parent.
382
+ * Similarly, nested optional terms are collapsed:
383
+ * `optional(optional(X))` becomes `optional(X)` when the outer optional
384
+ * contains only a single inner optional term.
382
385
  *
383
386
  * 3. *Sorting*: Reorders terms to improve readability by placing:
384
387
  * - Commands (subcommands) first
@@ -391,8 +394,8 @@ declare function formatUsage(programName: string, usage: Usage, options?: UsageF
391
394
  *
392
395
  * @param usage The usage description to normalize.
393
396
  * @returns A normalized usage description with degenerate terms removed,
394
- * nested exclusive terms flattened, and remaining terms sorted for
395
- * optimal readability.
397
+ * nested exclusive and optional terms flattened, and remaining
398
+ * terms sorted for optimal readability.
396
399
  */
397
400
  declare function normalizeUsage(usage: Usage): Usage;
398
401
  /**
package/dist/usage.js CHANGED
@@ -239,6 +239,9 @@ function formatUsage(programName, usage, options = {}) {
239
239
  * nested exclusive terms into their parent exclusive term to avoid
240
240
  * redundant nesting. For example, an exclusive term containing another
241
241
  * exclusive term will have its nested terms flattened into the parent.
242
+ * Similarly, nested optional terms are collapsed:
243
+ * `optional(optional(X))` becomes `optional(X)` when the outer optional
244
+ * contains only a single inner optional term.
242
245
  *
243
246
  * 3. *Sorting*: Reorders terms to improve readability by placing:
244
247
  * - Commands (subcommands) first
@@ -251,8 +254,8 @@ function formatUsage(programName, usage, options = {}) {
251
254
  *
252
255
  * @param usage The usage description to normalize.
253
256
  * @returns A normalized usage description with degenerate terms removed,
254
- * nested exclusive terms flattened, and remaining terms sorted for
255
- * optimal readability.
257
+ * nested exclusive and optional terms flattened, and remaining
258
+ * terms sorted for optimal readability.
256
259
  */
257
260
  function normalizeUsage(usage) {
258
261
  const terms = usage.map(normalizeUsageTerm).filter(isNonDegenerateTerm);
@@ -266,11 +269,14 @@ function normalizeUsage(usage) {
266
269
  return terms;
267
270
  }
268
271
  function normalizeUsageTerm(term) {
269
- if (term.type === "optional") return {
270
- type: "optional",
271
- terms: normalizeUsage(term.terms)
272
- };
273
- else if (term.type === "multiple") return {
272
+ if (term.type === "optional") {
273
+ const normalized = normalizeUsage(term.terms);
274
+ if (normalized.length === 1 && normalized[0].type === "optional") return normalized[0];
275
+ return {
276
+ type: "optional",
277
+ terms: normalized
278
+ };
279
+ } else if (term.type === "multiple") return {
274
280
  type: "multiple",
275
281
  terms: normalizeUsage(term.terms),
276
282
  min: term.min
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.1555+118c402b",
3
+ "version": "1.0.0-dev.1561+241c020e",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",