@optique/core 1.0.0-dev.1300 → 1.0.0-dev.1309

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
@@ -87,24 +87,20 @@ function formatDocPage(programName, page, options = {}) {
87
87
  ...page,
88
88
  sections: filteredSections
89
89
  };
90
+ const hasContent = (msg) => Array.isArray(msg) && msg.length > 0;
90
91
  if (options.maxWidth != null) {
91
92
  const hasEntries = page.sections.some((s) => s.entries.length > 0);
92
- const hasContent = (msg) => Array.isArray(msg) && msg.length > 0;
93
- const needsDescColumn = hasEntries && page.sections.some((s) => s.entries.some((e) => hasContent(e.description) || options.showDefault && e.default != null || options.showChoices && e.choices != null));
93
+ const needsDescColumn = hasEntries && page.sections.some((s) => s.entries.some((e) => hasContent(e.description) || options.showDefault && hasContent(e.default) || options.showChoices && hasContent(e.choices)));
94
94
  let minDescWidth = 1;
95
95
  if (needsDescColumn) {
96
- if (options.showDefault && page.sections.some((s) => s.entries.some((e) => e.default != null))) {
96
+ if (options.showDefault && page.sections.some((s) => s.entries.some((e) => hasContent(e.default)))) {
97
97
  const prefix = typeof options.showDefault === "object" ? options.showDefault.prefix ?? " [" : " [";
98
- const suffix = typeof options.showDefault === "object" ? options.showDefault.suffix ?? "]" : "]";
99
- const hasEmptyDefault = page.sections.some((s) => s.entries.some((e) => e.default != null && Array.isArray(e.default) && e.default.length === 0));
100
- minDescWidth = Math.max(minDescWidth, hasEmptyDefault ? prefix.length + suffix.length : prefix.length);
98
+ minDescWidth = Math.max(minDescWidth, prefix.length);
101
99
  }
102
- if (options.showChoices && page.sections.some((s) => s.entries.some((e) => e.choices != null))) {
100
+ if (options.showChoices && page.sections.some((s) => s.entries.some((e) => hasContent(e.choices)))) {
103
101
  const prefix = typeof options.showChoices === "object" ? options.showChoices.prefix ?? " (" : " (";
104
- const suffix = typeof options.showChoices === "object" ? options.showChoices.suffix ?? ")" : ")";
105
102
  const label = typeof options.showChoices === "object" ? options.showChoices.label ?? "choices: " : "choices: ";
106
- const hasEmptyChoices = page.sections.some((s) => s.entries.some((e) => e.choices != null && Array.isArray(e.choices) && e.choices.length === 0));
107
- minDescWidth = Math.max(minDescWidth, hasEmptyChoices ? prefix.length + label.length + suffix.length : prefix.length + label.length);
103
+ minDescWidth = Math.max(minDescWidth, prefix.length + label.length);
108
104
  }
109
105
  }
110
106
  const splitEntryMin = termIndent + 2 + Math.max(2, 2 * minDescWidth - 1);
@@ -196,7 +192,7 @@ function formatDocPage(programName, page, options = {}) {
196
192
  startWidth: extraTermOffset > 0 ? extraTermOffset : void 0
197
193
  };
198
194
  let description = entry.description == null ? "" : require_message.formatMessage(entry.description, descFormatOptions);
199
- if (options.showDefault && entry.default != null) {
195
+ if (options.showDefault && hasContent(entry.default)) {
200
196
  const prefix = typeof options.showDefault === "object" ? options.showDefault.prefix ?? " [" : " [";
201
197
  const suffix = typeof options.showDefault === "object" ? options.showDefault.suffix ?? "]" : "]";
202
198
  let defaultStartWidth;
@@ -219,7 +215,7 @@ function formatDocPage(programName, page, options = {}) {
219
215
  const formattedDefault = options.colors ? `\x1b[2m${defaultText}\x1b[0m` : defaultText;
220
216
  description += formattedDefault;
221
217
  }
222
- if (options.showChoices && entry.choices != null) {
218
+ if (options.showChoices && hasContent(entry.choices)) {
223
219
  const prefix = typeof options.showChoices === "object" ? options.showChoices.prefix ?? " (" : " (";
224
220
  const suffix = typeof options.showChoices === "object" ? options.showChoices.suffix ?? ")" : ")";
225
221
  const label = typeof options.showChoices === "object" ? options.showChoices.label ?? "choices: " : "choices: ";
package/dist/doc.js CHANGED
@@ -87,24 +87,20 @@ function formatDocPage(programName, page, options = {}) {
87
87
  ...page,
88
88
  sections: filteredSections
89
89
  };
90
+ const hasContent = (msg) => Array.isArray(msg) && msg.length > 0;
90
91
  if (options.maxWidth != null) {
91
92
  const hasEntries = page.sections.some((s) => s.entries.length > 0);
92
- const hasContent = (msg) => Array.isArray(msg) && msg.length > 0;
93
- const needsDescColumn = hasEntries && page.sections.some((s) => s.entries.some((e) => hasContent(e.description) || options.showDefault && e.default != null || options.showChoices && e.choices != null));
93
+ const needsDescColumn = hasEntries && page.sections.some((s) => s.entries.some((e) => hasContent(e.description) || options.showDefault && hasContent(e.default) || options.showChoices && hasContent(e.choices)));
94
94
  let minDescWidth = 1;
95
95
  if (needsDescColumn) {
96
- if (options.showDefault && page.sections.some((s) => s.entries.some((e) => e.default != null))) {
96
+ if (options.showDefault && page.sections.some((s) => s.entries.some((e) => hasContent(e.default)))) {
97
97
  const prefix = typeof options.showDefault === "object" ? options.showDefault.prefix ?? " [" : " [";
98
- const suffix = typeof options.showDefault === "object" ? options.showDefault.suffix ?? "]" : "]";
99
- const hasEmptyDefault = page.sections.some((s) => s.entries.some((e) => e.default != null && Array.isArray(e.default) && e.default.length === 0));
100
- minDescWidth = Math.max(minDescWidth, hasEmptyDefault ? prefix.length + suffix.length : prefix.length);
98
+ minDescWidth = Math.max(minDescWidth, prefix.length);
101
99
  }
102
- if (options.showChoices && page.sections.some((s) => s.entries.some((e) => e.choices != null))) {
100
+ if (options.showChoices && page.sections.some((s) => s.entries.some((e) => hasContent(e.choices)))) {
103
101
  const prefix = typeof options.showChoices === "object" ? options.showChoices.prefix ?? " (" : " (";
104
- const suffix = typeof options.showChoices === "object" ? options.showChoices.suffix ?? ")" : ")";
105
102
  const label = typeof options.showChoices === "object" ? options.showChoices.label ?? "choices: " : "choices: ";
106
- const hasEmptyChoices = page.sections.some((s) => s.entries.some((e) => e.choices != null && Array.isArray(e.choices) && e.choices.length === 0));
107
- minDescWidth = Math.max(minDescWidth, hasEmptyChoices ? prefix.length + label.length + suffix.length : prefix.length + label.length);
103
+ minDescWidth = Math.max(minDescWidth, prefix.length + label.length);
108
104
  }
109
105
  }
110
106
  const splitEntryMin = termIndent + 2 + Math.max(2, 2 * minDescWidth - 1);
@@ -196,7 +192,7 @@ function formatDocPage(programName, page, options = {}) {
196
192
  startWidth: extraTermOffset > 0 ? extraTermOffset : void 0
197
193
  };
198
194
  let description = entry.description == null ? "" : formatMessage(entry.description, descFormatOptions);
199
- if (options.showDefault && entry.default != null) {
195
+ if (options.showDefault && hasContent(entry.default)) {
200
196
  const prefix = typeof options.showDefault === "object" ? options.showDefault.prefix ?? " [" : " [";
201
197
  const suffix = typeof options.showDefault === "object" ? options.showDefault.suffix ?? "]" : "]";
202
198
  let defaultStartWidth;
@@ -219,7 +215,7 @@ function formatDocPage(programName, page, options = {}) {
219
215
  const formattedDefault = options.colors ? `\x1b[2m${defaultText}\x1b[0m` : defaultText;
220
216
  description += formattedDefault;
221
217
  }
222
- if (options.showChoices && entry.choices != null) {
218
+ if (options.showChoices && hasContent(entry.choices)) {
223
219
  const prefix = typeof options.showChoices === "object" ? options.showChoices.prefix ?? " (" : " (";
224
220
  const suffix = typeof options.showChoices === "object" ? options.showChoices.suffix ?? ")" : ")";
225
221
  const label = typeof options.showChoices === "object" ? options.showChoices.label ?? "choices: " : "choices: ";
@@ -201,7 +201,11 @@ function getSuggestionKey(suggestion) {
201
201
  * - Literal suggestions: same text
202
202
  * - File suggestions: same type, extensions, and pattern
203
203
  *
204
- * The first occurrence of each unique suggestion is kept.
204
+ * The first occurrence of each unique suggestion is kept. For file
205
+ * suggestions, `includeHidden` is merged across duplicates: if any
206
+ * duplicate has `includeHidden: true`, the kept suggestion is upgraded
207
+ * to `includeHidden: true` because it is a superset of the non-hidden
208
+ * variant.
205
209
  *
206
210
  * @param suggestions Array of suggestions that may contain duplicates
207
211
  * @returns A new array with duplicates removed, preserving order of first occurrences
@@ -220,13 +224,20 @@ function getSuggestionKey(suggestion) {
220
224
  * @since 0.9.0
221
225
  */
222
226
  function deduplicateSuggestions(suggestions) {
223
- const seen = /* @__PURE__ */ new Set();
224
- return suggestions.filter((suggestion) => {
227
+ const entries = /* @__PURE__ */ new Map();
228
+ const order = [];
229
+ for (const suggestion of suggestions) {
225
230
  const key = getSuggestionKey(suggestion);
226
- if (seen.has(key)) return false;
227
- seen.add(key);
228
- return true;
229
- });
231
+ const existing = entries.get(key);
232
+ if (existing == null) {
233
+ entries.set(key, suggestion);
234
+ order.push(key);
235
+ } else if (suggestion.kind === "file" && existing.kind === "file" && suggestion.includeHidden === true && existing.includeHidden !== true) entries.set(key, {
236
+ ...existing,
237
+ includeHidden: true
238
+ });
239
+ }
240
+ return order.map((key) => entries.get(key));
230
241
  }
231
242
 
232
243
  //#endregion
@@ -201,7 +201,11 @@ function getSuggestionKey(suggestion) {
201
201
  * - Literal suggestions: same text
202
202
  * - File suggestions: same type, extensions, and pattern
203
203
  *
204
- * The first occurrence of each unique suggestion is kept.
204
+ * The first occurrence of each unique suggestion is kept. For file
205
+ * suggestions, `includeHidden` is merged across duplicates: if any
206
+ * duplicate has `includeHidden: true`, the kept suggestion is upgraded
207
+ * to `includeHidden: true` because it is a superset of the non-hidden
208
+ * variant.
205
209
  *
206
210
  * @param suggestions Array of suggestions that may contain duplicates
207
211
  * @returns A new array with duplicates removed, preserving order of first occurrences
@@ -220,13 +224,20 @@ function getSuggestionKey(suggestion) {
220
224
  * @since 0.9.0
221
225
  */
222
226
  function deduplicateSuggestions(suggestions) {
223
- const seen = /* @__PURE__ */ new Set();
224
- return suggestions.filter((suggestion) => {
227
+ const entries = /* @__PURE__ */ new Map();
228
+ const order = [];
229
+ for (const suggestion of suggestions) {
225
230
  const key = getSuggestionKey(suggestion);
226
- if (seen.has(key)) return false;
227
- seen.add(key);
228
- return true;
229
- });
231
+ const existing = entries.get(key);
232
+ if (existing == null) {
233
+ entries.set(key, suggestion);
234
+ order.push(key);
235
+ } else if (suggestion.kind === "file" && existing.kind === "file" && suggestion.includeHidden === true && existing.includeHidden !== true) entries.set(key, {
236
+ ...existing,
237
+ includeHidden: true
238
+ });
239
+ }
240
+ return order.map((key) => entries.get(key));
230
241
  }
231
242
 
232
243
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.1300+12293782",
3
+ "version": "1.0.0-dev.1309+70f882d5",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",