@optique/core 0.6.7 → 0.6.9-dev.197

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.
@@ -647,8 +647,16 @@ function merge(...args) {
647
647
  });
648
648
  },
649
649
  getDocFragments(state, _defaultValue) {
650
- const fragments = parsers.flatMap((p) => {
651
- const parserState = p.initialState === void 0 ? { kind: "unavailable" } : state.kind === "unavailable" ? { kind: "unavailable" } : {
650
+ const fragments = parsers.flatMap((p, i) => {
651
+ let parserState;
652
+ if (p.initialState === void 0) {
653
+ const key = `__parser_${i}`;
654
+ if (state.kind === "available" && state.state && typeof state.state === "object" && key in state.state) parserState = {
655
+ kind: "available",
656
+ state: state.state[key]
657
+ };
658
+ else parserState = { kind: "unavailable" };
659
+ } else parserState = state.kind === "unavailable" ? { kind: "unavailable" } : {
652
660
  kind: "available",
653
661
  state: state.state
654
662
  };
@@ -647,8 +647,16 @@ function merge(...args) {
647
647
  });
648
648
  },
649
649
  getDocFragments(state, _defaultValue) {
650
- const fragments = parsers.flatMap((p) => {
651
- const parserState = p.initialState === void 0 ? { kind: "unavailable" } : state.kind === "unavailable" ? { kind: "unavailable" } : {
650
+ const fragments = parsers.flatMap((p, i) => {
651
+ let parserState;
652
+ if (p.initialState === void 0) {
653
+ const key = `__parser_${i}`;
654
+ if (state.kind === "available" && state.state && typeof state.state === "object" && key in state.state) parserState = {
655
+ kind: "available",
656
+ state: state.state[key]
657
+ };
658
+ else parserState = { kind: "unavailable" };
659
+ } else parserState = state.kind === "unavailable" ? { kind: "unavailable" } : {
652
660
  kind: "available",
653
661
  state: state.state
654
662
  };
package/dist/facade.cjs CHANGED
@@ -13,7 +13,7 @@ const require_parser = require('./parser.cjs');
13
13
  * Creates help parsers based on the specified mode.
14
14
  */
15
15
  function createHelpParser(mode) {
16
- const helpCommand = require_primitives.command("help", require_modifiers.multiple(require_primitives.argument(require_valueparser.string({ metavar: "COMMAND" }))), { description: require_message.message`Show help information.` });
16
+ const helpCommand = require_primitives.command("help", require_modifiers.multiple(require_primitives.argument(require_valueparser.string({ metavar: "COMMAND" }), { description: require_message.message`Command name to show help for.` })), { description: require_message.message`Show help information.` });
17
17
  const helpOption = require_primitives.flag("--help", { description: require_message.message`Show help information.` });
18
18
  switch (mode) {
19
19
  case "command": return {
@@ -84,14 +84,14 @@ function createCompletionParser(mode, programName, availableShells) {
84
84
  completionCommand: null,
85
85
  completionOption: require_constructs.object({
86
86
  shell: completionOption,
87
- args: require_modifiers.withDefault(require_modifiers.multiple(require_primitives.argument(require_valueparser.string({ metavar: "ARG" }))), [])
87
+ args: require_modifiers.withDefault(require_modifiers.multiple(require_primitives.argument(require_valueparser.string({ metavar: "ARG" }), { description: require_message.message`Command line arguments for completion suggestions (used by shell integration; you usually don't need to provide this).` })), [])
88
88
  })
89
89
  };
90
90
  case "both": return {
91
91
  completionCommand,
92
92
  completionOption: require_constructs.object({
93
93
  shell: completionOption,
94
- args: require_modifiers.withDefault(require_modifiers.multiple(require_primitives.argument(require_valueparser.string({ metavar: "ARG" }))), [])
94
+ args: require_modifiers.withDefault(require_modifiers.multiple(require_primitives.argument(require_valueparser.string({ metavar: "ARG" }), { description: require_message.message`Command line arguments for completion suggestions (used by shell integration; you usually don't need to provide this).` })), [])
95
95
  })
96
96
  };
97
97
  }
package/dist/facade.js CHANGED
@@ -13,7 +13,7 @@ import { getDocPage, parse, suggest } from "./parser.js";
13
13
  * Creates help parsers based on the specified mode.
14
14
  */
15
15
  function createHelpParser(mode) {
16
- const helpCommand = command("help", multiple(argument(string({ metavar: "COMMAND" }))), { description: message`Show help information.` });
16
+ const helpCommand = command("help", multiple(argument(string({ metavar: "COMMAND" }), { description: message`Command name to show help for.` })), { description: message`Show help information.` });
17
17
  const helpOption = flag("--help", { description: message`Show help information.` });
18
18
  switch (mode) {
19
19
  case "command": return {
@@ -84,14 +84,14 @@ function createCompletionParser(mode, programName, availableShells) {
84
84
  completionCommand: null,
85
85
  completionOption: object({
86
86
  shell: completionOption,
87
- args: withDefault(multiple(argument(string({ metavar: "ARG" }))), [])
87
+ args: withDefault(multiple(argument(string({ metavar: "ARG" }), { description: message`Command line arguments for completion suggestions (used by shell integration; you usually don't need to provide this).` })), [])
88
88
  })
89
89
  };
90
90
  case "both": return {
91
91
  completionCommand,
92
92
  completionOption: object({
93
93
  shell: completionOption,
94
- args: withDefault(multiple(argument(string({ metavar: "ARG" }))), [])
94
+ args: withDefault(multiple(argument(string({ metavar: "ARG" }), { description: message`Command line arguments for completion suggestions (used by shell integration; you usually don't need to provide this).` })), [])
95
95
  })
96
96
  };
97
97
  }
package/dist/parser.cjs CHANGED
@@ -149,16 +149,15 @@ function getDocPage(parser, args = []) {
149
149
  }
150
150
  if (entries.length > 0) sections.push({ entries });
151
151
  const usage = [...require_usage.normalizeUsage(parser.usage)];
152
- let i = 0;
153
- for (const arg of args) {
152
+ for (const arg of args) for (let i = 0; i < usage.length; i++) {
154
153
  const term = usage[i];
155
- if (usage.length > i && term.type === "exclusive") for (const termGroup of term.terms) {
154
+ if (term.type !== "exclusive") continue;
155
+ for (const termGroup of term.terms) {
156
156
  const firstTerm = termGroup[0];
157
157
  if (firstTerm?.type !== "command" || firstTerm.name !== arg) continue;
158
158
  usage.splice(i, 1, ...termGroup);
159
159
  break;
160
160
  }
161
- i++;
162
161
  }
163
162
  return {
164
163
  usage,
package/dist/parser.js CHANGED
@@ -149,16 +149,15 @@ function getDocPage(parser, args = []) {
149
149
  }
150
150
  if (entries.length > 0) sections.push({ entries });
151
151
  const usage = [...normalizeUsage(parser.usage)];
152
- let i = 0;
153
- for (const arg of args) {
152
+ for (const arg of args) for (let i = 0; i < usage.length; i++) {
154
153
  const term = usage[i];
155
- if (usage.length > i && term.type === "exclusive") for (const termGroup of term.terms) {
154
+ if (term.type !== "exclusive") continue;
155
+ for (const termGroup of term.terms) {
156
156
  const firstTerm = termGroup[0];
157
157
  if (firstTerm?.type !== "command" || firstTerm.name !== arg) continue;
158
158
  usage.splice(i, 1, ...termGroup);
159
159
  break;
160
160
  }
161
- i++;
162
161
  }
163
162
  return {
164
163
  usage,
@@ -666,7 +666,10 @@ function command(name, parser, options = {}) {
666
666
  const innerState = state.state[0] === "parsing" ? {
667
667
  kind: "available",
668
668
  state: state.state[1]
669
- } : { kind: "unavailable" };
669
+ } : {
670
+ kind: "available",
671
+ state: parser.initialState
672
+ };
670
673
  const innerFragments = parser.getDocFragments(innerState, defaultValue);
671
674
  return {
672
675
  ...innerFragments,
@@ -666,7 +666,10 @@ function command(name, parser, options = {}) {
666
666
  const innerState = state.state[0] === "parsing" ? {
667
667
  kind: "available",
668
668
  state: state.state[1]
669
- } : { kind: "unavailable" };
669
+ } : {
670
+ kind: "available",
671
+ state: parser.initialState
672
+ };
670
673
  const innerFragments = parser.getDocFragments(innerState, defaultValue);
671
674
  return {
672
675
  ...innerFragments,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "0.6.7",
3
+ "version": "0.6.9-dev.197+945d8f0c",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",