@optique/core 1.0.0-dev.483 → 1.0.0-dev.488

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
@@ -27,9 +27,10 @@ function scoreSection(section) {
27
27
  /**
28
28
  * The default section comparator: command-only sections come first, then
29
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
32
- * same score preserve their original relative order (stable sort).
30
+ * receive a score bonus of -1 via {@link scoreSection} so that untitled
31
+ * command-only sections naturally sort before titled command-only sections.
32
+ * Sections with the same score preserve their original relative order
33
+ * (stable sort).
33
34
  */
34
35
  function defaultSectionOrder(a, b) {
35
36
  return scoreSection(a) - scoreSection(b);
@@ -103,8 +104,7 @@ function formatDocPage(programName, page, options = {}) {
103
104
  })).toSorted((a, b) => {
104
105
  const cmp = comparator(a.section, b.section);
105
106
  if (cmp !== 0) return cmp;
106
- const titleCmp = (a.section.title == null ? 0 : 1) - (b.section.title == null ? 0 : 1);
107
- return titleCmp !== 0 ? titleCmp : a.index - b.index;
107
+ return a.index - b.index;
108
108
  }).map(({ section }) => section);
109
109
  for (const section of sections) {
110
110
  if (section.entries.length < 1) continue;
package/dist/doc.js CHANGED
@@ -27,9 +27,10 @@ function scoreSection(section) {
27
27
  /**
28
28
  * The default section comparator: command-only sections come first, then
29
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
32
- * same score preserve their original relative order (stable sort).
30
+ * receive a score bonus of -1 via {@link scoreSection} so that untitled
31
+ * command-only sections naturally sort before titled command-only sections.
32
+ * Sections with the same score preserve their original relative order
33
+ * (stable sort).
33
34
  */
34
35
  function defaultSectionOrder(a, b) {
35
36
  return scoreSection(a) - scoreSection(b);
@@ -103,8 +104,7 @@ function formatDocPage(programName, page, options = {}) {
103
104
  })).toSorted((a, b) => {
104
105
  const cmp = comparator(a.section, b.section);
105
106
  if (cmp !== 0) return cmp;
106
- const titleCmp = (a.section.title == null ? 0 : 1) - (b.section.title == null ? 0 : 1);
107
- return titleCmp !== 0 ? titleCmp : a.index - b.index;
107
+ return a.index - b.index;
108
108
  }).map(({ section }) => section);
109
109
  for (const section of sections) {
110
110
  if (section.entries.length < 1) continue;
@@ -495,7 +495,6 @@ function multiple(parser, options = {}) {
495
495
  });
496
496
  },
497
497
  suggest(context, prefix) {
498
- const innerState = context.state.length > 0 ? context.state.at(-1) : parser.initialState;
499
498
  const selectedValues = /* @__PURE__ */ new Set();
500
499
  for (const s of context.state) {
501
500
  const completed = syncParser.complete(s);
@@ -511,12 +510,12 @@ function multiple(parser, options = {}) {
511
510
  return require_mode_dispatch.dispatchIterableByMode(parser.$mode, function* () {
512
511
  for (const s of syncParser.suggest({
513
512
  ...context,
514
- state: innerState
513
+ state: parser.initialState
515
514
  }, prefix)) if (shouldInclude(s)) yield s;
516
515
  }, async function* () {
517
516
  const suggestions = parser.suggest({
518
517
  ...context,
519
- state: innerState
518
+ state: parser.initialState
520
519
  }, prefix);
521
520
  for await (const s of suggestions) if (shouldInclude(s)) yield s;
522
521
  });
package/dist/modifiers.js CHANGED
@@ -495,7 +495,6 @@ function multiple(parser, options = {}) {
495
495
  });
496
496
  },
497
497
  suggest(context, prefix) {
498
- const innerState = context.state.length > 0 ? context.state.at(-1) : parser.initialState;
499
498
  const selectedValues = /* @__PURE__ */ new Set();
500
499
  for (const s of context.state) {
501
500
  const completed = syncParser.complete(s);
@@ -511,12 +510,12 @@ function multiple(parser, options = {}) {
511
510
  return dispatchIterableByMode(parser.$mode, function* () {
512
511
  for (const s of syncParser.suggest({
513
512
  ...context,
514
- state: innerState
513
+ state: parser.initialState
515
514
  }, prefix)) if (shouldInclude(s)) yield s;
516
515
  }, async function* () {
517
516
  const suggestions = parser.suggest({
518
517
  ...context,
519
- state: innerState
518
+ state: parser.initialState
520
519
  }, prefix);
521
520
  for await (const s of suggestions) if (shouldInclude(s)) yield s;
522
521
  });
package/dist/parser.cjs CHANGED
@@ -387,14 +387,34 @@ function buildDocPage(parser, context, args) {
387
387
  kind: "available",
388
388
  state: context.state
389
389
  }, void 0);
390
- const entries = fragments.filter((f) => f.type === "entry");
391
- const sections = [];
392
- for (const fragment of fragments) {
393
- if (fragment.type !== "section") continue;
394
- if (fragment.title == null) entries.push(...fragment.entries);
395
- else sections.push(fragment);
390
+ const buildingSections = [];
391
+ let untitledSection = null;
392
+ const titledSectionMap = /* @__PURE__ */ new Map();
393
+ for (const fragment of fragments) if (fragment.type === "entry") {
394
+ if (untitledSection == null) {
395
+ untitledSection = { entries: [] };
396
+ buildingSections.push(untitledSection);
397
+ }
398
+ untitledSection.entries.push(fragment);
399
+ } else if (fragment.type === "section") if (fragment.title == null) {
400
+ if (untitledSection == null) {
401
+ untitledSection = { entries: [] };
402
+ buildingSections.push(untitledSection);
403
+ }
404
+ untitledSection.entries.push(...fragment.entries);
405
+ } else {
406
+ let section = titledSectionMap.get(fragment.title);
407
+ if (section == null) {
408
+ section = {
409
+ title: fragment.title,
410
+ entries: []
411
+ };
412
+ titledSectionMap.set(fragment.title, section);
413
+ buildingSections.push(section);
414
+ }
415
+ section.entries.push(...fragment.entries);
396
416
  }
397
- if (entries.length > 0) sections.push({ entries });
417
+ const sections = buildingSections;
398
418
  const usage = [...require_usage.normalizeUsage(parser.usage)];
399
419
  let i = 0;
400
420
  for (const arg of args) {
package/dist/parser.js CHANGED
@@ -387,14 +387,34 @@ function buildDocPage(parser, context, args) {
387
387
  kind: "available",
388
388
  state: context.state
389
389
  }, void 0);
390
- const entries = fragments.filter((f) => f.type === "entry");
391
- const sections = [];
392
- for (const fragment of fragments) {
393
- if (fragment.type !== "section") continue;
394
- if (fragment.title == null) entries.push(...fragment.entries);
395
- else sections.push(fragment);
390
+ const buildingSections = [];
391
+ let untitledSection = null;
392
+ const titledSectionMap = /* @__PURE__ */ new Map();
393
+ for (const fragment of fragments) if (fragment.type === "entry") {
394
+ if (untitledSection == null) {
395
+ untitledSection = { entries: [] };
396
+ buildingSections.push(untitledSection);
397
+ }
398
+ untitledSection.entries.push(fragment);
399
+ } else if (fragment.type === "section") if (fragment.title == null) {
400
+ if (untitledSection == null) {
401
+ untitledSection = { entries: [] };
402
+ buildingSections.push(untitledSection);
403
+ }
404
+ untitledSection.entries.push(...fragment.entries);
405
+ } else {
406
+ let section = titledSectionMap.get(fragment.title);
407
+ if (section == null) {
408
+ section = {
409
+ title: fragment.title,
410
+ entries: []
411
+ };
412
+ titledSectionMap.set(fragment.title, section);
413
+ buildingSections.push(section);
414
+ }
415
+ section.entries.push(...fragment.entries);
396
416
  }
397
- if (entries.length > 0) sections.push({ entries });
417
+ const sections = buildingSections;
398
418
  const usage = [...normalizeUsage(parser.usage)];
399
419
  let i = 0;
400
420
  for (const arg of args) {
@@ -1,5 +1,6 @@
1
1
  const require_message = require('./message.cjs');
2
2
  const require_dependency = require('./dependency.cjs');
3
+ const require_mode_dispatch = require('./mode-dispatch.cjs');
3
4
  const require_usage = require('./usage.cjs');
4
5
  const require_suggestion = require('./suggestion.cjs');
5
6
  const require_usage_internals = require('./usage-internals.cjs');
@@ -835,6 +836,7 @@ function argument(valueParser, options = {}) {
835
836
  };
836
837
  },
837
838
  suggest(context, prefix) {
839
+ if (context.state != null) return require_mode_dispatch.dispatchIterableByMode(valueParser.$mode, function* () {}, async function* () {});
838
840
  if (isAsync) return suggestArgumentAsync(valueParser, require_usage.isSuggestionHidden(options.hidden), prefix, context.dependencyRegistry);
839
841
  return suggestArgumentSync(valueParser, require_usage.isSuggestionHidden(options.hidden), prefix, context.dependencyRegistry);
840
842
  },
@@ -1,5 +1,6 @@
1
1
  import { message, metavar, optionName, optionNames, text, valueSet } from "./message.js";
2
2
  import { createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, dependencyId, getDefaultValuesFunction, getDependencyIds, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, suggestWithDependency } from "./dependency.js";
3
+ import { dispatchIterableByMode } from "./mode-dispatch.js";
3
4
  import { extractOptionNames, isDocHidden, isSuggestionHidden } from "./usage.js";
4
5
  import { DEFAULT_FIND_SIMILAR_OPTIONS, createErrorWithSuggestions, createSuggestionMessage, findSimilar } from "./suggestion.js";
5
6
  import { extractLeadingCommandNames } from "./usage-internals.js";
@@ -835,6 +836,7 @@ function argument(valueParser, options = {}) {
835
836
  };
836
837
  },
837
838
  suggest(context, prefix) {
839
+ if (context.state != null) return dispatchIterableByMode(valueParser.$mode, function* () {}, async function* () {});
838
840
  if (isAsync) return suggestArgumentAsync(valueParser, isSuggestionHidden(options.hidden), prefix, context.dependencyRegistry);
839
841
  return suggestArgumentSync(valueParser, isSuggestionHidden(options.hidden), prefix, context.dependencyRegistry);
840
842
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.483+8c78671b",
3
+ "version": "1.0.0-dev.488+690cf201",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",