@optique/core 0.10.0-dev.313 → 0.10.0-dev.323

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/index.cjs CHANGED
@@ -70,6 +70,7 @@ exports.merge = require_constructs.merge;
70
70
  exports.message = require_message.message;
71
71
  exports.metavar = require_message.metavar;
72
72
  exports.multiple = require_modifiers.multiple;
73
+ exports.nonEmpty = require_modifiers.nonEmpty;
73
74
  exports.normalizeUsage = require_usage.normalizeUsage;
74
75
  exports.nu = require_completion.nu;
75
76
  exports.object = require_constructs.object;
package/dist/index.d.cts CHANGED
@@ -4,10 +4,10 @@ import { OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOption
4
4
  import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowDefaultOptions, formatDocPage } from "./doc.cjs";
5
5
  import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, FloatOptions, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, choice, float, integer, isValueParser, locale, string, url, uuid } from "./valueparser.cjs";
6
6
  import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.cjs";
7
- import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, optional, withDefault } from "./modifiers.cjs";
7
+ import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.cjs";
8
8
  import { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, PendingDependencySourceState, ResolvedDependency, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource, parseWithDependency, pendingDependencySourceStateMarker, suggestWithDependency, transformsDependencyValue, transformsDependencyValueMarker, wrappedDependencySourceMarker } from "./dependency.cjs";
9
9
  import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, flag, option, passThrough } from "./primitives.cjs";
10
10
  import { CombineModes, DocState, InferMode, InferValue, Mode, ModeIterable, ModeValue, Parser, ParserContext, ParserResult, Result, Suggestion, getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.cjs";
11
11
  import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.cjs";
12
12
  import { RunOptions, RunParserError, runParser, runParserAsync, runParserSync } from "./facade.cjs";
13
- export { AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, ResolvedDependency, Result, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, pwsh, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
13
+ export { AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, ResolvedDependency, Result, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, locale, longestMatch, map, merge, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, pwsh, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
package/dist/index.d.ts CHANGED
@@ -4,10 +4,10 @@ import { OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOption
4
4
  import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowDefaultOptions, formatDocPage } from "./doc.js";
5
5
  import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, FloatOptions, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, choice, float, integer, isValueParser, locale, string, url, uuid } from "./valueparser.js";
6
6
  import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
7
- import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, optional, withDefault } from "./modifiers.js";
7
+ import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
8
8
  import { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, PendingDependencySourceState, ResolvedDependency, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource, parseWithDependency, pendingDependencySourceStateMarker, suggestWithDependency, transformsDependencyValue, transformsDependencyValueMarker, wrappedDependencySourceMarker } from "./dependency.js";
9
9
  import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, flag, option, passThrough } from "./primitives.js";
10
10
  import { CombineModes, DocState, InferMode, InferValue, Mode, ModeIterable, ModeValue, Parser, ParserContext, ParserResult, Result, Suggestion, getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.js";
11
11
  import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.js";
12
12
  import { RunOptions, RunParserError, runParser, runParserAsync, runParserSync } from "./facade.js";
13
- export { AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, ResolvedDependency, Result, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, pwsh, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
13
+ export { AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, ResolvedDependency, Result, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, locale, longestMatch, map, merge, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, pwsh, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
package/dist/index.js CHANGED
@@ -4,11 +4,11 @@ import { DependencyRegistry, createDeferredParseState, createDependencySourceSta
4
4
  import { extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, normalizeUsage } from "./usage.js";
5
5
  import { DuplicateOptionError, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
6
6
  import { formatDocPage } from "./doc.js";
7
- import { WithDefaultError, map, multiple, optional, withDefault } from "./modifiers.js";
7
+ import { WithDefaultError, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
8
8
  import { ensureNonEmptyString, isNonEmptyString } from "./nonempty.js";
9
9
  import { choice, float, integer, isValueParser, locale, string, url, uuid } from "./valueparser.js";
10
10
  import { argument, command, constant, flag, option, passThrough } from "./primitives.js";
11
11
  import { getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.js";
12
12
  import { RunParserError, runParser, runParserAsync, runParserSync } from "./facade.js";
13
13
 
14
- export { DependencyRegistry, DuplicateOptionError, RunParserError, WithDefaultError, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, pwsh, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
14
+ export { DependencyRegistry, DuplicateOptionError, RunParserError, WithDefaultError, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, locale, longestMatch, map, merge, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, pwsh, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
@@ -578,10 +578,90 @@ function multiple(parser, options = {}) {
578
578
  }
579
579
  return resultParser;
580
580
  }
581
+ /**
582
+ * Creates a parser that requires the wrapped parser to consume at least one
583
+ * input token to succeed. If the wrapped parser succeeds without consuming
584
+ * any tokens, this parser fails with an error.
585
+ *
586
+ * This modifier is useful with `longestMatch()` for implementing conditional
587
+ * default values. When used together, `nonEmpty()` prevents a parser with
588
+ * only default values from matching when no input is provided, allowing
589
+ * another branch (like a help command) to match instead.
590
+ *
591
+ * @template M The execution mode of the parser.
592
+ * @template T The type of value produced by the wrapped parser.
593
+ * @template TState The type of state used by the wrapped parser.
594
+ * @param parser The {@link Parser} that must consume input to succeed.
595
+ * @returns A {@link Parser} that fails if the wrapped parser consumes no input.
596
+ *
597
+ * @example
598
+ * ```typescript
599
+ * // Without nonEmpty(): activeParser always wins (consumes 0 tokens)
600
+ * // With nonEmpty(): helpParser wins when no options are provided
601
+ * const activeParser = nonEmpty(object({
602
+ * cwd: withDefault(option("--cwd", string()), "./default"),
603
+ * key: optional(option("--key", string())),
604
+ * }));
605
+ *
606
+ * const helpParser = object({
607
+ * mode: constant("help"),
608
+ * });
609
+ *
610
+ * const parser = longestMatch(activeParser, helpParser);
611
+ *
612
+ * // cli → helpParser matches (activeParser fails with nonEmpty)
613
+ * // cli --key foo → activeParser matches (consumes tokens)
614
+ * ```
615
+ *
616
+ * @since 0.10.0
617
+ */
618
+ function nonEmpty(parser) {
619
+ const syncParser = parser;
620
+ const isAsync = parser.$mode === "async";
621
+ const processNonEmptyResult = (result) => {
622
+ if (!result.success) return result;
623
+ if (result.consumed.length === 0) return {
624
+ success: false,
625
+ consumed: 0,
626
+ error: require_message.message`Parser must consume at least one token.`
627
+ };
628
+ return result;
629
+ };
630
+ const parseSync = (context) => {
631
+ const result = syncParser.parse(context);
632
+ return processNonEmptyResult(result);
633
+ };
634
+ const parseAsync = async (context) => {
635
+ const result = await parser.parse(context);
636
+ return processNonEmptyResult(result);
637
+ };
638
+ return {
639
+ $mode: parser.$mode,
640
+ $valueType: parser.$valueType,
641
+ $stateType: parser.$stateType,
642
+ priority: parser.priority,
643
+ usage: parser.usage,
644
+ initialState: parser.initialState,
645
+ parse(context) {
646
+ if (isAsync) return parseAsync(context);
647
+ return parseSync(context);
648
+ },
649
+ complete(state) {
650
+ return parser.complete(state);
651
+ },
652
+ suggest(context, prefix) {
653
+ return parser.suggest(context, prefix);
654
+ },
655
+ getDocFragments(state, defaultValue) {
656
+ return syncParser.getDocFragments(state, defaultValue);
657
+ }
658
+ };
659
+ }
581
660
 
582
661
  //#endregion
583
662
  exports.WithDefaultError = WithDefaultError;
584
663
  exports.map = map;
585
664
  exports.multiple = multiple;
665
+ exports.nonEmpty = nonEmpty;
586
666
  exports.optional = optional;
587
667
  exports.withDefault = withDefault;
@@ -193,5 +193,43 @@ interface MultipleErrorOptions {
193
193
  * of type {@link TState}.
194
194
  */
195
195
  declare function multiple<M extends Mode, TValue, TState>(parser: Parser<M, TValue, TState>, options?: MultipleOptions): Parser<M, readonly TValue[], readonly TState[]>;
196
+ /**
197
+ * Creates a parser that requires the wrapped parser to consume at least one
198
+ * input token to succeed. If the wrapped parser succeeds without consuming
199
+ * any tokens, this parser fails with an error.
200
+ *
201
+ * This modifier is useful with `longestMatch()` for implementing conditional
202
+ * default values. When used together, `nonEmpty()` prevents a parser with
203
+ * only default values from matching when no input is provided, allowing
204
+ * another branch (like a help command) to match instead.
205
+ *
206
+ * @template M The execution mode of the parser.
207
+ * @template T The type of value produced by the wrapped parser.
208
+ * @template TState The type of state used by the wrapped parser.
209
+ * @param parser The {@link Parser} that must consume input to succeed.
210
+ * @returns A {@link Parser} that fails if the wrapped parser consumes no input.
211
+ *
212
+ * @example
213
+ * ```typescript
214
+ * // Without nonEmpty(): activeParser always wins (consumes 0 tokens)
215
+ * // With nonEmpty(): helpParser wins when no options are provided
216
+ * const activeParser = nonEmpty(object({
217
+ * cwd: withDefault(option("--cwd", string()), "./default"),
218
+ * key: optional(option("--key", string())),
219
+ * }));
220
+ *
221
+ * const helpParser = object({
222
+ * mode: constant("help"),
223
+ * });
224
+ *
225
+ * const parser = longestMatch(activeParser, helpParser);
226
+ *
227
+ * // cli → helpParser matches (activeParser fails with nonEmpty)
228
+ * // cli --key foo → activeParser matches (consumes tokens)
229
+ * ```
230
+ *
231
+ * @since 0.10.0
232
+ */
233
+ declare function nonEmpty<M extends Mode, T, TState>(parser: Parser<M, T, TState>): Parser<M, T, TState>;
196
234
  //#endregion
197
- export { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, optional, withDefault };
235
+ export { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, nonEmpty, optional, withDefault };
@@ -193,5 +193,43 @@ interface MultipleErrorOptions {
193
193
  * of type {@link TState}.
194
194
  */
195
195
  declare function multiple<M extends Mode, TValue, TState>(parser: Parser<M, TValue, TState>, options?: MultipleOptions): Parser<M, readonly TValue[], readonly TState[]>;
196
+ /**
197
+ * Creates a parser that requires the wrapped parser to consume at least one
198
+ * input token to succeed. If the wrapped parser succeeds without consuming
199
+ * any tokens, this parser fails with an error.
200
+ *
201
+ * This modifier is useful with `longestMatch()` for implementing conditional
202
+ * default values. When used together, `nonEmpty()` prevents a parser with
203
+ * only default values from matching when no input is provided, allowing
204
+ * another branch (like a help command) to match instead.
205
+ *
206
+ * @template M The execution mode of the parser.
207
+ * @template T The type of value produced by the wrapped parser.
208
+ * @template TState The type of state used by the wrapped parser.
209
+ * @param parser The {@link Parser} that must consume input to succeed.
210
+ * @returns A {@link Parser} that fails if the wrapped parser consumes no input.
211
+ *
212
+ * @example
213
+ * ```typescript
214
+ * // Without nonEmpty(): activeParser always wins (consumes 0 tokens)
215
+ * // With nonEmpty(): helpParser wins when no options are provided
216
+ * const activeParser = nonEmpty(object({
217
+ * cwd: withDefault(option("--cwd", string()), "./default"),
218
+ * key: optional(option("--key", string())),
219
+ * }));
220
+ *
221
+ * const helpParser = object({
222
+ * mode: constant("help"),
223
+ * });
224
+ *
225
+ * const parser = longestMatch(activeParser, helpParser);
226
+ *
227
+ * // cli → helpParser matches (activeParser fails with nonEmpty)
228
+ * // cli --key foo → activeParser matches (consumes tokens)
229
+ * ```
230
+ *
231
+ * @since 0.10.0
232
+ */
233
+ declare function nonEmpty<M extends Mode, T, TState>(parser: Parser<M, T, TState>): Parser<M, T, TState>;
196
234
  //#endregion
197
- export { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, optional, withDefault };
235
+ export { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, nonEmpty, optional, withDefault };
package/dist/modifiers.js CHANGED
@@ -578,6 +578,85 @@ function multiple(parser, options = {}) {
578
578
  }
579
579
  return resultParser;
580
580
  }
581
+ /**
582
+ * Creates a parser that requires the wrapped parser to consume at least one
583
+ * input token to succeed. If the wrapped parser succeeds without consuming
584
+ * any tokens, this parser fails with an error.
585
+ *
586
+ * This modifier is useful with `longestMatch()` for implementing conditional
587
+ * default values. When used together, `nonEmpty()` prevents a parser with
588
+ * only default values from matching when no input is provided, allowing
589
+ * another branch (like a help command) to match instead.
590
+ *
591
+ * @template M The execution mode of the parser.
592
+ * @template T The type of value produced by the wrapped parser.
593
+ * @template TState The type of state used by the wrapped parser.
594
+ * @param parser The {@link Parser} that must consume input to succeed.
595
+ * @returns A {@link Parser} that fails if the wrapped parser consumes no input.
596
+ *
597
+ * @example
598
+ * ```typescript
599
+ * // Without nonEmpty(): activeParser always wins (consumes 0 tokens)
600
+ * // With nonEmpty(): helpParser wins when no options are provided
601
+ * const activeParser = nonEmpty(object({
602
+ * cwd: withDefault(option("--cwd", string()), "./default"),
603
+ * key: optional(option("--key", string())),
604
+ * }));
605
+ *
606
+ * const helpParser = object({
607
+ * mode: constant("help"),
608
+ * });
609
+ *
610
+ * const parser = longestMatch(activeParser, helpParser);
611
+ *
612
+ * // cli → helpParser matches (activeParser fails with nonEmpty)
613
+ * // cli --key foo → activeParser matches (consumes tokens)
614
+ * ```
615
+ *
616
+ * @since 0.10.0
617
+ */
618
+ function nonEmpty(parser) {
619
+ const syncParser = parser;
620
+ const isAsync = parser.$mode === "async";
621
+ const processNonEmptyResult = (result) => {
622
+ if (!result.success) return result;
623
+ if (result.consumed.length === 0) return {
624
+ success: false,
625
+ consumed: 0,
626
+ error: message`Parser must consume at least one token.`
627
+ };
628
+ return result;
629
+ };
630
+ const parseSync = (context) => {
631
+ const result = syncParser.parse(context);
632
+ return processNonEmptyResult(result);
633
+ };
634
+ const parseAsync = async (context) => {
635
+ const result = await parser.parse(context);
636
+ return processNonEmptyResult(result);
637
+ };
638
+ return {
639
+ $mode: parser.$mode,
640
+ $valueType: parser.$valueType,
641
+ $stateType: parser.$stateType,
642
+ priority: parser.priority,
643
+ usage: parser.usage,
644
+ initialState: parser.initialState,
645
+ parse(context) {
646
+ if (isAsync) return parseAsync(context);
647
+ return parseSync(context);
648
+ },
649
+ complete(state) {
650
+ return parser.complete(state);
651
+ },
652
+ suggest(context, prefix) {
653
+ return parser.suggest(context, prefix);
654
+ },
655
+ getDocFragments(state, defaultValue) {
656
+ return syncParser.getDocFragments(state, defaultValue);
657
+ }
658
+ };
659
+ }
581
660
 
582
661
  //#endregion
583
- export { WithDefaultError, map, multiple, optional, withDefault };
662
+ export { WithDefaultError, map, multiple, nonEmpty, optional, withDefault };
package/dist/parser.cjs CHANGED
@@ -387,6 +387,7 @@ exports.longestMatch = require_constructs.longestMatch;
387
387
  exports.map = require_modifiers.map;
388
388
  exports.merge = require_constructs.merge;
389
389
  exports.multiple = require_modifiers.multiple;
390
+ exports.nonEmpty = require_modifiers.nonEmpty;
390
391
  exports.object = require_constructs.object;
391
392
  exports.option = require_primitives.option;
392
393
  exports.optional = require_modifiers.optional;
package/dist/parser.d.cts CHANGED
@@ -3,7 +3,7 @@ import { Usage } from "./usage.cjs";
3
3
  import { DocFragments, DocPage } from "./doc.cjs";
4
4
  import { ValueParserResult } from "./valueparser.cjs";
5
5
  import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.cjs";
6
- import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, optional, withDefault } from "./modifiers.cjs";
6
+ import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.cjs";
7
7
  import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, flag, option, passThrough } from "./primitives.cjs";
8
8
 
9
9
  //#region src/parser.d.ts
@@ -516,4 +516,4 @@ declare function getDocPage(parser: Parser<"sync", unknown, unknown>, args?: rea
516
516
  declare function getDocPage(parser: Parser<"async", unknown, unknown>, args?: readonly string[]): Promise<DocPage | undefined>;
517
517
  declare function getDocPage<M extends Mode>(parser: Parser<M, unknown, unknown>, args?: readonly string[]): ModeValue<M, DocPage | undefined>;
518
518
  //#endregion
519
- export { ArgumentErrorOptions, ArgumentOptions, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, InferMode, InferValue, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionOptions, OptionState, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, Suggestion, TupleOptions, WithDefaultError, WithDefaultOptions, argument, command, concat, conditional, constant, flag, getDocPage, getDocPageAsync, getDocPageSync, group, longestMatch, map, merge, multiple, object, option, optional, or, parse, parseAsync, parseSync, passThrough, suggest, suggestAsync, suggestSync, tuple, withDefault };
519
+ export { ArgumentErrorOptions, ArgumentOptions, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, InferMode, InferValue, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionOptions, OptionState, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, Suggestion, TupleOptions, WithDefaultError, WithDefaultOptions, argument, command, concat, conditional, constant, flag, getDocPage, getDocPageAsync, getDocPageSync, group, longestMatch, map, merge, multiple, nonEmpty, object, option, optional, or, parse, parseAsync, parseSync, passThrough, suggest, suggestAsync, suggestSync, tuple, withDefault };
package/dist/parser.d.ts CHANGED
@@ -3,7 +3,7 @@ import { Usage } from "./usage.js";
3
3
  import { DocFragments, DocPage } from "./doc.js";
4
4
  import { ValueParserResult } from "./valueparser.js";
5
5
  import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
6
- import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, optional, withDefault } from "./modifiers.js";
6
+ import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
7
7
  import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, flag, option, passThrough } from "./primitives.js";
8
8
 
9
9
  //#region src/parser.d.ts
@@ -516,4 +516,4 @@ declare function getDocPage(parser: Parser<"sync", unknown, unknown>, args?: rea
516
516
  declare function getDocPage(parser: Parser<"async", unknown, unknown>, args?: readonly string[]): Promise<DocPage | undefined>;
517
517
  declare function getDocPage<M extends Mode>(parser: Parser<M, unknown, unknown>, args?: readonly string[]): ModeValue<M, DocPage | undefined>;
518
518
  //#endregion
519
- export { ArgumentErrorOptions, ArgumentOptions, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, InferMode, InferValue, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionOptions, OptionState, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, Suggestion, TupleOptions, WithDefaultError, WithDefaultOptions, argument, command, concat, conditional, constant, flag, getDocPage, getDocPageAsync, getDocPageSync, group, longestMatch, map, merge, multiple, object, option, optional, or, parse, parseAsync, parseSync, passThrough, suggest, suggestAsync, suggestSync, tuple, withDefault };
519
+ export { ArgumentErrorOptions, ArgumentOptions, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, InferMode, InferValue, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionOptions, OptionState, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, Suggestion, TupleOptions, WithDefaultError, WithDefaultOptions, argument, command, concat, conditional, constant, flag, getDocPage, getDocPageAsync, getDocPageSync, group, longestMatch, map, merge, multiple, nonEmpty, object, option, optional, or, parse, parseAsync, parseSync, passThrough, suggest, suggestAsync, suggestSync, tuple, withDefault };
package/dist/parser.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { message } from "./message.js";
2
2
  import { normalizeUsage } from "./usage.js";
3
3
  import { DuplicateOptionError, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
4
- import { WithDefaultError, map, multiple, optional, withDefault } from "./modifiers.js";
4
+ import { WithDefaultError, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
5
5
  import { argument, command, constant, flag, option, passThrough } from "./primitives.js";
6
6
 
7
7
  //#region src/parser.ts
@@ -371,4 +371,4 @@ function buildDocPage(parser, context, args) {
371
371
  }
372
372
 
373
373
  //#endregion
374
- export { DuplicateOptionError, WithDefaultError, argument, command, concat, conditional, constant, flag, getDocPage, getDocPageAsync, getDocPageSync, group, longestMatch, map, merge, multiple, object, option, optional, or, parse, parseAsync, parseSync, passThrough, suggest, suggestAsync, suggestSync, tuple, withDefault };
374
+ export { DuplicateOptionError, WithDefaultError, argument, command, concat, conditional, constant, flag, getDocPage, getDocPageAsync, getDocPageSync, group, longestMatch, map, merge, multiple, nonEmpty, object, option, optional, or, parse, parseAsync, parseSync, passThrough, suggest, suggestAsync, suggestSync, tuple, withDefault };
@@ -940,8 +940,21 @@ function command(name, parser, options = {}) {
940
940
  success: false,
941
941
  error: options.errors?.notFound ?? require_message.message`Command ${require_message.optionName(name)} was not matched.`
942
942
  };
943
- else if (state[0] === "matched") return parser.complete(parser.initialState);
944
- else if (state[0] === "parsing") return parser.complete(state[1]);
943
+ else if (state[0] === "matched") {
944
+ const parseResultOrPromise = parser.parse({
945
+ buffer: [],
946
+ optionsTerminated: false,
947
+ usage: [],
948
+ state: parser.initialState
949
+ });
950
+ if (isAsync) return parseResultOrPromise.then((parseResult$1) => {
951
+ if (parseResult$1.success) return parser.complete(parseResult$1.next.state);
952
+ return parser.complete(parser.initialState);
953
+ });
954
+ const parseResult = parseResultOrPromise;
955
+ if (parseResult.success) return parser.complete(parseResult.next.state);
956
+ return parser.complete(parser.initialState);
957
+ } else if (state[0] === "parsing") return parser.complete(state[1]);
945
958
  return {
946
959
  success: false,
947
960
  error: options.errors?.invalidState ?? require_message.message`Invalid command state during completion.`
@@ -940,8 +940,21 @@ function command(name, parser, options = {}) {
940
940
  success: false,
941
941
  error: options.errors?.notFound ?? message`Command ${optionName(name)} was not matched.`
942
942
  };
943
- else if (state[0] === "matched") return parser.complete(parser.initialState);
944
- else if (state[0] === "parsing") return parser.complete(state[1]);
943
+ else if (state[0] === "matched") {
944
+ const parseResultOrPromise = parser.parse({
945
+ buffer: [],
946
+ optionsTerminated: false,
947
+ usage: [],
948
+ state: parser.initialState
949
+ });
950
+ if (isAsync) return parseResultOrPromise.then((parseResult$1) => {
951
+ if (parseResult$1.success) return parser.complete(parseResult$1.next.state);
952
+ return parser.complete(parser.initialState);
953
+ });
954
+ const parseResult = parseResultOrPromise;
955
+ if (parseResult.success) return parser.complete(parseResult.next.state);
956
+ return parser.complete(parser.initialState);
957
+ } else if (state[0] === "parsing") return parser.complete(state[1]);
945
958
  return {
946
959
  success: false,
947
960
  error: options.errors?.invalidState ?? message`Invalid command state during completion.`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "0.10.0-dev.313+05a0d1bb",
3
+ "version": "0.10.0-dev.323+8b4662d5",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",