@optique/core 0.4.0-dev.54 → 0.4.0-dev.56

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/doc.cjs CHANGED
@@ -73,11 +73,19 @@ function formatDocPage(programName, page, options = {}) {
73
73
  optionsSeparator: ", ",
74
74
  maxWidth: options.maxWidth == null ? void 0 : options.maxWidth - termIndent
75
75
  });
76
- output += `${" ".repeat(termIndent)}${ansiAwareRightPad(term, termWidth)} ${entry.description == null ? "" : indentLines(require_message.formatMessage(entry.description, {
76
+ let description = entry.description == null ? "" : require_message.formatMessage(entry.description, {
77
77
  colors: options.colors,
78
78
  quotes: !options.colors,
79
79
  maxWidth: options.maxWidth == null ? void 0 : options.maxWidth - termIndent - termWidth - 2
80
- }), termIndent + termWidth + 2)}\n`;
80
+ });
81
+ if (options.showDefault && entry.default != null) {
82
+ const prefix = typeof options.showDefault === "object" ? options.showDefault.prefix ?? " [" : " [";
83
+ const suffix = typeof options.showDefault === "object" ? options.showDefault.suffix ?? "]" : "]";
84
+ const defaultText = `${prefix}${entry.default}${suffix}`;
85
+ const formattedDefault = options.colors ? `\x1b[2m${defaultText}\x1b[0m` : defaultText;
86
+ description += formattedDefault;
87
+ }
88
+ output += `${" ".repeat(termIndent)}${ansiAwareRightPad(term, termWidth)} ${description === "" ? "" : indentLines(description, termIndent + termWidth + 2)}\n`;
81
89
  }
82
90
  }
83
91
  if (page.footer != null) {
package/dist/doc.d.cts CHANGED
@@ -69,6 +69,25 @@ interface DocFragments {
69
69
  */
70
70
  readonly fragments: readonly DocFragment[];
71
71
  }
72
+ /**
73
+ * Configuration for customizing default value display formatting.
74
+ *
75
+ * @since 0.4.0
76
+ */
77
+ interface ShowDefaultOptions {
78
+ /**
79
+ * Text to display before the default value.
80
+ *
81
+ * @default `" ["`
82
+ */
83
+ readonly prefix?: string;
84
+ /**
85
+ * Text to display after the default value.
86
+ *
87
+ * @default `"]"`
88
+ */
89
+ readonly suffix?: string;
90
+ }
72
91
  /**
73
92
  * Options for formatting a documentation page.
74
93
  */
@@ -92,6 +111,30 @@ interface DocPageFormatOptions {
92
111
  * Maximum width of the entire formatted output.
93
112
  */
94
113
  maxWidth?: number;
114
+ /**
115
+ * Whether and how to display default values for options and arguments.
116
+ *
117
+ * - `boolean`: When `true`, displays defaults using format `[value]`
118
+ * - `ShowDefaultOptions`: Custom formatting with configurable prefix and suffix
119
+ *
120
+ * Default values are automatically dimmed when `colors` is enabled.
121
+ *
122
+ * @default `false`
123
+ * @since 0.4.0
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * // Basic usage - shows "[3000]"
128
+ * { showDefault: true }
129
+ *
130
+ * // Custom format - shows "(default: 3000)"
131
+ * { showDefault: { prefix: " (default: ", suffix: ")" } }
132
+ *
133
+ * // Custom format - shows " - defaults to 3000"
134
+ * { showDefault: { prefix: " - defaults to ", suffix: "" } }
135
+ * ```
136
+ */
137
+ showDefault?: boolean | ShowDefaultOptions;
95
138
  }
96
139
  /**
97
140
  * Formats a documentation page into a human-readable string.
@@ -126,4 +169,4 @@ interface DocPageFormatOptions {
126
169
  */
127
170
  declare function formatDocPage(programName: string, page: DocPage, options?: DocPageFormatOptions): string;
128
171
  //#endregion
129
- export { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, formatDocPage };
172
+ export { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowDefaultOptions, formatDocPage };
package/dist/doc.d.ts CHANGED
@@ -69,6 +69,25 @@ interface DocFragments {
69
69
  */
70
70
  readonly fragments: readonly DocFragment[];
71
71
  }
72
+ /**
73
+ * Configuration for customizing default value display formatting.
74
+ *
75
+ * @since 0.4.0
76
+ */
77
+ interface ShowDefaultOptions {
78
+ /**
79
+ * Text to display before the default value.
80
+ *
81
+ * @default `" ["`
82
+ */
83
+ readonly prefix?: string;
84
+ /**
85
+ * Text to display after the default value.
86
+ *
87
+ * @default `"]"`
88
+ */
89
+ readonly suffix?: string;
90
+ }
72
91
  /**
73
92
  * Options for formatting a documentation page.
74
93
  */
@@ -92,6 +111,30 @@ interface DocPageFormatOptions {
92
111
  * Maximum width of the entire formatted output.
93
112
  */
94
113
  maxWidth?: number;
114
+ /**
115
+ * Whether and how to display default values for options and arguments.
116
+ *
117
+ * - `boolean`: When `true`, displays defaults using format `[value]`
118
+ * - `ShowDefaultOptions`: Custom formatting with configurable prefix and suffix
119
+ *
120
+ * Default values are automatically dimmed when `colors` is enabled.
121
+ *
122
+ * @default `false`
123
+ * @since 0.4.0
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * // Basic usage - shows "[3000]"
128
+ * { showDefault: true }
129
+ *
130
+ * // Custom format - shows "(default: 3000)"
131
+ * { showDefault: { prefix: " (default: ", suffix: ")" } }
132
+ *
133
+ * // Custom format - shows " - defaults to 3000"
134
+ * { showDefault: { prefix: " - defaults to ", suffix: "" } }
135
+ * ```
136
+ */
137
+ showDefault?: boolean | ShowDefaultOptions;
95
138
  }
96
139
  /**
97
140
  * Formats a documentation page into a human-readable string.
@@ -126,4 +169,4 @@ interface DocPageFormatOptions {
126
169
  */
127
170
  declare function formatDocPage(programName: string, page: DocPage, options?: DocPageFormatOptions): string;
128
171
  //#endregion
129
- export { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, formatDocPage };
172
+ export { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowDefaultOptions, formatDocPage };
package/dist/doc.js CHANGED
@@ -73,11 +73,19 @@ function formatDocPage(programName, page, options = {}) {
73
73
  optionsSeparator: ", ",
74
74
  maxWidth: options.maxWidth == null ? void 0 : options.maxWidth - termIndent
75
75
  });
76
- output += `${" ".repeat(termIndent)}${ansiAwareRightPad(term, termWidth)} ${entry.description == null ? "" : indentLines(formatMessage(entry.description, {
76
+ let description = entry.description == null ? "" : formatMessage(entry.description, {
77
77
  colors: options.colors,
78
78
  quotes: !options.colors,
79
79
  maxWidth: options.maxWidth == null ? void 0 : options.maxWidth - termIndent - termWidth - 2
80
- }), termIndent + termWidth + 2)}\n`;
80
+ });
81
+ if (options.showDefault && entry.default != null) {
82
+ const prefix = typeof options.showDefault === "object" ? options.showDefault.prefix ?? " [" : " [";
83
+ const suffix = typeof options.showDefault === "object" ? options.showDefault.suffix ?? "]" : "]";
84
+ const defaultText = `${prefix}${entry.default}${suffix}`;
85
+ const formattedDefault = options.colors ? `\x1b[2m${defaultText}\x1b[0m` : defaultText;
86
+ description += formattedDefault;
87
+ }
88
+ output += `${" ".repeat(termIndent)}${ansiAwareRightPad(term, termWidth)} ${description === "" ? "" : indentLines(description, termIndent + termWidth + 2)}\n`;
81
89
  }
82
90
  }
83
91
  if (page.footer != null) {
package/dist/facade.cjs CHANGED
@@ -287,7 +287,7 @@ function run(parser, programName, args, options = {}) {
287
287
  const versionMode = options.version?.mode ?? "option";
288
288
  const versionValue = options.version?.value ?? "";
289
289
  const onVersion = options.version?.onShow ?? (() => ({}));
290
- let { colors, maxWidth, aboveError = "usage", onError = () => {
290
+ let { colors, maxWidth, showDefault, aboveError = "usage", onError = () => {
291
291
  throw new RunError("Failed to parse command line arguments.");
292
292
  }, stderr = console.error, stdout = console.log } = options;
293
293
  const help = options.help ? helpMode : "none";
@@ -336,7 +336,8 @@ function run(parser, programName, args, options = {}) {
336
336
  const doc = require_parser.getDocPage(helpGeneratorParser, classified.commands);
337
337
  if (doc != null) stdout(require_doc.formatDocPage(programName, doc, {
338
338
  colors,
339
- maxWidth
339
+ maxWidth,
340
+ showDefault
340
341
  }));
341
342
  try {
342
343
  return onHelp(0);
@@ -351,7 +352,8 @@ function run(parser, programName, args, options = {}) {
351
352
  if (doc == null) aboveError = "usage";
352
353
  else stderr(require_doc.formatDocPage(programName, doc, {
353
354
  colors,
354
- maxWidth
355
+ maxWidth,
356
+ showDefault
355
357
  }));
356
358
  }
357
359
  if (aboveError === "usage") stderr(`Usage: ${indentLines(require_usage.formatUsage(programName, augmentedParser.usage, {
package/dist/facade.d.cts CHANGED
@@ -1,3 +1,4 @@
1
+ import { ShowDefaultOptions } from "./doc.cjs";
1
2
  import { InferValue, Parser } from "./parser.cjs";
2
3
 
3
4
  //#region src/facade.d.ts
@@ -20,6 +21,18 @@ interface RunOptions<THelp, TError> {
20
21
  * this width. If not specified, text will not be wrapped.
21
22
  */
22
23
  readonly maxWidth?: number;
24
+ /**
25
+ * Whether and how to display default values for options and arguments.
26
+ *
27
+ * - `boolean`: When `true`, displays defaults using format `[value]`
28
+ * - `ShowDefaultOptions`: Custom formatting with configurable prefix and suffix
29
+ *
30
+ * Default values are automatically dimmed when `colors` is enabled.
31
+ *
32
+ * @default `false`
33
+ * @since 0.4.0
34
+ */
35
+ readonly showDefault?: boolean | ShowDefaultOptions;
23
36
  /**
24
37
  * Help configuration. When provided, enables help functionality.
25
38
  */
package/dist/facade.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { ShowDefaultOptions } from "./doc.js";
1
2
  import { InferValue, Parser } from "./parser.js";
2
3
 
3
4
  //#region src/facade.d.ts
@@ -20,6 +21,18 @@ interface RunOptions<THelp, TError> {
20
21
  * this width. If not specified, text will not be wrapped.
21
22
  */
22
23
  readonly maxWidth?: number;
24
+ /**
25
+ * Whether and how to display default values for options and arguments.
26
+ *
27
+ * - `boolean`: When `true`, displays defaults using format `[value]`
28
+ * - `ShowDefaultOptions`: Custom formatting with configurable prefix and suffix
29
+ *
30
+ * Default values are automatically dimmed when `colors` is enabled.
31
+ *
32
+ * @default `false`
33
+ * @since 0.4.0
34
+ */
35
+ readonly showDefault?: boolean | ShowDefaultOptions;
23
36
  /**
24
37
  * Help configuration. When provided, enables help functionality.
25
38
  */
package/dist/facade.js CHANGED
@@ -287,7 +287,7 @@ function run(parser, programName, args, options = {}) {
287
287
  const versionMode = options.version?.mode ?? "option";
288
288
  const versionValue = options.version?.value ?? "";
289
289
  const onVersion = options.version?.onShow ?? (() => ({}));
290
- let { colors, maxWidth, aboveError = "usage", onError = () => {
290
+ let { colors, maxWidth, showDefault, aboveError = "usage", onError = () => {
291
291
  throw new RunError("Failed to parse command line arguments.");
292
292
  }, stderr = console.error, stdout = console.log } = options;
293
293
  const help = options.help ? helpMode : "none";
@@ -336,7 +336,8 @@ function run(parser, programName, args, options = {}) {
336
336
  const doc = getDocPage(helpGeneratorParser, classified.commands);
337
337
  if (doc != null) stdout(formatDocPage(programName, doc, {
338
338
  colors,
339
- maxWidth
339
+ maxWidth,
340
+ showDefault
340
341
  }));
341
342
  try {
342
343
  return onHelp(0);
@@ -351,7 +352,8 @@ function run(parser, programName, args, options = {}) {
351
352
  if (doc == null) aboveError = "usage";
352
353
  else stderr(formatDocPage(programName, doc, {
353
354
  colors,
354
- maxWidth
355
+ maxWidth,
356
+ showDefault
355
357
  }));
356
358
  }
357
359
  if (aboveError === "usage") stderr(`Usage: ${indentLines(formatUsage(programName, augmentedParser.usage, {
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Message, MessageFormatOptions, MessageTerm, formatMessage, message, metavar, optionName, optionNames, text, value, values } from "./message.cjs";
2
2
  import { OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, formatUsage, formatUsageTerm, normalizeUsage } from "./usage.cjs";
3
- import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, formatDocPage } from "./doc.cjs";
3
+ import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowDefaultOptions, formatDocPage } from "./doc.cjs";
4
4
  import { ChoiceOptions, FloatOptions, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, choice, float, integer, isValueParser, locale, string, url, uuid } from "./valueparser.cjs";
5
5
  import { ArgumentOptions, CommandOptions, DocState, FlagOptions, InferValue, MultipleOptions, OptionOptions, Parser, ParserContext, ParserResult, Result, argument, command, concat, constant, flag, getDocPage, group, longestMatch, map, merge, multiple, object, option, optional, or, parse, tuple, withDefault } from "./parser.cjs";
6
6
  import { RunError, RunOptions, run } from "./facade.cjs";
7
- export { ArgumentOptions, ChoiceOptions, CommandOptions, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, FlagOptions, FloatOptions, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, Message, MessageFormatOptions, MessageTerm, MultipleOptions, OptionName, OptionOptions, Parser, ParserContext, ParserResult, Result, RunError, RunOptions, StringOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, argument, choice, command, concat, constant, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, group, integer, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, object, option, optionName, optionNames, optional, or, parse, run, string, text, tuple, url, uuid, value, values, withDefault };
7
+ export { ArgumentOptions, ChoiceOptions, CommandOptions, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, FlagOptions, FloatOptions, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, Message, MessageFormatOptions, MessageTerm, MultipleOptions, OptionName, OptionOptions, Parser, ParserContext, ParserResult, Result, RunError, RunOptions, ShowDefaultOptions, StringOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, argument, choice, command, concat, constant, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, group, integer, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, object, option, optionName, optionNames, optional, or, parse, run, string, text, tuple, url, uuid, value, values, withDefault };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Message, MessageFormatOptions, MessageTerm, formatMessage, message, metavar, optionName, optionNames, text, value, values } from "./message.js";
2
2
  import { OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, formatUsage, formatUsageTerm, normalizeUsage } from "./usage.js";
3
- import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, formatDocPage } from "./doc.js";
3
+ import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowDefaultOptions, formatDocPage } from "./doc.js";
4
4
  import { ChoiceOptions, FloatOptions, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, choice, float, integer, isValueParser, locale, string, url, uuid } from "./valueparser.js";
5
5
  import { ArgumentOptions, CommandOptions, DocState, FlagOptions, InferValue, MultipleOptions, OptionOptions, Parser, ParserContext, ParserResult, Result, argument, command, concat, constant, flag, getDocPage, group, longestMatch, map, merge, multiple, object, option, optional, or, parse, tuple, withDefault } from "./parser.js";
6
6
  import { RunError, RunOptions, run } from "./facade.js";
7
- export { ArgumentOptions, ChoiceOptions, CommandOptions, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, FlagOptions, FloatOptions, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, Message, MessageFormatOptions, MessageTerm, MultipleOptions, OptionName, OptionOptions, Parser, ParserContext, ParserResult, Result, RunError, RunOptions, StringOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, argument, choice, command, concat, constant, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, group, integer, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, object, option, optionName, optionNames, optional, or, parse, run, string, text, tuple, url, uuid, value, values, withDefault };
7
+ export { ArgumentOptions, ChoiceOptions, CommandOptions, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, FlagOptions, FloatOptions, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, Message, MessageFormatOptions, MessageTerm, MultipleOptions, OptionName, OptionOptions, Parser, ParserContext, ParserResult, Result, RunError, RunOptions, ShowDefaultOptions, StringOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, argument, choice, command, concat, constant, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, group, integer, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, object, option, optionName, optionNames, optional, or, parse, run, string, text, tuple, url, uuid, value, values, withDefault };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "0.4.0-dev.54+e30f3e5c",
3
+ "version": "0.4.0-dev.56+2ae81fd7",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",