@optique/core 1.0.0-dev.1502 → 1.0.0-dev.1514

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
@@ -1173,15 +1173,15 @@ function disposeContextsSync(contexts) {
1173
1173
  */
1174
1174
  async function runWith(parser, programName, contexts, options) {
1175
1175
  const args = options?.args ?? [];
1176
- if (needsEarlyExit(args, options)) {
1177
- if (parser.$mode === "async") return runParser(parser, programName, args, options);
1178
- return Promise.resolve(runParser(parser, programName, args, options));
1179
- }
1180
1176
  if (contexts.length === 0) {
1181
1177
  if (parser.$mode === "async") return runParser(parser, programName, args, options);
1182
1178
  return Promise.resolve(runParser(parser, programName, args, options));
1183
1179
  }
1184
1180
  try {
1181
+ if (needsEarlyExit(args, options)) {
1182
+ if (parser.$mode === "async") return runParser(parser, programName, args, options);
1183
+ return Promise.resolve(runParser(parser, programName, args, options));
1184
+ }
1185
1185
  const ctxOptions = options?.contextOptions;
1186
1186
  const { annotations: phase1Annotations, annotationsList: phase1AnnotationsList, hasDynamic: needsTwoPhase } = await collectPhase1Annotations(contexts, ctxOptions);
1187
1187
  if (!needsTwoPhase) {
@@ -1245,9 +1245,9 @@ async function runWith(parser, programName, contexts, options) {
1245
1245
  function runWithSync(parser, programName, contexts, options) {
1246
1246
  if (parser.$mode !== "sync") throw new TypeError("Cannot use an async parser with runWithSync(). Use runWith() or runWithAsync() instead.");
1247
1247
  const args = options?.args ?? [];
1248
- if (needsEarlyExit(args, options)) return runParser(parser, programName, args, options);
1249
1248
  if (contexts.length === 0) return runParser(parser, programName, args, options);
1250
1249
  try {
1250
+ if (needsEarlyExit(args, options)) return runParser(parser, programName, args, options);
1251
1251
  const ctxOptions = options?.contextOptions;
1252
1252
  const { annotations: phase1Annotations, annotationsList: phase1AnnotationsList, hasDynamic: needsTwoPhase } = collectPhase1AnnotationsSync(contexts, ctxOptions);
1253
1253
  if (!needsTwoPhase) {
package/dist/facade.js CHANGED
@@ -1173,15 +1173,15 @@ function disposeContextsSync(contexts) {
1173
1173
  */
1174
1174
  async function runWith(parser, programName, contexts, options) {
1175
1175
  const args = options?.args ?? [];
1176
- if (needsEarlyExit(args, options)) {
1177
- if (parser.$mode === "async") return runParser(parser, programName, args, options);
1178
- return Promise.resolve(runParser(parser, programName, args, options));
1179
- }
1180
1176
  if (contexts.length === 0) {
1181
1177
  if (parser.$mode === "async") return runParser(parser, programName, args, options);
1182
1178
  return Promise.resolve(runParser(parser, programName, args, options));
1183
1179
  }
1184
1180
  try {
1181
+ if (needsEarlyExit(args, options)) {
1182
+ if (parser.$mode === "async") return runParser(parser, programName, args, options);
1183
+ return Promise.resolve(runParser(parser, programName, args, options));
1184
+ }
1185
1185
  const ctxOptions = options?.contextOptions;
1186
1186
  const { annotations: phase1Annotations, annotationsList: phase1AnnotationsList, hasDynamic: needsTwoPhase } = await collectPhase1Annotations(contexts, ctxOptions);
1187
1187
  if (!needsTwoPhase) {
@@ -1245,9 +1245,9 @@ async function runWith(parser, programName, contexts, options) {
1245
1245
  function runWithSync(parser, programName, contexts, options) {
1246
1246
  if (parser.$mode !== "sync") throw new TypeError("Cannot use an async parser with runWithSync(). Use runWith() or runWithAsync() instead.");
1247
1247
  const args = options?.args ?? [];
1248
- if (needsEarlyExit(args, options)) return runParser(parser, programName, args, options);
1249
1248
  if (contexts.length === 0) return runParser(parser, programName, args, options);
1250
1249
  try {
1250
+ if (needsEarlyExit(args, options)) return runParser(parser, programName, args, options);
1251
1251
  const ctxOptions = options?.contextOptions;
1252
1252
  const { annotations: phase1Annotations, annotationsList: phase1AnnotationsList, hasDynamic: needsTwoPhase } = collectPhase1AnnotationsSync(contexts, ctxOptions);
1253
1253
  if (!needsTwoPhase) {
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.1502+fda779c7",
3
+ "version": "1.0.0-dev.1514+78606b85",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",