@optique/core 1.0.0-dev.1553 → 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/facade.cjs CHANGED
@@ -563,6 +563,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
563
563
  args = argsOrOptions;
564
564
  options = optionsParam ?? {};
565
565
  }
566
+ require_validate.validateProgramName(programName);
566
567
  const { colors, maxWidth, showDefault, showChoices, sectionOrder, aboveError = "usage", onError = () => {
567
568
  throw new RunParserError("Failed to parse command line arguments.");
568
569
  }, stderr = console.error, stdout = console.log, brief, description, examples, author, bugs, footer } = options;
package/dist/facade.d.cts CHANGED
@@ -272,11 +272,13 @@ interface RunOptions<THelp, TError> {
272
272
  * @param options Configuration options for output formatting and callbacks.
273
273
  * @returns The parsed result value, or the return value of `onHelp`/`onError`
274
274
  * callbacks.
275
- * @throws {TypeError} If `options.version.value` is not a non-empty string
276
- * without ASCII control characters, or if any meta command/option
277
- * name is empty, whitespace-only, contains whitespace or control
278
- * characters, or (for option names) lacks a valid prefix (`--`,
279
- * `-`, `/`, or `+`).
275
+ * @throws {TypeError} If `programName` (or `program.metadata.name`) is not
276
+ * a string, is empty, is whitespace-only, or contains control
277
+ * characters. Also thrown if `options.version.value` is not a
278
+ * non-empty string without ASCII control characters, or if any
279
+ * meta command/option name is empty, whitespace-only, contains
280
+ * whitespace or control characters, or (for option names) lacks a
281
+ * valid prefix (`--`, `-`, `/`, or `+`).
280
282
  * @throws {RunParserError} When parsing fails and no `onError` callback is
281
283
  * provided.
282
284
  * @since 0.10.0 Added support for {@link Program} objects.
package/dist/facade.d.ts CHANGED
@@ -272,11 +272,13 @@ interface RunOptions<THelp, TError> {
272
272
  * @param options Configuration options for output formatting and callbacks.
273
273
  * @returns The parsed result value, or the return value of `onHelp`/`onError`
274
274
  * callbacks.
275
- * @throws {TypeError} If `options.version.value` is not a non-empty string
276
- * without ASCII control characters, or if any meta command/option
277
- * name is empty, whitespace-only, contains whitespace or control
278
- * characters, or (for option names) lacks a valid prefix (`--`,
279
- * `-`, `/`, or `+`).
275
+ * @throws {TypeError} If `programName` (or `program.metadata.name`) is not
276
+ * a string, is empty, is whitespace-only, or contains control
277
+ * characters. Also thrown if `options.version.value` is not a
278
+ * non-empty string without ASCII control characters, or if any
279
+ * meta command/option name is empty, whitespace-only, contains
280
+ * whitespace or control characters, or (for option names) lacks a
281
+ * valid prefix (`--`, `-`, `/`, or `+`).
280
282
  * @throws {RunParserError} When parsing fails and no `onError` callback is
281
283
  * provided.
282
284
  * @since 0.10.0 Added support for {@link Program} objects.
package/dist/facade.js CHANGED
@@ -2,7 +2,7 @@ import { injectAnnotations } from "./annotations.js";
2
2
  import { commandLine, formatMessage, lineBreak, message, optionName, text, value } from "./message.js";
3
3
  import { bash, fish, nu, pwsh, zsh } from "./completion.js";
4
4
  import { dispatchByMode } from "./mode-dispatch.js";
5
- import { validateCommandNames, validateMetaNameCollisions, validateOptionNames } from "./validate.js";
5
+ import { validateCommandNames, validateMetaNameCollisions, validateOptionNames, validateProgramName } from "./validate.js";
6
6
  import { extractCommandNames, extractLiteralValues, extractOptionNames, formatUsage } from "./usage.js";
7
7
  import { formatDocPage } from "./doc.js";
8
8
  import { group, longestMatch, object } from "./constructs.js";
@@ -563,6 +563,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
563
563
  args = argsOrOptions;
564
564
  options = optionsParam ?? {};
565
565
  }
566
+ validateProgramName(programName);
566
567
  const { colors, maxWidth, showDefault, showChoices, sectionOrder, aboveError = "usage", onError = () => {
567
568
  throw new RunParserError("Failed to parse command line arguments.");
568
569
  }, stderr = console.error, stdout = console.log, brief, description, examples, author, bugs, footer } = options;
package/dist/program.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ const require_validate = require('./validate.cjs');
1
2
 
2
3
  //#region src/program.ts
3
4
  /**
@@ -11,6 +12,8 @@
11
12
  * @template T - The type of value produced by the parser.
12
13
  * @param program - The program definition with parser and metadata.
13
14
  * @returns The same program object with inferred types.
15
+ * @throws {TypeError} If `program.metadata.name` is not a string, is empty,
16
+ * is whitespace-only, or contains control characters.
14
17
  *
15
18
  * @example
16
19
  * ```typescript
@@ -37,6 +40,7 @@
37
40
  * @since 1.0.0
38
41
  */
39
42
  function defineProgram(program) {
43
+ require_validate.validateProgramName(program.metadata.name);
40
44
  return program;
41
45
  }
42
46
 
@@ -94,6 +94,8 @@ interface Program<M extends Mode, T> {
94
94
  * @template T - The type of value produced by the parser.
95
95
  * @param program - The program definition with parser and metadata.
96
96
  * @returns The same program object with inferred types.
97
+ * @throws {TypeError} If `program.metadata.name` is not a string, is empty,
98
+ * is whitespace-only, or contains control characters.
97
99
  *
98
100
  * @example
99
101
  * ```typescript
package/dist/program.d.ts CHANGED
@@ -94,6 +94,8 @@ interface Program<M extends Mode, T> {
94
94
  * @template T - The type of value produced by the parser.
95
95
  * @param program - The program definition with parser and metadata.
96
96
  * @returns The same program object with inferred types.
97
+ * @throws {TypeError} If `program.metadata.name` is not a string, is empty,
98
+ * is whitespace-only, or contains control characters.
97
99
  *
98
100
  * @example
99
101
  * ```typescript
package/dist/program.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { validateProgramName } from "./validate.js";
2
+
1
3
  //#region src/program.ts
2
4
  /**
3
5
  * Defines a CLI program with a parser and metadata.
@@ -10,6 +12,8 @@
10
12
  * @template T - The type of value produced by the parser.
11
13
  * @param program - The program definition with parser and metadata.
12
14
  * @returns The same program object with inferred types.
15
+ * @throws {TypeError} If `program.metadata.name` is not a string, is empty,
16
+ * is whitespace-only, or contains control characters.
13
17
  *
14
18
  * @example
15
19
  * ```typescript
@@ -36,6 +40,7 @@
36
40
  * @since 1.0.0
37
41
  */
38
42
  function defineProgram(program) {
43
+ validateProgramName(program.metadata.name);
39
44
  return program;
40
45
  }
41
46
 
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.1553+1e439439",
3
+ "version": "1.0.0-dev.1561+241c020e",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",