@optique/core 0.3.0-dev.39 → 0.3.0-dev.40

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.d.cts CHANGED
@@ -2,6 +2,6 @@ import { Message, MessageFormatOptions, MessageTerm, formatMessage, message, met
2
2
  import { OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, formatUsage, formatUsageTerm, normalizeUsage } from "./usage.cjs";
3
3
  import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, 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
- import { ArgumentOptions, CommandOptions, FlagOptions, InferValue, MultipleOptions, OptionOptions, Parser, ParserContext, ParserResult, Result, argument, command, concat, constant, flag, getDocPage, map, merge, multiple, object, option, optional, or, parse, tuple, withDefault } from "./parser.cjs";
5
+ import { ArgumentOptions, CommandOptions, DocState, FlagOptions, InferValue, MultipleOptions, OptionOptions, Parser, ParserContext, ParserResult, Result, argument, command, concat, constant, flag, getDocPage, 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, 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, integer, isValueParser, locale, 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, StringOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, argument, choice, command, concat, constant, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, integer, isValueParser, locale, 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
@@ -2,6 +2,6 @@ import { Message, MessageFormatOptions, MessageTerm, formatMessage, message, met
2
2
  import { OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, formatUsage, formatUsageTerm, normalizeUsage } from "./usage.js";
3
3
  import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, 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
- import { ArgumentOptions, CommandOptions, FlagOptions, InferValue, MultipleOptions, OptionOptions, Parser, ParserContext, ParserResult, Result, argument, command, concat, constant, flag, getDocPage, map, merge, multiple, object, option, optional, or, parse, tuple, withDefault } from "./parser.js";
5
+ import { ArgumentOptions, CommandOptions, DocState, FlagOptions, InferValue, MultipleOptions, OptionOptions, Parser, ParserContext, ParserResult, Result, argument, command, concat, constant, flag, getDocPage, 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, 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, integer, isValueParser, locale, 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, StringOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, argument, choice, command, concat, constant, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, integer, isValueParser, locale, map, merge, message, metavar, multiple, normalizeUsage, object, option, optionName, optionNames, optional, or, parse, run, string, text, tuple, url, uuid, value, values, withDefault };
package/dist/parser.cjs CHANGED
@@ -514,7 +514,11 @@ function optional(parser) {
514
514
  return parser.complete(state[0]);
515
515
  },
516
516
  getDocFragments(state, defaultValue) {
517
- return parser.getDocFragments(typeof state === "undefined" ? parser.initialState : state[0], defaultValue);
517
+ const innerState = state.kind === "unavailable" ? { kind: "unavailable" } : state.state === void 0 ? { kind: "unavailable" } : {
518
+ kind: "available",
519
+ state: state.state[0]
520
+ };
521
+ return parser.getDocFragments(innerState, defaultValue);
518
522
  }
519
523
  };
520
524
  }
@@ -566,7 +570,11 @@ function withDefault(parser, defaultValue) {
566
570
  return parser.complete(state[0]);
567
571
  },
568
572
  getDocFragments(state, upperDefaultValue) {
569
- return parser.getDocFragments(typeof state === "undefined" ? parser.initialState : state[0], upperDefaultValue != null ? upperDefaultValue : typeof defaultValue === "function" ? defaultValue() : defaultValue);
573
+ const innerState = state.kind === "unavailable" ? { kind: "unavailable" } : state.state === void 0 ? { kind: "unavailable" } : {
574
+ kind: "available",
575
+ state: state.state[0]
576
+ };
577
+ return parser.getDocFragments(innerState, upperDefaultValue != null ? upperDefaultValue : typeof defaultValue === "function" ? defaultValue() : defaultValue);
570
578
  }
571
579
  };
572
580
  }
@@ -697,7 +705,11 @@ function multiple(parser, options = {}) {
697
705
  };
698
706
  },
699
707
  getDocFragments(state, defaultValue) {
700
- return parser.getDocFragments(state.at(-1) ?? parser.initialState, defaultValue != null && defaultValue.length > 0 ? defaultValue[0] : void 0);
708
+ const innerState = state.kind === "unavailable" ? { kind: "unavailable" } : state.state.length > 0 ? {
709
+ kind: "available",
710
+ state: state.state.at(-1)
711
+ } : { kind: "unavailable" };
712
+ return parser.getDocFragments(innerState, defaultValue != null && defaultValue.length > 0 ? defaultValue[0] : void 0);
701
713
  }
702
714
  };
703
715
  }
@@ -788,7 +800,13 @@ function object(labelOrParsers, maybeParsers) {
788
800
  };
789
801
  },
790
802
  getDocFragments(state, defaultValue) {
791
- const fragments = parserPairs.flatMap(([field, p]) => p.getDocFragments(state[field], defaultValue?.[field]).fragments);
803
+ const fragments = parserPairs.flatMap(([field, p]) => {
804
+ const fieldState = state.kind === "unavailable" ? { kind: "unavailable" } : {
805
+ kind: "available",
806
+ state: state.state[field]
807
+ };
808
+ return p.getDocFragments(fieldState, defaultValue?.[field]).fragments;
809
+ });
792
810
  const entries = fragments.filter((d) => d.type === "entry");
793
811
  const sections = [];
794
812
  for (const fragment of fragments) {
@@ -892,7 +910,13 @@ function tuple(labelOrParsers, maybeParsers) {
892
910
  };
893
911
  },
894
912
  getDocFragments(state, defaultValue) {
895
- const fragments = parsers.flatMap((p, i) => p.getDocFragments(state[i], defaultValue?.[i]).fragments);
913
+ const fragments = parsers.flatMap((p, i) => {
914
+ const indexState = state.kind === "unavailable" ? { kind: "unavailable" } : {
915
+ kind: "available",
916
+ state: state.state[i]
917
+ };
918
+ return p.getDocFragments(indexState, defaultValue?.[i]).fragments;
919
+ });
896
920
  const entries = fragments.filter((d) => d.type === "entry");
897
921
  const sections = [];
898
922
  for (const fragment of fragments) {
@@ -976,10 +1000,14 @@ function or(...parsers) {
976
1000
  getDocFragments(state, _defaultValue) {
977
1001
  let description;
978
1002
  let fragments;
979
- if (state == null) fragments = parsers.flatMap((p) => p.getDocFragments(p.initialState, void 0).fragments);
1003
+ if (state.kind === "unavailable" || state.state == null) fragments = parsers.flatMap((p) => p.getDocFragments({ kind: "unavailable" }, void 0).fragments);
980
1004
  else {
981
- const [index, parserResult] = state;
982
- const docFragments = parsers[index].getDocFragments(parserResult.success ? parserResult.next.state : parsers[index].initialState, void 0);
1005
+ const [index, parserResult] = state.state;
1006
+ const innerState = parserResult.success ? {
1007
+ kind: "available",
1008
+ state: parserResult.next.state
1009
+ } : { kind: "unavailable" };
1010
+ const docFragments = parsers[index].getDocFragments(innerState, void 0);
983
1011
  description = docFragments.description;
984
1012
  fragments = docFragments.fragments;
985
1013
  }
@@ -1082,7 +1110,13 @@ function merge(...parsers) {
1082
1110
  };
1083
1111
  },
1084
1112
  getDocFragments(state, _defaultValue) {
1085
- const fragments = parsers.flatMap((p) => p.getDocFragments(state, void 0).fragments);
1113
+ const fragments = parsers.flatMap((p) => {
1114
+ const parserState = p.initialState === void 0 ? { kind: "unavailable" } : state.kind === "unavailable" ? { kind: "unavailable" } : {
1115
+ kind: "available",
1116
+ state: state.state
1117
+ };
1118
+ return p.getDocFragments(parserState, void 0).fragments;
1119
+ });
1086
1120
  const entries = fragments.filter((f) => f.type === "entry");
1087
1121
  const sections = [];
1088
1122
  for (const fragment of fragments) {
@@ -1183,7 +1217,13 @@ function concat(...parsers) {
1183
1217
  };
1184
1218
  },
1185
1219
  getDocFragments(state, _defaultValue) {
1186
- const fragments = parsers.flatMap((p, index) => p.getDocFragments(state[index], void 0).fragments);
1220
+ const fragments = parsers.flatMap((p, index) => {
1221
+ const indexState = state.kind === "unavailable" ? { kind: "unavailable" } : {
1222
+ kind: "available",
1223
+ state: state.state[index]
1224
+ };
1225
+ return p.getDocFragments(indexState, void 0).fragments;
1226
+ });
1187
1227
  const entries = fragments.filter((f) => f.type === "entry");
1188
1228
  const sections = [];
1189
1229
  for (const fragment of fragments) {
@@ -1290,7 +1330,7 @@ function command(name, parser, options = {}) {
1290
1330
  };
1291
1331
  },
1292
1332
  getDocFragments(state, defaultValue) {
1293
- if (typeof state === "undefined") return {
1333
+ if (state.kind === "unavailable" || typeof state.state === "undefined") return {
1294
1334
  description: options.description,
1295
1335
  fragments: [{
1296
1336
  type: "entry",
@@ -1301,7 +1341,11 @@ function command(name, parser, options = {}) {
1301
1341
  description: options.description
1302
1342
  }]
1303
1343
  };
1304
- const innerFragments = parser.getDocFragments(state[0] === "parsing" ? state[1] : parser.initialState, defaultValue);
1344
+ const innerState = state.state[0] === "parsing" ? {
1345
+ kind: "available",
1346
+ state: state.state[1]
1347
+ } : { kind: "unavailable" };
1348
+ const innerFragments = parser.getDocFragments(innerState, defaultValue);
1305
1349
  return {
1306
1350
  ...innerFragments,
1307
1351
  description: innerFragments.description ?? options.description
@@ -1398,7 +1442,10 @@ function getDocPage(parser, args = []) {
1398
1442
  if (!result.success) break;
1399
1443
  context = result.next;
1400
1444
  } while (context.buffer.length > 0);
1401
- const { description, fragments } = parser.getDocFragments(context.state, void 0);
1445
+ const { description, fragments } = parser.getDocFragments({
1446
+ kind: "available",
1447
+ state: context.state
1448
+ }, void 0);
1402
1449
  const entries = fragments.filter((f) => f.type === "entry");
1403
1450
  const sections = [];
1404
1451
  for (const fragment of fragments) {
package/dist/parser.d.cts CHANGED
@@ -5,6 +5,19 @@ import { ValueParser, ValueParserResult } from "./valueparser.cjs";
5
5
 
6
6
  //#region src/parser.d.ts
7
7
 
8
+ /**
9
+ * Represents the state passed to getDocFragments.
10
+ * Can be either the actual parser state or an explicit indicator
11
+ * that no state is available.
12
+ * @template TState The type of the actual state when available.
13
+ * @since 0.3.0
14
+ */
15
+ type DocState<TState> = {
16
+ readonly kind: "available";
17
+ readonly state: TState;
18
+ } | {
19
+ readonly kind: "unavailable";
20
+ };
8
21
  /**
9
22
  * Parser interface for command-line argument parsing.
10
23
  * @template TValue The type of the value returned by the parser.
@@ -65,15 +78,14 @@ interface Parser<TValue, TState> {
65
78
  /**
66
79
  * Generates a documentation fragment for this parser, which can be used
67
80
  * to describe the parser's usage, description, and default value.
68
- * @param state The current state of the parser, which may contain
69
- * accumulated data or context needed to produce
70
- * the documentation.
81
+ * @param state The current state of the parser, wrapped in a DocState
82
+ * to indicate whether the actual state is available or not.
71
83
  * @param defaultValue An optional default value that can be used
72
84
  * to provide a default value in the documentation.
73
85
  * @returns {@link DocFragments} object containing documentation
74
86
  * fragments for this parser.
75
87
  */
76
- getDocFragments(state: TState, defaultValue?: TValue): DocFragments;
88
+ getDocFragments(state: DocState<TState>, defaultValue?: TValue): DocFragments;
77
89
  }
78
90
  /**
79
91
  * The context of the parser, which includes the input buffer and the state.
@@ -924,4 +936,4 @@ declare function parse<T>(parser: Parser<T, unknown>, args: readonly string[]):
924
936
  */
925
937
  declare function getDocPage(parser: Parser<unknown, unknown>, args?: readonly string[]): DocPage | undefined;
926
938
  //#endregion
927
- export { ArgumentOptions, CommandOptions, FlagOptions, InferValue, MultipleOptions, OptionOptions, Parser, ParserContext, ParserResult, Result, argument, command, concat, constant, flag, getDocPage, map, merge, multiple, object, option, optional, or, parse, tuple, withDefault };
939
+ export { ArgumentOptions, CommandOptions, DocState, FlagOptions, InferValue, MultipleOptions, OptionOptions, Parser, ParserContext, ParserResult, Result, argument, command, concat, constant, flag, getDocPage, map, merge, multiple, object, option, optional, or, parse, tuple, withDefault };
package/dist/parser.d.ts CHANGED
@@ -5,6 +5,19 @@ import { ValueParser, ValueParserResult } from "./valueparser.js";
5
5
 
6
6
  //#region src/parser.d.ts
7
7
 
8
+ /**
9
+ * Represents the state passed to getDocFragments.
10
+ * Can be either the actual parser state or an explicit indicator
11
+ * that no state is available.
12
+ * @template TState The type of the actual state when available.
13
+ * @since 0.3.0
14
+ */
15
+ type DocState<TState> = {
16
+ readonly kind: "available";
17
+ readonly state: TState;
18
+ } | {
19
+ readonly kind: "unavailable";
20
+ };
8
21
  /**
9
22
  * Parser interface for command-line argument parsing.
10
23
  * @template TValue The type of the value returned by the parser.
@@ -65,15 +78,14 @@ interface Parser<TValue, TState> {
65
78
  /**
66
79
  * Generates a documentation fragment for this parser, which can be used
67
80
  * to describe the parser's usage, description, and default value.
68
- * @param state The current state of the parser, which may contain
69
- * accumulated data or context needed to produce
70
- * the documentation.
81
+ * @param state The current state of the parser, wrapped in a DocState
82
+ * to indicate whether the actual state is available or not.
71
83
  * @param defaultValue An optional default value that can be used
72
84
  * to provide a default value in the documentation.
73
85
  * @returns {@link DocFragments} object containing documentation
74
86
  * fragments for this parser.
75
87
  */
76
- getDocFragments(state: TState, defaultValue?: TValue): DocFragments;
88
+ getDocFragments(state: DocState<TState>, defaultValue?: TValue): DocFragments;
77
89
  }
78
90
  /**
79
91
  * The context of the parser, which includes the input buffer and the state.
@@ -924,4 +936,4 @@ declare function parse<T>(parser: Parser<T, unknown>, args: readonly string[]):
924
936
  */
925
937
  declare function getDocPage(parser: Parser<unknown, unknown>, args?: readonly string[]): DocPage | undefined;
926
938
  //#endregion
927
- export { ArgumentOptions, CommandOptions, FlagOptions, InferValue, MultipleOptions, OptionOptions, Parser, ParserContext, ParserResult, Result, argument, command, concat, constant, flag, getDocPage, map, merge, multiple, object, option, optional, or, parse, tuple, withDefault };
939
+ export { ArgumentOptions, CommandOptions, DocState, FlagOptions, InferValue, MultipleOptions, OptionOptions, Parser, ParserContext, ParserResult, Result, argument, command, concat, constant, flag, getDocPage, map, merge, multiple, object, option, optional, or, parse, tuple, withDefault };
package/dist/parser.js CHANGED
@@ -514,7 +514,11 @@ function optional(parser) {
514
514
  return parser.complete(state[0]);
515
515
  },
516
516
  getDocFragments(state, defaultValue) {
517
- return parser.getDocFragments(typeof state === "undefined" ? parser.initialState : state[0], defaultValue);
517
+ const innerState = state.kind === "unavailable" ? { kind: "unavailable" } : state.state === void 0 ? { kind: "unavailable" } : {
518
+ kind: "available",
519
+ state: state.state[0]
520
+ };
521
+ return parser.getDocFragments(innerState, defaultValue);
518
522
  }
519
523
  };
520
524
  }
@@ -566,7 +570,11 @@ function withDefault(parser, defaultValue) {
566
570
  return parser.complete(state[0]);
567
571
  },
568
572
  getDocFragments(state, upperDefaultValue) {
569
- return parser.getDocFragments(typeof state === "undefined" ? parser.initialState : state[0], upperDefaultValue != null ? upperDefaultValue : typeof defaultValue === "function" ? defaultValue() : defaultValue);
573
+ const innerState = state.kind === "unavailable" ? { kind: "unavailable" } : state.state === void 0 ? { kind: "unavailable" } : {
574
+ kind: "available",
575
+ state: state.state[0]
576
+ };
577
+ return parser.getDocFragments(innerState, upperDefaultValue != null ? upperDefaultValue : typeof defaultValue === "function" ? defaultValue() : defaultValue);
570
578
  }
571
579
  };
572
580
  }
@@ -697,7 +705,11 @@ function multiple(parser, options = {}) {
697
705
  };
698
706
  },
699
707
  getDocFragments(state, defaultValue) {
700
- return parser.getDocFragments(state.at(-1) ?? parser.initialState, defaultValue != null && defaultValue.length > 0 ? defaultValue[0] : void 0);
708
+ const innerState = state.kind === "unavailable" ? { kind: "unavailable" } : state.state.length > 0 ? {
709
+ kind: "available",
710
+ state: state.state.at(-1)
711
+ } : { kind: "unavailable" };
712
+ return parser.getDocFragments(innerState, defaultValue != null && defaultValue.length > 0 ? defaultValue[0] : void 0);
701
713
  }
702
714
  };
703
715
  }
@@ -788,7 +800,13 @@ function object(labelOrParsers, maybeParsers) {
788
800
  };
789
801
  },
790
802
  getDocFragments(state, defaultValue) {
791
- const fragments = parserPairs.flatMap(([field, p]) => p.getDocFragments(state[field], defaultValue?.[field]).fragments);
803
+ const fragments = parserPairs.flatMap(([field, p]) => {
804
+ const fieldState = state.kind === "unavailable" ? { kind: "unavailable" } : {
805
+ kind: "available",
806
+ state: state.state[field]
807
+ };
808
+ return p.getDocFragments(fieldState, defaultValue?.[field]).fragments;
809
+ });
792
810
  const entries = fragments.filter((d) => d.type === "entry");
793
811
  const sections = [];
794
812
  for (const fragment of fragments) {
@@ -892,7 +910,13 @@ function tuple(labelOrParsers, maybeParsers) {
892
910
  };
893
911
  },
894
912
  getDocFragments(state, defaultValue) {
895
- const fragments = parsers.flatMap((p, i) => p.getDocFragments(state[i], defaultValue?.[i]).fragments);
913
+ const fragments = parsers.flatMap((p, i) => {
914
+ const indexState = state.kind === "unavailable" ? { kind: "unavailable" } : {
915
+ kind: "available",
916
+ state: state.state[i]
917
+ };
918
+ return p.getDocFragments(indexState, defaultValue?.[i]).fragments;
919
+ });
896
920
  const entries = fragments.filter((d) => d.type === "entry");
897
921
  const sections = [];
898
922
  for (const fragment of fragments) {
@@ -976,10 +1000,14 @@ function or(...parsers) {
976
1000
  getDocFragments(state, _defaultValue) {
977
1001
  let description;
978
1002
  let fragments;
979
- if (state == null) fragments = parsers.flatMap((p) => p.getDocFragments(p.initialState, void 0).fragments);
1003
+ if (state.kind === "unavailable" || state.state == null) fragments = parsers.flatMap((p) => p.getDocFragments({ kind: "unavailable" }, void 0).fragments);
980
1004
  else {
981
- const [index, parserResult] = state;
982
- const docFragments = parsers[index].getDocFragments(parserResult.success ? parserResult.next.state : parsers[index].initialState, void 0);
1005
+ const [index, parserResult] = state.state;
1006
+ const innerState = parserResult.success ? {
1007
+ kind: "available",
1008
+ state: parserResult.next.state
1009
+ } : { kind: "unavailable" };
1010
+ const docFragments = parsers[index].getDocFragments(innerState, void 0);
983
1011
  description = docFragments.description;
984
1012
  fragments = docFragments.fragments;
985
1013
  }
@@ -1082,7 +1110,13 @@ function merge(...parsers) {
1082
1110
  };
1083
1111
  },
1084
1112
  getDocFragments(state, _defaultValue) {
1085
- const fragments = parsers.flatMap((p) => p.getDocFragments(state, void 0).fragments);
1113
+ const fragments = parsers.flatMap((p) => {
1114
+ const parserState = p.initialState === void 0 ? { kind: "unavailable" } : state.kind === "unavailable" ? { kind: "unavailable" } : {
1115
+ kind: "available",
1116
+ state: state.state
1117
+ };
1118
+ return p.getDocFragments(parserState, void 0).fragments;
1119
+ });
1086
1120
  const entries = fragments.filter((f) => f.type === "entry");
1087
1121
  const sections = [];
1088
1122
  for (const fragment of fragments) {
@@ -1183,7 +1217,13 @@ function concat(...parsers) {
1183
1217
  };
1184
1218
  },
1185
1219
  getDocFragments(state, _defaultValue) {
1186
- const fragments = parsers.flatMap((p, index) => p.getDocFragments(state[index], void 0).fragments);
1220
+ const fragments = parsers.flatMap((p, index) => {
1221
+ const indexState = state.kind === "unavailable" ? { kind: "unavailable" } : {
1222
+ kind: "available",
1223
+ state: state.state[index]
1224
+ };
1225
+ return p.getDocFragments(indexState, void 0).fragments;
1226
+ });
1187
1227
  const entries = fragments.filter((f) => f.type === "entry");
1188
1228
  const sections = [];
1189
1229
  for (const fragment of fragments) {
@@ -1290,7 +1330,7 @@ function command(name, parser, options = {}) {
1290
1330
  };
1291
1331
  },
1292
1332
  getDocFragments(state, defaultValue) {
1293
- if (typeof state === "undefined") return {
1333
+ if (state.kind === "unavailable" || typeof state.state === "undefined") return {
1294
1334
  description: options.description,
1295
1335
  fragments: [{
1296
1336
  type: "entry",
@@ -1301,7 +1341,11 @@ function command(name, parser, options = {}) {
1301
1341
  description: options.description
1302
1342
  }]
1303
1343
  };
1304
- const innerFragments = parser.getDocFragments(state[0] === "parsing" ? state[1] : parser.initialState, defaultValue);
1344
+ const innerState = state.state[0] === "parsing" ? {
1345
+ kind: "available",
1346
+ state: state.state[1]
1347
+ } : { kind: "unavailable" };
1348
+ const innerFragments = parser.getDocFragments(innerState, defaultValue);
1305
1349
  return {
1306
1350
  ...innerFragments,
1307
1351
  description: innerFragments.description ?? options.description
@@ -1398,7 +1442,10 @@ function getDocPage(parser, args = []) {
1398
1442
  if (!result.success) break;
1399
1443
  context = result.next;
1400
1444
  } while (context.buffer.length > 0);
1401
- const { description, fragments } = parser.getDocFragments(context.state, void 0);
1445
+ const { description, fragments } = parser.getDocFragments({
1446
+ kind: "available",
1447
+ state: context.state
1448
+ }, void 0);
1402
1449
  const entries = fragments.filter((f) => f.type === "entry");
1403
1450
  const sections = [];
1404
1451
  for (const fragment of fragments) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "0.3.0-dev.39+80d894ad",
3
+ "version": "0.3.0-dev.40+7b4a92a1",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",