@optique/core 1.0.0-dev.489 → 1.0.0-dev.490

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/parser.cjs CHANGED
@@ -416,14 +416,26 @@ function buildDocPage(parser, context, args) {
416
416
  }
417
417
  const sections = buildingSections;
418
418
  const usage = [...require_usage.normalizeUsage(parser.usage)];
419
+ const maybeApplyCommandUsageLine = (term, arg, isLastArg, usageIndex) => {
420
+ if (term?.type !== "command" || term.name !== arg || !isLastArg || term.usageLine == null) return;
421
+ const defaultUsageLine = usage.slice(usageIndex + 1);
422
+ const customUsageLine = typeof term.usageLine === "function" ? term.usageLine(defaultUsageLine) : term.usageLine;
423
+ const normalizedCustomUsageLine = require_usage.normalizeUsage(customUsageLine);
424
+ usage.splice(usageIndex + 1, usage.length - (usageIndex + 1), ...normalizedCustomUsageLine);
425
+ };
419
426
  let i = 0;
420
- for (const arg of args) {
427
+ for (let argIndex = 0; argIndex < args.length; argIndex++) {
428
+ const arg = args[argIndex];
421
429
  if (i >= usage.length) break;
422
- const term = usage[i];
430
+ let term = usage[i];
423
431
  if (term.type === "exclusive") {
424
432
  const found = findCommandInExclusive(term, arg);
425
- if (found) usage.splice(i, 1, ...found);
433
+ if (found) {
434
+ usage.splice(i, 1, ...found);
435
+ term = usage[i];
436
+ }
426
437
  }
438
+ maybeApplyCommandUsageLine(term, arg, argIndex === args.length - 1, i);
427
439
  i++;
428
440
  }
429
441
  return {
package/dist/parser.js CHANGED
@@ -416,14 +416,26 @@ function buildDocPage(parser, context, args) {
416
416
  }
417
417
  const sections = buildingSections;
418
418
  const usage = [...normalizeUsage(parser.usage)];
419
+ const maybeApplyCommandUsageLine = (term, arg, isLastArg, usageIndex) => {
420
+ if (term?.type !== "command" || term.name !== arg || !isLastArg || term.usageLine == null) return;
421
+ const defaultUsageLine = usage.slice(usageIndex + 1);
422
+ const customUsageLine = typeof term.usageLine === "function" ? term.usageLine(defaultUsageLine) : term.usageLine;
423
+ const normalizedCustomUsageLine = normalizeUsage(customUsageLine);
424
+ usage.splice(usageIndex + 1, usage.length - (usageIndex + 1), ...normalizedCustomUsageLine);
425
+ };
419
426
  let i = 0;
420
- for (const arg of args) {
427
+ for (let argIndex = 0; argIndex < args.length; argIndex++) {
428
+ const arg = args[argIndex];
421
429
  if (i >= usage.length) break;
422
- const term = usage[i];
430
+ let term = usage[i];
423
431
  if (term.type === "exclusive") {
424
432
  const found = findCommandInExclusive(term, arg);
425
- if (found) usage.splice(i, 1, ...found);
433
+ if (found) {
434
+ usage.splice(i, 1, ...found);
435
+ term = usage[i];
436
+ }
426
437
  }
438
+ maybeApplyCommandUsageLine(term, arg, argIndex === args.length - 1, i);
427
439
  i++;
428
440
  }
429
441
  return {
@@ -927,6 +927,7 @@ function command(name, parser, options = {}) {
927
927
  usage: [{
928
928
  type: "command",
929
929
  name,
930
+ ...options.usageLine != null && { usageLine: options.usageLine },
930
931
  ...options.hidden != null && { hidden: options.hidden }
931
932
  }, ...parser.usage],
932
933
  initialState: void 0,
@@ -1,5 +1,5 @@
1
1
  import { Message } from "./message.cjs";
2
- import { HiddenVisibility, OptionName } from "./usage.cjs";
2
+ import { HiddenVisibility, OptionName, Usage } from "./usage.cjs";
3
3
  import { ValueParser, ValueParserResult } from "./valueparser.cjs";
4
4
  import { DeferredParseState, PendingDependencySourceState } from "./dependency.cjs";
5
5
  import { Mode, Parser } from "./parser.cjs";
@@ -326,6 +326,19 @@ interface CommandOptions {
326
326
  * @since 0.6.0
327
327
  */
328
328
  readonly footer?: Message;
329
+ /**
330
+ * Usage line override for this command's own help page.
331
+ *
332
+ * This option customizes the usage tail shown when rendering help for this
333
+ * command itself (e.g., `myapp config --help`). It does not change parsing
334
+ * behavior or shell completion.
335
+ *
336
+ * - `Usage`: Replaces the default usage tail.
337
+ * - `(defaultUsageLine) => Usage`: Computes the usage tail from the default.
338
+ *
339
+ * @since 1.0.0
340
+ */
341
+ readonly usageLine?: Usage | ((defaultUsageLine: Usage) => Usage);
329
342
  /**
330
343
  * Controls command visibility:
331
344
  *
@@ -1,5 +1,5 @@
1
1
  import { Message } from "./message.js";
2
- import { HiddenVisibility, OptionName } from "./usage.js";
2
+ import { HiddenVisibility, OptionName, Usage } from "./usage.js";
3
3
  import { ValueParser, ValueParserResult } from "./valueparser.js";
4
4
  import { DeferredParseState, PendingDependencySourceState } from "./dependency.js";
5
5
  import { Mode, Parser } from "./parser.js";
@@ -326,6 +326,19 @@ interface CommandOptions {
326
326
  * @since 0.6.0
327
327
  */
328
328
  readonly footer?: Message;
329
+ /**
330
+ * Usage line override for this command's own help page.
331
+ *
332
+ * This option customizes the usage tail shown when rendering help for this
333
+ * command itself (e.g., `myapp config --help`). It does not change parsing
334
+ * behavior or shell completion.
335
+ *
336
+ * - `Usage`: Replaces the default usage tail.
337
+ * - `(defaultUsageLine) => Usage`: Computes the usage tail from the default.
338
+ *
339
+ * @since 1.0.0
340
+ */
341
+ readonly usageLine?: Usage | ((defaultUsageLine: Usage) => Usage);
329
342
  /**
330
343
  * Controls command visibility:
331
344
  *
@@ -927,6 +927,7 @@ function command(name, parser, options = {}) {
927
927
  usage: [{
928
928
  type: "command",
929
929
  name,
930
+ ...options.usageLine != null && { usageLine: options.usageLine },
930
931
  ...options.hidden != null && { hidden: options.hidden }
931
932
  }, ...parser.usage],
932
933
  initialState: void 0,
package/dist/usage.cjs CHANGED
@@ -419,6 +419,12 @@ function* formatUsageTermInternal(term, options) {
419
419
  text: options?.colors ? `\x1b[2m${text}\x1b[0m` : text,
420
420
  width: 5
421
421
  };
422
+ } else if (term.type === "ellipsis") {
423
+ const text = "...";
424
+ yield {
425
+ text: options?.colors ? `\x1b[2m${text}\x1b[0m` : text,
426
+ width: 3
427
+ };
422
428
  } else throw new TypeError(`Unknown usage term type: ${term["type"]}.`);
423
429
  }
424
430
 
package/dist/usage.d.cts CHANGED
@@ -98,6 +98,12 @@ type UsageTerm =
98
98
  * in the command-line usage.
99
99
  */
100
100
  readonly name: string;
101
+ /**
102
+ * Optional usage line override for this command's own help page.
103
+ * This affects help/documentation rendering only.
104
+ * @since 1.0.0
105
+ */
106
+ readonly usageLine?: Usage | ((defaultUsageLine: Usage) => Usage);
101
107
  /**
102
108
  * Visibility controls for this term.
103
109
  * @since 0.9.0
@@ -181,6 +187,17 @@ type UsageTerm =
181
187
  * @since 0.9.0
182
188
  */
183
189
  readonly hidden?: HiddenVisibility;
190
+ }
191
+ /**
192
+ * An ellipsis term, which represents a summary placeholder in usage output.
193
+ * Unlike {@link passthrough}, this term has no parsing semantics and is used
194
+ * only for display.
195
+ * @since 1.0.0
196
+ */ | {
197
+ /**
198
+ * The type of the term, which is always `"ellipsis"` for this term.
199
+ */
200
+ readonly type: "ellipsis";
184
201
  };
185
202
  /**
186
203
  * Represents a command-line usage description, which is a sequence of
package/dist/usage.d.ts CHANGED
@@ -98,6 +98,12 @@ type UsageTerm =
98
98
  * in the command-line usage.
99
99
  */
100
100
  readonly name: string;
101
+ /**
102
+ * Optional usage line override for this command's own help page.
103
+ * This affects help/documentation rendering only.
104
+ * @since 1.0.0
105
+ */
106
+ readonly usageLine?: Usage | ((defaultUsageLine: Usage) => Usage);
101
107
  /**
102
108
  * Visibility controls for this term.
103
109
  * @since 0.9.0
@@ -181,6 +187,17 @@ type UsageTerm =
181
187
  * @since 0.9.0
182
188
  */
183
189
  readonly hidden?: HiddenVisibility;
190
+ }
191
+ /**
192
+ * An ellipsis term, which represents a summary placeholder in usage output.
193
+ * Unlike {@link passthrough}, this term has no parsing semantics and is used
194
+ * only for display.
195
+ * @since 1.0.0
196
+ */ | {
197
+ /**
198
+ * The type of the term, which is always `"ellipsis"` for this term.
199
+ */
200
+ readonly type: "ellipsis";
184
201
  };
185
202
  /**
186
203
  * Represents a command-line usage description, which is a sequence of
package/dist/usage.js CHANGED
@@ -418,6 +418,12 @@ function* formatUsageTermInternal(term, options) {
418
418
  text: options?.colors ? `\x1b[2m${text}\x1b[0m` : text,
419
419
  width: 5
420
420
  };
421
+ } else if (term.type === "ellipsis") {
422
+ const text = "...";
423
+ yield {
424
+ text: options?.colors ? `\x1b[2m${text}\x1b[0m` : text,
425
+ width: 3
426
+ };
421
427
  } else throw new TypeError(`Unknown usage term type: ${term["type"]}.`);
422
428
  }
423
429
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.489+709d13c5",
3
+ "version": "1.0.0-dev.490+fe0b9010",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",