@optique/core 0.7.14 → 0.7.16-dev.389

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.
@@ -1112,10 +1112,17 @@ function group(label, parser) {
1112
1112
  for (const fragment of fragments) if (fragment.type === "entry") allEntries.push(fragment);
1113
1113
  else if (fragment.type === "section") if (fragment.title) titledSections.push(fragment);
1114
1114
  else allEntries.push(...fragment.entries);
1115
- const labeledSection = {
1115
+ const initialFragments = parser.getDocFragments({
1116
+ kind: "available",
1117
+ state: parser.initialState
1118
+ }, void 0);
1119
+ const initialHasCommands = initialFragments.fragments.some((f) => f.type === "entry" && f.term.type === "command" || f.type === "section" && f.entries.some((e) => e.term.type === "command"));
1120
+ const currentHasCommands = allEntries.some((e) => e.term.type === "command");
1121
+ const applyLabel = !initialHasCommands || currentHasCommands;
1122
+ const labeledSection = applyLabel ? {
1116
1123
  title: label,
1117
1124
  entries: allEntries
1118
- };
1125
+ } : { entries: allEntries };
1119
1126
  return {
1120
1127
  description,
1121
1128
  fragments: [...titledSections.map((s) => ({
@@ -1112,10 +1112,17 @@ function group(label, parser) {
1112
1112
  for (const fragment of fragments) if (fragment.type === "entry") allEntries.push(fragment);
1113
1113
  else if (fragment.type === "section") if (fragment.title) titledSections.push(fragment);
1114
1114
  else allEntries.push(...fragment.entries);
1115
- const labeledSection = {
1115
+ const initialFragments = parser.getDocFragments({
1116
+ kind: "available",
1117
+ state: parser.initialState
1118
+ }, void 0);
1119
+ const initialHasCommands = initialFragments.fragments.some((f) => f.type === "entry" && f.term.type === "command" || f.type === "section" && f.entries.some((e) => e.term.type === "command"));
1120
+ const currentHasCommands = allEntries.some((e) => e.term.type === "command");
1121
+ const applyLabel = !initialHasCommands || currentHasCommands;
1122
+ const labeledSection = applyLabel ? {
1116
1123
  title: label,
1117
1124
  entries: allEntries
1118
- };
1125
+ } : { entries: allEntries };
1119
1126
  return {
1120
1127
  description,
1121
1128
  fragments: [...titledSections.map((s) => ({
package/dist/usage.cjs CHANGED
@@ -186,8 +186,10 @@ function normalizeUsageTerm(term) {
186
186
  const terms = [];
187
187
  for (const usage of term.terms) {
188
188
  const normalized = normalizeUsage(usage);
189
- if (normalized.length === 1 && normalized[0].type === "exclusive") for (const subUsage of normalized[0].terms) terms.push(subUsage);
190
- else terms.push(normalized);
189
+ if (normalized.length >= 1 && normalized[0].type === "exclusive") {
190
+ const rest = normalized.slice(1);
191
+ for (const subUsage of normalized[0].terms) terms.push([...subUsage, ...rest]);
192
+ } else terms.push(normalized);
191
193
  }
192
194
  return {
193
195
  type: "exclusive",
package/dist/usage.js CHANGED
@@ -185,8 +185,10 @@ function normalizeUsageTerm(term) {
185
185
  const terms = [];
186
186
  for (const usage of term.terms) {
187
187
  const normalized = normalizeUsage(usage);
188
- if (normalized.length === 1 && normalized[0].type === "exclusive") for (const subUsage of normalized[0].terms) terms.push(subUsage);
189
- else terms.push(normalized);
188
+ if (normalized.length >= 1 && normalized[0].type === "exclusive") {
189
+ const rest = normalized.slice(1);
190
+ for (const subUsage of normalized[0].terms) terms.push([...subUsage, ...rest]);
191
+ } else terms.push(normalized);
190
192
  }
191
193
  return {
192
194
  type: "exclusive",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "0.7.14",
3
+ "version": "0.7.16-dev.389+19027a10",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",