@optique/core 0.6.9-dev.197 → 0.6.9

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/parser.cjs CHANGED
@@ -93,6 +93,26 @@ function suggest(parser, args) {
93
93
  return Array.from(parser.suggest(context, prefix));
94
94
  }
95
95
  /**
96
+ * Recursively searches for a command within nested exclusive usage terms.
97
+ * When the command is found, returns the expanded usage terms for that command.
98
+ *
99
+ * @param term The usage term to search in
100
+ * @param commandName The command name to find
101
+ * @returns The expanded usage terms if found, null otherwise
102
+ */
103
+ function findCommandInExclusive(term, commandName) {
104
+ if (term.type !== "exclusive") return null;
105
+ for (const termGroup of term.terms) {
106
+ const firstTerm = termGroup[0];
107
+ if (firstTerm?.type === "command" && firstTerm.name === commandName) return termGroup;
108
+ if (firstTerm?.type === "exclusive") {
109
+ const found = findCommandInExclusive(firstTerm, commandName);
110
+ if (found) return [...found, ...termGroup.slice(1)];
111
+ }
112
+ }
113
+ return null;
114
+ }
115
+ /**
96
116
  * Generates a documentation page for a parser based on its current state after
97
117
  * attempting to parse the provided arguments. This function is useful for
98
118
  * creating help documentation that reflects the current parsing context.
@@ -149,15 +169,14 @@ function getDocPage(parser, args = []) {
149
169
  }
150
170
  if (entries.length > 0) sections.push({ entries });
151
171
  const usage = [...require_usage.normalizeUsage(parser.usage)];
152
- for (const arg of args) for (let i = 0; i < usage.length; i++) {
172
+ let i = 0;
173
+ for (const arg of args) {
153
174
  const term = usage[i];
154
- if (term.type !== "exclusive") continue;
155
- for (const termGroup of term.terms) {
156
- const firstTerm = termGroup[0];
157
- if (firstTerm?.type !== "command" || firstTerm.name !== arg) continue;
158
- usage.splice(i, 1, ...termGroup);
159
- break;
175
+ if (usage.length > i && term.type === "exclusive") {
176
+ const found = findCommandInExclusive(term, arg);
177
+ if (found) usage.splice(i, 1, ...found);
160
178
  }
179
+ i++;
161
180
  }
162
181
  return {
163
182
  usage,
package/dist/parser.js CHANGED
@@ -93,6 +93,26 @@ function suggest(parser, args) {
93
93
  return Array.from(parser.suggest(context, prefix));
94
94
  }
95
95
  /**
96
+ * Recursively searches for a command within nested exclusive usage terms.
97
+ * When the command is found, returns the expanded usage terms for that command.
98
+ *
99
+ * @param term The usage term to search in
100
+ * @param commandName The command name to find
101
+ * @returns The expanded usage terms if found, null otherwise
102
+ */
103
+ function findCommandInExclusive(term, commandName) {
104
+ if (term.type !== "exclusive") return null;
105
+ for (const termGroup of term.terms) {
106
+ const firstTerm = termGroup[0];
107
+ if (firstTerm?.type === "command" && firstTerm.name === commandName) return termGroup;
108
+ if (firstTerm?.type === "exclusive") {
109
+ const found = findCommandInExclusive(firstTerm, commandName);
110
+ if (found) return [...found, ...termGroup.slice(1)];
111
+ }
112
+ }
113
+ return null;
114
+ }
115
+ /**
96
116
  * Generates a documentation page for a parser based on its current state after
97
117
  * attempting to parse the provided arguments. This function is useful for
98
118
  * creating help documentation that reflects the current parsing context.
@@ -149,15 +169,14 @@ function getDocPage(parser, args = []) {
149
169
  }
150
170
  if (entries.length > 0) sections.push({ entries });
151
171
  const usage = [...normalizeUsage(parser.usage)];
152
- for (const arg of args) for (let i = 0; i < usage.length; i++) {
172
+ let i = 0;
173
+ for (const arg of args) {
153
174
  const term = usage[i];
154
- if (term.type !== "exclusive") continue;
155
- for (const termGroup of term.terms) {
156
- const firstTerm = termGroup[0];
157
- if (firstTerm?.type !== "command" || firstTerm.name !== arg) continue;
158
- usage.splice(i, 1, ...termGroup);
159
- break;
175
+ if (usage.length > i && term.type === "exclusive") {
176
+ const found = findCommandInExclusive(term, arg);
177
+ if (found) usage.splice(i, 1, ...found);
160
178
  }
179
+ i++;
161
180
  }
162
181
  return {
163
182
  usage,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "0.6.9-dev.197+945d8f0c",
3
+ "version": "0.6.9",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",