@optique/core 0.8.13 → 0.8.14

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.
@@ -838,6 +838,9 @@ function merge(...args) {
838
838
  return require_suggestion.deduplicateSuggestions(suggestions);
839
839
  },
840
840
  getDocFragments(state, _defaultValue) {
841
+ let brief;
842
+ let description;
843
+ let footer;
841
844
  const fragments = parsers.flatMap((p, i) => {
842
845
  let parserState;
843
846
  if (p.initialState === void 0) {
@@ -851,7 +854,11 @@ function merge(...args) {
851
854
  kind: "available",
852
855
  state: state.state
853
856
  };
854
- return p.getDocFragments(parserState, void 0).fragments;
857
+ const docFragments = p.getDocFragments(parserState, void 0);
858
+ brief ??= docFragments.brief;
859
+ description ??= docFragments.description;
860
+ footer ??= docFragments.footer;
861
+ return docFragments.fragments;
855
862
  });
856
863
  const entries = fragments.filter((f) => f.type === "entry");
857
864
  const sections = [];
@@ -866,18 +873,28 @@ function merge(...args) {
866
873
  entries
867
874
  };
868
875
  sections.push(labeledSection);
869
- return { fragments: sections.map((s) => ({
876
+ return {
877
+ brief,
878
+ description,
879
+ footer,
880
+ fragments: sections.map((s) => ({
881
+ ...s,
882
+ type: "section"
883
+ }))
884
+ };
885
+ }
886
+ return {
887
+ brief,
888
+ description,
889
+ footer,
890
+ fragments: [...sections.map((s) => ({
870
891
  ...s,
871
892
  type: "section"
872
- })) };
873
- }
874
- return { fragments: [...sections.map((s) => ({
875
- ...s,
876
- type: "section"
877
- })), {
878
- type: "section",
879
- entries
880
- }] };
893
+ })), {
894
+ type: "section",
895
+ entries
896
+ }]
897
+ };
881
898
  }
882
899
  };
883
900
  }
@@ -1062,10 +1079,17 @@ function group(label, parser) {
1062
1079
  for (const fragment of fragments) if (fragment.type === "entry") allEntries.push(fragment);
1063
1080
  else if (fragment.type === "section") if (fragment.title) titledSections.push(fragment);
1064
1081
  else allEntries.push(...fragment.entries);
1065
- const labeledSection = {
1082
+ const initialFragments = parser.getDocFragments({
1083
+ kind: "available",
1084
+ state: parser.initialState
1085
+ }, void 0);
1086
+ const initialHasCommands = initialFragments.fragments.some((f) => f.type === "entry" && f.term.type === "command" || f.type === "section" && f.entries.some((e) => e.term.type === "command"));
1087
+ const currentHasCommands = allEntries.some((e) => e.term.type === "command");
1088
+ const applyLabel = !initialHasCommands || currentHasCommands;
1089
+ const labeledSection = applyLabel ? {
1066
1090
  title: label,
1067
1091
  entries: allEntries
1068
- };
1092
+ } : { entries: allEntries };
1069
1093
  return {
1070
1094
  description,
1071
1095
  fragments: [...titledSections.map((s) => ({
@@ -838,6 +838,9 @@ function merge(...args) {
838
838
  return deduplicateSuggestions(suggestions);
839
839
  },
840
840
  getDocFragments(state, _defaultValue) {
841
+ let brief;
842
+ let description;
843
+ let footer;
841
844
  const fragments = parsers.flatMap((p, i) => {
842
845
  let parserState;
843
846
  if (p.initialState === void 0) {
@@ -851,7 +854,11 @@ function merge(...args) {
851
854
  kind: "available",
852
855
  state: state.state
853
856
  };
854
- return p.getDocFragments(parserState, void 0).fragments;
857
+ const docFragments = p.getDocFragments(parserState, void 0);
858
+ brief ??= docFragments.brief;
859
+ description ??= docFragments.description;
860
+ footer ??= docFragments.footer;
861
+ return docFragments.fragments;
855
862
  });
856
863
  const entries = fragments.filter((f) => f.type === "entry");
857
864
  const sections = [];
@@ -866,18 +873,28 @@ function merge(...args) {
866
873
  entries
867
874
  };
868
875
  sections.push(labeledSection);
869
- return { fragments: sections.map((s) => ({
876
+ return {
877
+ brief,
878
+ description,
879
+ footer,
880
+ fragments: sections.map((s) => ({
881
+ ...s,
882
+ type: "section"
883
+ }))
884
+ };
885
+ }
886
+ return {
887
+ brief,
888
+ description,
889
+ footer,
890
+ fragments: [...sections.map((s) => ({
870
891
  ...s,
871
892
  type: "section"
872
- })) };
873
- }
874
- return { fragments: [...sections.map((s) => ({
875
- ...s,
876
- type: "section"
877
- })), {
878
- type: "section",
879
- entries
880
- }] };
893
+ })), {
894
+ type: "section",
895
+ entries
896
+ }]
897
+ };
881
898
  }
882
899
  };
883
900
  }
@@ -1062,10 +1079,17 @@ function group(label, parser) {
1062
1079
  for (const fragment of fragments) if (fragment.type === "entry") allEntries.push(fragment);
1063
1080
  else if (fragment.type === "section") if (fragment.title) titledSections.push(fragment);
1064
1081
  else allEntries.push(...fragment.entries);
1065
- const labeledSection = {
1082
+ const initialFragments = parser.getDocFragments({
1083
+ kind: "available",
1084
+ state: parser.initialState
1085
+ }, void 0);
1086
+ const initialHasCommands = initialFragments.fragments.some((f) => f.type === "entry" && f.term.type === "command" || f.type === "section" && f.entries.some((e) => e.term.type === "command"));
1087
+ const currentHasCommands = allEntries.some((e) => e.term.type === "command");
1088
+ const applyLabel = !initialHasCommands || currentHasCommands;
1089
+ const labeledSection = applyLabel ? {
1066
1090
  title: label,
1067
1091
  entries: allEntries
1068
- };
1092
+ } : { entries: allEntries };
1069
1093
  return {
1070
1094
  description,
1071
1095
  fragments: [...titledSections.map((s) => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "0.8.13",
3
+ "version": "0.8.14",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",