@optique/core 1.2.0-dev.2242 → 1.2.0-dev.2246

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.
@@ -279,16 +279,24 @@ function createErrorWithSuggestions(baseError, invalidInput, usage, type = "both
279
279
  */
280
280
  function appendValueHint(base, input, candidates, options) {
281
281
  const suggestions = findSimilar(input, candidates, options != null ? {
282
- ...DEFAULT_FIND_SIMILAR_OPTIONS,
283
- ...options
282
+ maxDistance: options.maxDistance ?? DEFAULT_FIND_SIMILAR_OPTIONS.maxDistance,
283
+ maxDistanceRatio: DEFAULT_FIND_SIMILAR_OPTIONS.maxDistanceRatio,
284
+ maxSuggestions: options.maxSuggestions ?? DEFAULT_FIND_SIMILAR_OPTIONS.maxSuggestions
284
285
  } : void 0);
285
- const suggestionMsg = createSuggestionMessage(suggestions);
286
- return suggestionMsg.length > 0 ? [
286
+ if (suggestions.length === 0) return base;
287
+ let suggestionMsg;
288
+ if (suggestions.length === 1) suggestionMsg = require_message.message`Did you mean ${require_message.value(suggestions[0])}?`;
289
+ else {
290
+ const parts = [require_message.text("Did you mean one of these?")];
291
+ for (const suggestion of suggestions) parts.push(require_message.text("\n "), require_message.value(suggestion));
292
+ suggestionMsg = parts;
293
+ }
294
+ return base.length > 0 ? [
287
295
  ...base,
288
296
  require_message.lineBreak(),
289
297
  require_message.lineBreak(),
290
298
  ...suggestionMsg
291
- ] : base;
299
+ ] : suggestionMsg;
292
300
  }
293
301
  /**
294
302
  * Creates a unique key for a suggestion to enable deduplication.
@@ -1,4 +1,4 @@
1
- import { lineBreak, message, optionName, text } from "./message.js";
1
+ import { lineBreak, message, optionName, text, value } from "./message.js";
2
2
  import { extractCommandNames, extractOptionNames, isSuggestionHidden } from "./usage.js";
3
3
 
4
4
  //#region src/suggestion.ts
@@ -279,16 +279,24 @@ function createErrorWithSuggestions(baseError, invalidInput, usage, type = "both
279
279
  */
280
280
  function appendValueHint(base, input, candidates, options) {
281
281
  const suggestions = findSimilar(input, candidates, options != null ? {
282
- ...DEFAULT_FIND_SIMILAR_OPTIONS,
283
- ...options
282
+ maxDistance: options.maxDistance ?? DEFAULT_FIND_SIMILAR_OPTIONS.maxDistance,
283
+ maxDistanceRatio: DEFAULT_FIND_SIMILAR_OPTIONS.maxDistanceRatio,
284
+ maxSuggestions: options.maxSuggestions ?? DEFAULT_FIND_SIMILAR_OPTIONS.maxSuggestions
284
285
  } : void 0);
285
- const suggestionMsg = createSuggestionMessage(suggestions);
286
- return suggestionMsg.length > 0 ? [
286
+ if (suggestions.length === 0) return base;
287
+ let suggestionMsg;
288
+ if (suggestions.length === 1) suggestionMsg = message`Did you mean ${value(suggestions[0])}?`;
289
+ else {
290
+ const parts = [text("Did you mean one of these?")];
291
+ for (const suggestion of suggestions) parts.push(text("\n "), value(suggestion));
292
+ suggestionMsg = parts;
293
+ }
294
+ return base.length > 0 ? [
287
295
  ...base,
288
296
  lineBreak(),
289
297
  lineBreak(),
290
298
  ...suggestionMsg
291
- ] : base;
299
+ ] : suggestionMsg;
292
300
  }
293
301
  /**
294
302
  * Creates a unique key for a suggestion to enable deduplication.