@optique/core 1.0.0-dev.387 → 1.0.0-dev.395

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.
@@ -1653,6 +1653,9 @@ function merge(...args) {
1653
1653
  }();
1654
1654
  },
1655
1655
  getDocFragments(state, _defaultValue) {
1656
+ let brief;
1657
+ let description;
1658
+ let footer;
1656
1659
  const fragments = parsers.flatMap((p, i) => {
1657
1660
  let parserState;
1658
1661
  if (p.initialState === void 0) {
@@ -1666,7 +1669,11 @@ function merge(...args) {
1666
1669
  kind: "available",
1667
1670
  state: state.state
1668
1671
  };
1669
- return p.getDocFragments(parserState, void 0).fragments;
1672
+ const docFragments = p.getDocFragments(parserState, void 0);
1673
+ brief ??= docFragments.brief;
1674
+ description ??= docFragments.description;
1675
+ footer ??= docFragments.footer;
1676
+ return docFragments.fragments;
1670
1677
  });
1671
1678
  const entries = fragments.filter((f) => f.type === "entry");
1672
1679
  const sections = [];
@@ -1681,18 +1688,28 @@ function merge(...args) {
1681
1688
  entries
1682
1689
  };
1683
1690
  sections.push(labeledSection);
1684
- return { fragments: sections.map((s) => ({
1691
+ return {
1692
+ brief,
1693
+ description,
1694
+ footer,
1695
+ fragments: sections.map((s) => ({
1696
+ ...s,
1697
+ type: "section"
1698
+ }))
1699
+ };
1700
+ }
1701
+ return {
1702
+ brief,
1703
+ description,
1704
+ footer,
1705
+ fragments: [...sections.map((s) => ({
1685
1706
  ...s,
1686
1707
  type: "section"
1687
- })) };
1688
- }
1689
- return { fragments: [...sections.map((s) => ({
1690
- ...s,
1691
- type: "section"
1692
- })), {
1693
- type: "section",
1694
- entries
1695
- }] };
1708
+ })), {
1709
+ type: "section",
1710
+ entries
1711
+ }]
1712
+ };
1696
1713
  }
1697
1714
  };
1698
1715
  }
@@ -1995,10 +2012,17 @@ function group(label, parser) {
1995
2012
  for (const fragment of fragments) if (fragment.type === "entry") allEntries.push(fragment);
1996
2013
  else if (fragment.type === "section") if (fragment.title) titledSections.push(fragment);
1997
2014
  else allEntries.push(...fragment.entries);
1998
- const labeledSection = {
2015
+ const initialFragments = parser.getDocFragments({
2016
+ kind: "available",
2017
+ state: parser.initialState
2018
+ }, void 0);
2019
+ const initialHasCommands = initialFragments.fragments.some((f) => f.type === "entry" && f.term.type === "command" || f.type === "section" && f.entries.some((e) => e.term.type === "command"));
2020
+ const currentHasCommands = allEntries.some((e) => e.term.type === "command");
2021
+ const applyLabel = !initialHasCommands || currentHasCommands;
2022
+ const labeledSection = applyLabel ? {
1999
2023
  title: label,
2000
2024
  entries: allEntries
2001
- };
2025
+ } : { entries: allEntries };
2002
2026
  return {
2003
2027
  description,
2004
2028
  fragments: [...titledSections.map((s) => ({
@@ -1653,6 +1653,9 @@ function merge(...args) {
1653
1653
  }();
1654
1654
  },
1655
1655
  getDocFragments(state, _defaultValue) {
1656
+ let brief;
1657
+ let description;
1658
+ let footer;
1656
1659
  const fragments = parsers.flatMap((p, i) => {
1657
1660
  let parserState;
1658
1661
  if (p.initialState === void 0) {
@@ -1666,7 +1669,11 @@ function merge(...args) {
1666
1669
  kind: "available",
1667
1670
  state: state.state
1668
1671
  };
1669
- return p.getDocFragments(parserState, void 0).fragments;
1672
+ const docFragments = p.getDocFragments(parserState, void 0);
1673
+ brief ??= docFragments.brief;
1674
+ description ??= docFragments.description;
1675
+ footer ??= docFragments.footer;
1676
+ return docFragments.fragments;
1670
1677
  });
1671
1678
  const entries = fragments.filter((f) => f.type === "entry");
1672
1679
  const sections = [];
@@ -1681,18 +1688,28 @@ function merge(...args) {
1681
1688
  entries
1682
1689
  };
1683
1690
  sections.push(labeledSection);
1684
- return { fragments: sections.map((s) => ({
1691
+ return {
1692
+ brief,
1693
+ description,
1694
+ footer,
1695
+ fragments: sections.map((s) => ({
1696
+ ...s,
1697
+ type: "section"
1698
+ }))
1699
+ };
1700
+ }
1701
+ return {
1702
+ brief,
1703
+ description,
1704
+ footer,
1705
+ fragments: [...sections.map((s) => ({
1685
1706
  ...s,
1686
1707
  type: "section"
1687
- })) };
1688
- }
1689
- return { fragments: [...sections.map((s) => ({
1690
- ...s,
1691
- type: "section"
1692
- })), {
1693
- type: "section",
1694
- entries
1695
- }] };
1708
+ })), {
1709
+ type: "section",
1710
+ entries
1711
+ }]
1712
+ };
1696
1713
  }
1697
1714
  };
1698
1715
  }
@@ -1995,10 +2012,17 @@ function group(label, parser) {
1995
2012
  for (const fragment of fragments) if (fragment.type === "entry") allEntries.push(fragment);
1996
2013
  else if (fragment.type === "section") if (fragment.title) titledSections.push(fragment);
1997
2014
  else allEntries.push(...fragment.entries);
1998
- const labeledSection = {
2015
+ const initialFragments = parser.getDocFragments({
2016
+ kind: "available",
2017
+ state: parser.initialState
2018
+ }, void 0);
2019
+ const initialHasCommands = initialFragments.fragments.some((f) => f.type === "entry" && f.term.type === "command" || f.type === "section" && f.entries.some((e) => e.term.type === "command"));
2020
+ const currentHasCommands = allEntries.some((e) => e.term.type === "command");
2021
+ const applyLabel = !initialHasCommands || currentHasCommands;
2022
+ const labeledSection = applyLabel ? {
1999
2023
  title: label,
2000
2024
  entries: allEntries
2001
- };
2025
+ } : { entries: allEntries };
2002
2026
  return {
2003
2027
  description,
2004
2028
  fragments: [...titledSections.map((s) => ({
package/dist/message.cjs CHANGED
@@ -257,7 +257,7 @@ function formatMessage(msg, options = {}) {
257
257
  const paragraphs = term.text.split(/\n\n+/);
258
258
  for (let paragraphIndex = 0; paragraphIndex < paragraphs.length; paragraphIndex++) {
259
259
  if (paragraphIndex > 0) yield {
260
- text: "\n",
260
+ text: "\n\n",
261
261
  width: -1
262
262
  };
263
263
  const paragraph = paragraphs[paragraphIndex].replace(/\n/g, " ");
package/dist/message.js CHANGED
@@ -256,7 +256,7 @@ function formatMessage(msg, options = {}) {
256
256
  const paragraphs = term.text.split(/\n\n+/);
257
257
  for (let paragraphIndex = 0; paragraphIndex < paragraphs.length; paragraphIndex++) {
258
258
  if (paragraphIndex > 0) yield {
259
- text: "\n",
259
+ text: "\n\n",
260
260
  width: -1
261
261
  };
262
262
  const paragraph = paragraphs[paragraphIndex].replace(/\n/g, " ");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.387+466f13e8",
3
+ "version": "1.0.0-dev.395+ace61d13",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",