@optique/core 1.0.0-dev.1500 → 1.0.0-dev.1510

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/message.cjs CHANGED
@@ -413,7 +413,7 @@ function formatMessage(msg, options = {}) {
413
413
  totalWidth = 0;
414
414
  continue;
415
415
  }
416
- if (options.maxWidth != null && totalWidth + width > options.maxWidth) {
416
+ if (options.maxWidth != null && totalWidth > 0 && totalWidth + width > options.maxWidth) {
417
417
  output += "\n";
418
418
  totalWidth = 0;
419
419
  }
package/dist/message.js CHANGED
@@ -412,7 +412,7 @@ function formatMessage(msg, options = {}) {
412
412
  totalWidth = 0;
413
413
  continue;
414
414
  }
415
- if (options.maxWidth != null && totalWidth + width > options.maxWidth) {
415
+ if (options.maxWidth != null && totalWidth > 0 && totalWidth + width > options.maxWidth) {
416
416
  output += "\n";
417
417
  totalWidth = 0;
418
418
  }
@@ -968,8 +968,11 @@ async function* suggestCommandAsync(context, prefix, name, parser, options) {
968
968
  * a description for documentation.
969
969
  * @returns A {@link Parser} that matches the command name and delegates
970
970
  * to the inner parser for the remaining arguments.
971
+ * @throws {TypeError} If `name` is empty, whitespace-only, contains
972
+ * embedded whitespace, or contains control characters.
971
973
  */
972
974
  function command(name, parser, options = {}) {
975
+ require_validate.validateCommandNames([name], "Command");
973
976
  const isAsync = parser.$mode === "async";
974
977
  const result = {
975
978
  [Symbol.for("@optique/core/commandParser")]: true,
@@ -396,6 +396,8 @@ type CommandState<TState> = undefined | ["matched", string] | ["parsing", TState
396
396
  * a description for documentation.
397
397
  * @returns A {@link Parser} that matches the command name and delegates
398
398
  * to the inner parser for the remaining arguments.
399
+ * @throws {TypeError} If `name` is empty, whitespace-only, contains
400
+ * embedded whitespace, or contains control characters.
399
401
  */
400
402
  declare function command<M extends Mode, T, TState>(name: string, parser: Parser<M, T, TState>, options?: CommandOptions): Parser<M, T, CommandState<TState>>;
401
403
  /**
@@ -396,6 +396,8 @@ type CommandState<TState> = undefined | ["matched", string] | ["parsing", TState
396
396
  * a description for documentation.
397
397
  * @returns A {@link Parser} that matches the command name and delegates
398
398
  * to the inner parser for the remaining arguments.
399
+ * @throws {TypeError} If `name` is empty, whitespace-only, contains
400
+ * embedded whitespace, or contains control characters.
399
401
  */
400
402
  declare function command<M extends Mode, T, TState>(name: string, parser: Parser<M, T, TState>, options?: CommandOptions): Parser<M, T, CommandState<TState>>;
401
403
  /**
@@ -2,7 +2,7 @@ import { annotateFreshArray, getAnnotations } from "./annotations.js";
2
2
  import { message, metavar, optionName, optionNames, text, valueSet } from "./message.js";
3
3
  import { createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, dependencyId, getDefaultValuesFunction, getDependencyIds, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, suggestWithDependency } from "./dependency.js";
4
4
  import { dispatchIterableByMode } from "./mode-dispatch.js";
5
- import { validateOptionNames } from "./validate.js";
5
+ import { validateCommandNames, validateOptionNames } from "./validate.js";
6
6
  import { extractOptionNames, isDocHidden, isSuggestionHidden } from "./usage.js";
7
7
  import { DEFAULT_FIND_SIMILAR_OPTIONS, createErrorWithSuggestions, createSuggestionMessage, findSimilar } from "./suggestion.js";
8
8
  import { extractLeadingCommandNames } from "./usage-internals.js";
@@ -968,8 +968,11 @@ async function* suggestCommandAsync(context, prefix, name, parser, options) {
968
968
  * a description for documentation.
969
969
  * @returns A {@link Parser} that matches the command name and delegates
970
970
  * to the inner parser for the remaining arguments.
971
+ * @throws {TypeError} If `name` is empty, whitespace-only, contains
972
+ * embedded whitespace, or contains control characters.
971
973
  */
972
974
  function command(name, parser, options = {}) {
975
+ validateCommandNames([name], "Command");
973
976
  const isAsync = parser.$mode === "async";
974
977
  const result = {
975
978
  [Symbol.for("@optique/core/commandParser")]: true,
package/dist/usage.cjs CHANGED
@@ -180,7 +180,7 @@ function formatUsage(programName, usage, options = {}) {
180
180
  output += " ";
181
181
  lineWidth += 1;
182
182
  }
183
- } else if (options.maxWidth != null && lineWidth + width > options.maxWidth) {
183
+ } else if (options.maxWidth != null && lineWidth > 0 && lineWidth + width > options.maxWidth) {
184
184
  if (output.endsWith(" ")) output = output.slice(0, -1);
185
185
  output += "\n";
186
186
  lineWidth = 0;
@@ -418,7 +418,7 @@ function formatUsageTerm(term, options = {}) {
418
418
  let lineWidth = 0;
419
419
  let output = "";
420
420
  for (const { text, width } of formatUsageTermInternal(visibleTerms[0], options)) {
421
- if (options.maxWidth != null && lineWidth + width > options.maxWidth) {
421
+ if (options.maxWidth != null && lineWidth > 0 && lineWidth + width > options.maxWidth) {
422
422
  if (output.endsWith(" ")) output = output.slice(0, -1);
423
423
  output += "\n";
424
424
  lineWidth = 0;
package/dist/usage.js CHANGED
@@ -180,7 +180,7 @@ function formatUsage(programName, usage, options = {}) {
180
180
  output += " ";
181
181
  lineWidth += 1;
182
182
  }
183
- } else if (options.maxWidth != null && lineWidth + width > options.maxWidth) {
183
+ } else if (options.maxWidth != null && lineWidth > 0 && lineWidth + width > options.maxWidth) {
184
184
  if (output.endsWith(" ")) output = output.slice(0, -1);
185
185
  output += "\n";
186
186
  lineWidth = 0;
@@ -418,7 +418,7 @@ function formatUsageTerm(term, options = {}) {
418
418
  let lineWidth = 0;
419
419
  let output = "";
420
420
  for (const { text, width } of formatUsageTermInternal(visibleTerms[0], options)) {
421
- if (options.maxWidth != null && lineWidth + width > options.maxWidth) {
421
+ if (options.maxWidth != null && lineWidth > 0 && lineWidth + width > options.maxWidth) {
422
422
  if (output.endsWith(" ")) output = output.slice(0, -1);
423
423
  output += "\n";
424
424
  lineWidth = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.1500+dc0650e5",
3
+ "version": "1.0.0-dev.1510+f054ad59",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",