@optique/core 1.0.0-dev.416 → 1.0.0-dev.427

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/doc.cjs CHANGED
@@ -17,12 +17,22 @@ function classifySection(section) {
17
17
  return 2;
18
18
  }
19
19
  /**
20
+ * Scores a section for the default smart sort. Untitled sections receive
21
+ * a bonus of `-1` so that the main (untitled) section appears before titled
22
+ * sections of a similar classification.
23
+ */
24
+ function scoreSection(section) {
25
+ return classifySection(section) + (section.title == null ? -1 : 0);
26
+ }
27
+ /**
20
28
  * The default section comparator: command-only sections come first, then
21
- * mixed sections, then option/argument-only sections. Sections with the
29
+ * mixed sections, then option/argument-only sections. Untitled sections
30
+ * receive a slight priority boost so the main (untitled) section appears
31
+ * before titled sections of a similar classification. Sections with the
22
32
  * same score preserve their original relative order (stable sort).
23
33
  */
24
34
  function defaultSectionOrder(a, b) {
25
- return classifySection(a) - classifySection(b);
35
+ return scoreSection(a) - scoreSection(b);
26
36
  }
27
37
  /**
28
38
  * Formats a documentation page into a human-readable string.
@@ -109,18 +119,37 @@ function formatDocPage(programName, page, options = {}) {
109
119
  optionsSeparator: ", ",
110
120
  maxWidth: options.maxWidth == null ? void 0 : options.maxWidth - termIndent
111
121
  });
112
- let description = entry.description == null ? "" : require_message.formatMessage(entry.description, {
122
+ const descColumnWidth = options.maxWidth == null ? void 0 : options.maxWidth - termIndent - termWidth - 2;
123
+ const termVisibleWidth = lastLineVisibleLength(term);
124
+ const extraTermOffset = descColumnWidth != null ? Math.max(0, termVisibleWidth - termWidth) : 0;
125
+ const currentExtraOffset = () => description.includes("\n") ? 0 : extraTermOffset;
126
+ const descFormatOptions = {
113
127
  colors: options.colors,
114
128
  quotes: !options.colors,
115
- maxWidth: options.maxWidth == null ? void 0 : options.maxWidth - termIndent - termWidth - 2
116
- });
129
+ maxWidth: descColumnWidth,
130
+ startWidth: extraTermOffset > 0 ? extraTermOffset : void 0
131
+ };
132
+ let description = entry.description == null ? "" : require_message.formatMessage(entry.description, descFormatOptions);
117
133
  if (options.showDefault && entry.default != null) {
118
134
  const prefix = typeof options.showDefault === "object" ? options.showDefault.prefix ?? " [" : " [";
119
135
  const suffix = typeof options.showDefault === "object" ? options.showDefault.suffix ?? "]" : "]";
120
- const defaultText = `${prefix}${require_message.formatMessage(entry.default, {
136
+ let defaultStartWidth;
137
+ if (descColumnWidth != null) {
138
+ const lastW = lastLineVisibleLength(description);
139
+ const effectiveLastW = lastW + currentExtraOffset();
140
+ if (effectiveLastW + prefix.length >= descColumnWidth) {
141
+ description += "\n";
142
+ defaultStartWidth = prefix.length;
143
+ } else defaultStartWidth = effectiveLastW + prefix.length;
144
+ }
145
+ const defaultFormatOptions = {
121
146
  colors: options.colors ? { resetSuffix: "\x1B[2m" } : false,
122
- quotes: !options.colors
123
- })}${suffix}`;
147
+ quotes: !options.colors,
148
+ maxWidth: descColumnWidth == null ? void 0 : descColumnWidth - suffix.length,
149
+ startWidth: defaultStartWidth
150
+ };
151
+ const defaultContent = require_message.formatMessage(entry.default, defaultFormatOptions);
152
+ const defaultText = `${prefix}${defaultContent}${suffix}`;
124
153
  const formattedDefault = options.colors ? `\x1b[2m${defaultText}\x1b[0m` : defaultText;
125
154
  description += formattedDefault;
126
155
  }
@@ -145,10 +174,23 @@ function formatDocPage(programName, page, options = {}) {
145
174
  }
146
175
  if (truncated) truncatedTerms = [...terms.slice(0, cutIndex), require_message.text(", ...")];
147
176
  }
148
- const choicesDisplay = require_message.formatMessage(truncatedTerms, {
177
+ let choicesStartWidth;
178
+ if (descColumnWidth != null) {
179
+ const lastW = lastLineVisibleLength(description);
180
+ const effectiveLastW = lastW + currentExtraOffset();
181
+ const prefixLabelLen = prefix.length + label.length;
182
+ if (effectiveLastW + prefixLabelLen >= descColumnWidth) {
183
+ description += "\n";
184
+ choicesStartWidth = prefixLabelLen;
185
+ } else choicesStartWidth = effectiveLastW + prefixLabelLen;
186
+ }
187
+ const choicesFormatOptions = {
149
188
  colors: options.colors ? { resetSuffix: "\x1B[2m" } : false,
150
- quotes: false
151
- });
189
+ quotes: false,
190
+ maxWidth: descColumnWidth == null ? void 0 : descColumnWidth - suffix.length,
191
+ startWidth: choicesStartWidth
192
+ };
193
+ const choicesDisplay = require_message.formatMessage(truncatedTerms, choicesFormatOptions);
152
194
  const choicesText = `${prefix}${label}${choicesDisplay}${suffix}`;
153
195
  const formattedChoices = options.colors ? `\x1b[2m${choicesText}\x1b[0m` : choicesText;
154
196
  description += formattedChoices;
@@ -205,12 +247,17 @@ function formatDocPage(programName, page, options = {}) {
205
247
  function indentLines(text$1, indent) {
206
248
  return text$1.split("\n").join("\n" + " ".repeat(indent));
207
249
  }
250
+ const ansiEscapeCodeRegex = /\x1B\[[0-9;]*[a-zA-Z]/g;
208
251
  function ansiAwareRightPad(text$1, length, char = " ") {
209
- const ansiEscapeCodeRegex = /\x1B\[[0-9;]*[a-zA-Z]/g;
210
252
  const strippedText = text$1.replace(ansiEscapeCodeRegex, "");
211
253
  if (strippedText.length >= length) return text$1;
212
254
  return text$1 + char.repeat(length - strippedText.length);
213
255
  }
256
+ function lastLineVisibleLength(text$1) {
257
+ const lastNewline = text$1.lastIndexOf("\n");
258
+ const lastLine = lastNewline === -1 ? text$1 : text$1.slice(lastNewline + 1);
259
+ return lastLine.replace(ansiEscapeCodeRegex, "").length;
260
+ }
214
261
 
215
262
  //#endregion
216
263
  exports.formatDocPage = formatDocPage;
package/dist/doc.js CHANGED
@@ -17,12 +17,22 @@ function classifySection(section) {
17
17
  return 2;
18
18
  }
19
19
  /**
20
+ * Scores a section for the default smart sort. Untitled sections receive
21
+ * a bonus of `-1` so that the main (untitled) section appears before titled
22
+ * sections of a similar classification.
23
+ */
24
+ function scoreSection(section) {
25
+ return classifySection(section) + (section.title == null ? -1 : 0);
26
+ }
27
+ /**
20
28
  * The default section comparator: command-only sections come first, then
21
- * mixed sections, then option/argument-only sections. Sections with the
29
+ * mixed sections, then option/argument-only sections. Untitled sections
30
+ * receive a slight priority boost so the main (untitled) section appears
31
+ * before titled sections of a similar classification. Sections with the
22
32
  * same score preserve their original relative order (stable sort).
23
33
  */
24
34
  function defaultSectionOrder(a, b) {
25
- return classifySection(a) - classifySection(b);
35
+ return scoreSection(a) - scoreSection(b);
26
36
  }
27
37
  /**
28
38
  * Formats a documentation page into a human-readable string.
@@ -109,18 +119,37 @@ function formatDocPage(programName, page, options = {}) {
109
119
  optionsSeparator: ", ",
110
120
  maxWidth: options.maxWidth == null ? void 0 : options.maxWidth - termIndent
111
121
  });
112
- let description = entry.description == null ? "" : formatMessage(entry.description, {
122
+ const descColumnWidth = options.maxWidth == null ? void 0 : options.maxWidth - termIndent - termWidth - 2;
123
+ const termVisibleWidth = lastLineVisibleLength(term);
124
+ const extraTermOffset = descColumnWidth != null ? Math.max(0, termVisibleWidth - termWidth) : 0;
125
+ const currentExtraOffset = () => description.includes("\n") ? 0 : extraTermOffset;
126
+ const descFormatOptions = {
113
127
  colors: options.colors,
114
128
  quotes: !options.colors,
115
- maxWidth: options.maxWidth == null ? void 0 : options.maxWidth - termIndent - termWidth - 2
116
- });
129
+ maxWidth: descColumnWidth,
130
+ startWidth: extraTermOffset > 0 ? extraTermOffset : void 0
131
+ };
132
+ let description = entry.description == null ? "" : formatMessage(entry.description, descFormatOptions);
117
133
  if (options.showDefault && entry.default != null) {
118
134
  const prefix = typeof options.showDefault === "object" ? options.showDefault.prefix ?? " [" : " [";
119
135
  const suffix = typeof options.showDefault === "object" ? options.showDefault.suffix ?? "]" : "]";
120
- const defaultText = `${prefix}${formatMessage(entry.default, {
136
+ let defaultStartWidth;
137
+ if (descColumnWidth != null) {
138
+ const lastW = lastLineVisibleLength(description);
139
+ const effectiveLastW = lastW + currentExtraOffset();
140
+ if (effectiveLastW + prefix.length >= descColumnWidth) {
141
+ description += "\n";
142
+ defaultStartWidth = prefix.length;
143
+ } else defaultStartWidth = effectiveLastW + prefix.length;
144
+ }
145
+ const defaultFormatOptions = {
121
146
  colors: options.colors ? { resetSuffix: "\x1B[2m" } : false,
122
- quotes: !options.colors
123
- })}${suffix}`;
147
+ quotes: !options.colors,
148
+ maxWidth: descColumnWidth == null ? void 0 : descColumnWidth - suffix.length,
149
+ startWidth: defaultStartWidth
150
+ };
151
+ const defaultContent = formatMessage(entry.default, defaultFormatOptions);
152
+ const defaultText = `${prefix}${defaultContent}${suffix}`;
124
153
  const formattedDefault = options.colors ? `\x1b[2m${defaultText}\x1b[0m` : defaultText;
125
154
  description += formattedDefault;
126
155
  }
@@ -145,10 +174,23 @@ function formatDocPage(programName, page, options = {}) {
145
174
  }
146
175
  if (truncated) truncatedTerms = [...terms.slice(0, cutIndex), text(", ...")];
147
176
  }
148
- const choicesDisplay = formatMessage(truncatedTerms, {
177
+ let choicesStartWidth;
178
+ if (descColumnWidth != null) {
179
+ const lastW = lastLineVisibleLength(description);
180
+ const effectiveLastW = lastW + currentExtraOffset();
181
+ const prefixLabelLen = prefix.length + label.length;
182
+ if (effectiveLastW + prefixLabelLen >= descColumnWidth) {
183
+ description += "\n";
184
+ choicesStartWidth = prefixLabelLen;
185
+ } else choicesStartWidth = effectiveLastW + prefixLabelLen;
186
+ }
187
+ const choicesFormatOptions = {
149
188
  colors: options.colors ? { resetSuffix: "\x1B[2m" } : false,
150
- quotes: false
151
- });
189
+ quotes: false,
190
+ maxWidth: descColumnWidth == null ? void 0 : descColumnWidth - suffix.length,
191
+ startWidth: choicesStartWidth
192
+ };
193
+ const choicesDisplay = formatMessage(truncatedTerms, choicesFormatOptions);
152
194
  const choicesText = `${prefix}${label}${choicesDisplay}${suffix}`;
153
195
  const formattedChoices = options.colors ? `\x1b[2m${choicesText}\x1b[0m` : choicesText;
154
196
  description += formattedChoices;
@@ -205,12 +247,17 @@ function formatDocPage(programName, page, options = {}) {
205
247
  function indentLines(text$1, indent) {
206
248
  return text$1.split("\n").join("\n" + " ".repeat(indent));
207
249
  }
250
+ const ansiEscapeCodeRegex = /\x1B\[[0-9;]*[a-zA-Z]/g;
208
251
  function ansiAwareRightPad(text$1, length, char = " ") {
209
- const ansiEscapeCodeRegex = /\x1B\[[0-9;]*[a-zA-Z]/g;
210
252
  const strippedText = text$1.replace(ansiEscapeCodeRegex, "");
211
253
  if (strippedText.length >= length) return text$1;
212
254
  return text$1 + char.repeat(length - strippedText.length);
213
255
  }
256
+ function lastLineVisibleLength(text$1) {
257
+ const lastNewline = text$1.lastIndexOf("\n");
258
+ const lastLine = lastNewline === -1 ? text$1 : text$1.slice(lastNewline + 1);
259
+ return lastLine.replace(ansiEscapeCodeRegex, "").length;
260
+ }
214
261
 
215
262
  //#endregion
216
263
  export { formatDocPage };
package/dist/facade.cjs CHANGED
@@ -543,6 +543,9 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
543
543
  const helpAsCommand = help === "command" || help === "both";
544
544
  const versionAsCommand = version === "command" || version === "both";
545
545
  const completionAsCommand = completion === "command" || completion === "both";
546
+ const helpAsOption = help === "option" || help === "both";
547
+ const versionAsOption = version === "option" || version === "both";
548
+ const completionAsOption = completion === "option" || completion === "both";
546
549
  const requestedCommand = classified.commands[0];
547
550
  if ((requestedCommand === "completion" || requestedCommand === "completions") && completionAsCommand && completionParsers.completionCommand) helpGeneratorParser = completionParsers.completionCommand;
548
551
  else if (requestedCommand === "help" && helpAsCommand && helpParsers.helpCommand) helpGeneratorParser = helpParsers.helpCommand;
@@ -561,6 +564,9 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
561
564
  commandParsers.push(...ungroupedMeta);
562
565
  for (const [label, parsers] of Object.entries(groupedMeta)) if (parsers.length === 1) commandParsers.push(require_constructs.group(label, parsers[0]));
563
566
  else commandParsers.push(require_constructs.group(label, require_constructs.longestMatch(...parsers)));
567
+ if (helpAsOption && helpParsers.helpOption) commandParsers.push(helpParsers.helpOption);
568
+ if (versionAsOption && versionParsers.versionOption) commandParsers.push(versionParsers.versionOption);
569
+ if (completionAsOption && completionParsers.completionOption) commandParsers.push(completionParsers.completionOption);
564
570
  if (commandParsers.length === 1) helpGeneratorParser = commandParsers[0];
565
571
  else if (commandParsers.length === 2) helpGeneratorParser = require_constructs.longestMatch(commandParsers[0], commandParsers[1]);
566
572
  else helpGeneratorParser = require_constructs.longestMatch(...commandParsers);
@@ -1045,7 +1051,7 @@ function runWithAsync(parser, programName, contexts, options) {
1045
1051
  */
1046
1052
  function injectAnnotationsIntoParser(parser, annotations) {
1047
1053
  const newInitialState = {
1048
- ...parser.initialState,
1054
+ ...typeof parser.initialState === "object" && parser.initialState !== null ? parser.initialState : {},
1049
1055
  [require_annotations.annotationKey]: annotations
1050
1056
  };
1051
1057
  return {
package/dist/facade.js CHANGED
@@ -543,6 +543,9 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
543
543
  const helpAsCommand = help === "command" || help === "both";
544
544
  const versionAsCommand = version === "command" || version === "both";
545
545
  const completionAsCommand = completion === "command" || completion === "both";
546
+ const helpAsOption = help === "option" || help === "both";
547
+ const versionAsOption = version === "option" || version === "both";
548
+ const completionAsOption = completion === "option" || completion === "both";
546
549
  const requestedCommand = classified.commands[0];
547
550
  if ((requestedCommand === "completion" || requestedCommand === "completions") && completionAsCommand && completionParsers.completionCommand) helpGeneratorParser = completionParsers.completionCommand;
548
551
  else if (requestedCommand === "help" && helpAsCommand && helpParsers.helpCommand) helpGeneratorParser = helpParsers.helpCommand;
@@ -561,6 +564,9 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
561
564
  commandParsers.push(...ungroupedMeta);
562
565
  for (const [label, parsers] of Object.entries(groupedMeta)) if (parsers.length === 1) commandParsers.push(group(label, parsers[0]));
563
566
  else commandParsers.push(group(label, longestMatch(...parsers)));
567
+ if (helpAsOption && helpParsers.helpOption) commandParsers.push(helpParsers.helpOption);
568
+ if (versionAsOption && versionParsers.versionOption) commandParsers.push(versionParsers.versionOption);
569
+ if (completionAsOption && completionParsers.completionOption) commandParsers.push(completionParsers.completionOption);
564
570
  if (commandParsers.length === 1) helpGeneratorParser = commandParsers[0];
565
571
  else if (commandParsers.length === 2) helpGeneratorParser = longestMatch(commandParsers[0], commandParsers[1]);
566
572
  else helpGeneratorParser = longestMatch(...commandParsers);
@@ -1045,7 +1051,7 @@ function runWithAsync(parser, programName, contexts, options) {
1045
1051
  */
1046
1052
  function injectAnnotationsIntoParser(parser, annotations) {
1047
1053
  const newInitialState = {
1048
- ...parser.initialState,
1054
+ ...typeof parser.initialState === "object" && parser.initialState !== null ? parser.initialState : {},
1049
1055
  [annotationKey]: annotations
1050
1056
  };
1051
1057
  return {
package/dist/message.cjs CHANGED
@@ -237,14 +237,6 @@ function valueSet(values$1, options) {
237
237
  });
238
238
  return result;
239
239
  }
240
- /**
241
- * Formats a {@link Message} into a human-readable string for
242
- * the terminal.
243
- * @param msg The message to format, which is an array of
244
- * {@link MessageTerm} objects.
245
- * @param options Optional formatting options to customize the output.
246
- * @returns A formatted string representation of the message.
247
- */
248
240
  function formatMessage(msg, options = {}) {
249
241
  const colorConfig = options.colors ?? false;
250
242
  const useColors = typeof colorConfig === "boolean" ? colorConfig : true;
@@ -376,7 +368,7 @@ function formatMessage(msg, options = {}) {
376
368
  }
377
369
  }
378
370
  let output = "";
379
- let totalWidth = 0;
371
+ let totalWidth = options.startWidth ?? 0;
380
372
  for (const { text: text$1, width } of stream()) {
381
373
  if (width === -1) {
382
374
  output += text$1;
package/dist/message.js CHANGED
@@ -236,14 +236,6 @@ function valueSet(values$1, options) {
236
236
  });
237
237
  return result;
238
238
  }
239
- /**
240
- * Formats a {@link Message} into a human-readable string for
241
- * the terminal.
242
- * @param msg The message to format, which is an array of
243
- * {@link MessageTerm} objects.
244
- * @param options Optional formatting options to customize the output.
245
- * @returns A formatted string representation of the message.
246
- */
247
239
  function formatMessage(msg, options = {}) {
248
240
  const colorConfig = options.colors ?? false;
249
241
  const useColors = typeof colorConfig === "boolean" ? colorConfig : true;
@@ -375,7 +367,7 @@ function formatMessage(msg, options = {}) {
375
367
  }
376
368
  }
377
369
  let output = "";
378
- let totalWidth = 0;
370
+ let totalWidth = options.startWidth ?? 0;
379
371
  for (const { text: text$1, width } of stream()) {
380
372
  if (width === -1) {
381
373
  output += text$1;
@@ -12,7 +12,7 @@ const require_mode_dispatch = require('./mode-dispatch.cjs');
12
12
  * @internal
13
13
  */
14
14
  function parseOptionalStyleSync(context, parser) {
15
- const innerState = typeof context.state === "undefined" ? parser.initialState : context.state[0];
15
+ const innerState = Array.isArray(context.state) ? context.state[0] : parser.initialState;
16
16
  const result = parser.parse({
17
17
  ...context,
18
18
  state: innerState
@@ -24,7 +24,7 @@ function parseOptionalStyleSync(context, parser) {
24
24
  * @internal
25
25
  */
26
26
  async function parseOptionalStyleAsync(context, parser) {
27
- const innerState = typeof context.state === "undefined" ? parser.initialState : context.state[0];
27
+ const innerState = Array.isArray(context.state) ? context.state[0] : parser.initialState;
28
28
  const result = await parser.parse({
29
29
  ...context,
30
30
  state: innerState
@@ -76,14 +76,14 @@ function processOptionalStyleResult(result, innerState, context) {
76
76
  function optional(parser) {
77
77
  const syncParser = parser;
78
78
  function* suggestSync(context, prefix) {
79
- const innerState = typeof context.state === "undefined" ? syncParser.initialState : context.state[0];
79
+ const innerState = Array.isArray(context.state) ? context.state[0] : syncParser.initialState;
80
80
  yield* syncParser.suggest({
81
81
  ...context,
82
82
  state: innerState
83
83
  }, prefix);
84
84
  }
85
85
  async function* suggestAsync(context, prefix) {
86
- const innerState = typeof context.state === "undefined" ? syncParser.initialState : context.state[0];
86
+ const innerState = Array.isArray(context.state) ? context.state[0] : syncParser.initialState;
87
87
  const suggestions = parser.suggest({
88
88
  ...context,
89
89
  state: innerState
@@ -110,7 +110,7 @@ function optional(parser) {
110
110
  return require_mode_dispatch.dispatchByMode(parser.$mode, () => parseOptionalStyleSync(context, syncParser), () => parseOptionalStyleAsync(context, parser));
111
111
  },
112
112
  complete(state) {
113
- if (typeof state === "undefined") {
113
+ if (!Array.isArray(state)) {
114
114
  if (innerHasWrappedDependency && wrappedPendingState) return require_mode_dispatch.dispatchByMode(parser.$mode, () => syncParser.complete([wrappedPendingState]), () => parser.complete([wrappedPendingState]));
115
115
  return {
116
116
  success: true,
@@ -175,14 +175,14 @@ var WithDefaultError = class extends Error {
175
175
  function withDefault(parser, defaultValue, options) {
176
176
  const syncParser = parser;
177
177
  function* suggestSync(context, prefix) {
178
- const innerState = typeof context.state === "undefined" ? syncParser.initialState : context.state[0];
178
+ const innerState = Array.isArray(context.state) ? context.state[0] : syncParser.initialState;
179
179
  yield* syncParser.suggest({
180
180
  ...context,
181
181
  state: innerState
182
182
  }, prefix);
183
183
  }
184
184
  async function* suggestAsync(context, prefix) {
185
- const innerState = typeof context.state === "undefined" ? syncParser.initialState : context.state[0];
185
+ const innerState = Array.isArray(context.state) ? context.state[0] : syncParser.initialState;
186
186
  const suggestions = parser.suggest({
187
187
  ...context,
188
188
  state: innerState
@@ -206,7 +206,7 @@ function withDefault(parser, defaultValue, options) {
206
206
  return require_mode_dispatch.dispatchByMode(parser.$mode, () => parseOptionalStyleSync(context, syncParser), () => parseOptionalStyleAsync(context, parser));
207
207
  },
208
208
  complete(state) {
209
- if (typeof state === "undefined") {
209
+ if (!Array.isArray(state)) {
210
210
  if (require_dependency.transformsDependencyValue(parser)) {
211
211
  const innerResult = require_mode_dispatch.dispatchByMode(parser.$mode, () => syncParser.complete(void 0), () => parser.complete(void 0));
212
212
  const handleInnerResult = (res) => {
package/dist/modifiers.js CHANGED
@@ -12,7 +12,7 @@ import { dispatchByMode, dispatchIterableByMode } from "./mode-dispatch.js";
12
12
  * @internal
13
13
  */
14
14
  function parseOptionalStyleSync(context, parser) {
15
- const innerState = typeof context.state === "undefined" ? parser.initialState : context.state[0];
15
+ const innerState = Array.isArray(context.state) ? context.state[0] : parser.initialState;
16
16
  const result = parser.parse({
17
17
  ...context,
18
18
  state: innerState
@@ -24,7 +24,7 @@ function parseOptionalStyleSync(context, parser) {
24
24
  * @internal
25
25
  */
26
26
  async function parseOptionalStyleAsync(context, parser) {
27
- const innerState = typeof context.state === "undefined" ? parser.initialState : context.state[0];
27
+ const innerState = Array.isArray(context.state) ? context.state[0] : parser.initialState;
28
28
  const result = await parser.parse({
29
29
  ...context,
30
30
  state: innerState
@@ -76,14 +76,14 @@ function processOptionalStyleResult(result, innerState, context) {
76
76
  function optional(parser) {
77
77
  const syncParser = parser;
78
78
  function* suggestSync(context, prefix) {
79
- const innerState = typeof context.state === "undefined" ? syncParser.initialState : context.state[0];
79
+ const innerState = Array.isArray(context.state) ? context.state[0] : syncParser.initialState;
80
80
  yield* syncParser.suggest({
81
81
  ...context,
82
82
  state: innerState
83
83
  }, prefix);
84
84
  }
85
85
  async function* suggestAsync(context, prefix) {
86
- const innerState = typeof context.state === "undefined" ? syncParser.initialState : context.state[0];
86
+ const innerState = Array.isArray(context.state) ? context.state[0] : syncParser.initialState;
87
87
  const suggestions = parser.suggest({
88
88
  ...context,
89
89
  state: innerState
@@ -110,7 +110,7 @@ function optional(parser) {
110
110
  return dispatchByMode(parser.$mode, () => parseOptionalStyleSync(context, syncParser), () => parseOptionalStyleAsync(context, parser));
111
111
  },
112
112
  complete(state) {
113
- if (typeof state === "undefined") {
113
+ if (!Array.isArray(state)) {
114
114
  if (innerHasWrappedDependency && wrappedPendingState) return dispatchByMode(parser.$mode, () => syncParser.complete([wrappedPendingState]), () => parser.complete([wrappedPendingState]));
115
115
  return {
116
116
  success: true,
@@ -175,14 +175,14 @@ var WithDefaultError = class extends Error {
175
175
  function withDefault(parser, defaultValue, options) {
176
176
  const syncParser = parser;
177
177
  function* suggestSync(context, prefix) {
178
- const innerState = typeof context.state === "undefined" ? syncParser.initialState : context.state[0];
178
+ const innerState = Array.isArray(context.state) ? context.state[0] : syncParser.initialState;
179
179
  yield* syncParser.suggest({
180
180
  ...context,
181
181
  state: innerState
182
182
  }, prefix);
183
183
  }
184
184
  async function* suggestAsync(context, prefix) {
185
- const innerState = typeof context.state === "undefined" ? syncParser.initialState : context.state[0];
185
+ const innerState = Array.isArray(context.state) ? context.state[0] : syncParser.initialState;
186
186
  const suggestions = parser.suggest({
187
187
  ...context,
188
188
  state: innerState
@@ -206,7 +206,7 @@ function withDefault(parser, defaultValue, options) {
206
206
  return dispatchByMode(parser.$mode, () => parseOptionalStyleSync(context, syncParser), () => parseOptionalStyleAsync(context, parser));
207
207
  },
208
208
  complete(state) {
209
- if (typeof state === "undefined") {
209
+ if (!Array.isArray(state)) {
210
210
  if (transformsDependencyValue(parser)) {
211
211
  const innerResult = dispatchByMode(parser.$mode, () => syncParser.complete(void 0), () => parser.complete(void 0));
212
212
  const handleInnerResult = (res) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.416+db8179aa",
3
+ "version": "1.0.0-dev.427+497e26fe",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",