@kjanat/dreamcli 4.0.0-rc.3 → 4.0.0

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.
Files changed (212) hide show
  1. package/README.md +5 -7
  2. package/dist/{runtime/adapter.d.mts → adapter-D0hbBNVB.d.mts} +2 -4
  3. package/dist/completion-D4mz6axB.mjs +6 -0
  4. package/dist/completion.d.mts +90 -0
  5. package/dist/completion.mjs +1 -0
  6. package/dist/config-B9ddC-Kb.mjs +1 -0
  7. package/dist/config.d.mts +2 -0
  8. package/dist/config.mjs +1 -0
  9. package/dist/core-Cp2w8vRq.mjs +17 -0
  10. package/dist/index-BziI2aKc.d.mts +5440 -0
  11. package/dist/index-DOfClfYR.d.mts +370 -0
  12. package/dist/index-DWsnGZlx.d.mts +831 -0
  13. package/dist/{core/cli/index.d.mts → index-DXROeDPC.d.mts} +116 -57
  14. package/dist/index-DndPmT8J.d.mts +275 -0
  15. package/dist/{core/json-schema/index.d.mts → index-DyoaS234.d.mts} +43 -34
  16. package/dist/index.d.mts +190 -41
  17. package/dist/index.mjs +1 -26
  18. package/dist/json-schema-C9SzZ7jY.mjs +52 -0
  19. package/dist/json-schema.d.mts +2 -0
  20. package/dist/json-schema.mjs +1 -0
  21. package/dist/package-json-BgE9YjjQ.mjs +3 -0
  22. package/dist/prompt.d.mts +48 -0
  23. package/dist/prompt.mjs +1 -0
  24. package/dist/rolldown-runtime-G4Kt5YOX.mjs +1 -0
  25. package/dist/runtime.d.mts +2 -6
  26. package/dist/runtime.mjs +1 -6
  27. package/dist/terminal-C8KTXjv5.mjs +6 -0
  28. package/dist/test-prompter-v__jT2yG.mjs +1 -0
  29. package/dist/testkit.d.mts +54 -6
  30. package/dist/testkit.mjs +1 -5
  31. package/dist/version.mjs +1 -7
  32. package/dreamcli.schema.json +697 -538
  33. package/package.json +29 -7
  34. package/skills/cli-creation/SKILL.md +16 -11
  35. package/CHANGELOG.md +0 -1116
  36. package/dist/core/cli/builtins.d.mts +0 -117
  37. package/dist/core/cli/builtins.mjs +0 -135
  38. package/dist/core/cli/compiled.d.mts +0 -66
  39. package/dist/core/cli/compiled.mjs +0 -76
  40. package/dist/core/cli/dispatch.d.mts +0 -115
  41. package/dist/core/cli/dispatch.mjs +0 -205
  42. package/dist/core/cli/help-links.d.mts +0 -27
  43. package/dist/core/cli/help-links.mjs +0 -41
  44. package/dist/core/cli/index.mjs +0 -1271
  45. package/dist/core/cli/planner.d.mts +0 -174
  46. package/dist/core/cli/planner.mjs +0 -323
  47. package/dist/core/cli/plugin.d.mts +0 -94
  48. package/dist/core/cli/plugin.mjs +0 -41
  49. package/dist/core/cli/propagate.d.mts +0 -39
  50. package/dist/core/cli/propagate.mjs +0 -57
  51. package/dist/core/cli/reserved-flags.d.mts +0 -19
  52. package/dist/core/cli/reserved-flags.mjs +0 -158
  53. package/dist/core/cli/root-help.d.mts +0 -53
  54. package/dist/core/cli/root-help.mjs +0 -221
  55. package/dist/core/cli/root-output-flags.d.mts +0 -74
  56. package/dist/core/cli/root-output-flags.mjs +0 -169
  57. package/dist/core/cli/root-surface.d.mts +0 -64
  58. package/dist/core/cli/root-surface.mjs +0 -28
  59. package/dist/core/cli/runtime-preflight.d.mts +0 -213
  60. package/dist/core/cli/runtime-preflight.mjs +0 -221
  61. package/dist/core/completion/index.d.mts +0 -76
  62. package/dist/core/completion/index.mjs +0 -90
  63. package/dist/core/completion/shells/bash.d.mts +0 -23
  64. package/dist/core/completion/shells/bash.mjs +0 -312
  65. package/dist/core/completion/shells/fish.d.mts +0 -19
  66. package/dist/core/completion/shells/fish.mjs +0 -164
  67. package/dist/core/completion/shells/powershell.d.mts +0 -13
  68. package/dist/core/completion/shells/powershell.mjs +0 -360
  69. package/dist/core/completion/shells/shared.d.mts +0 -164
  70. package/dist/core/completion/shells/shared.mjs +0 -147
  71. package/dist/core/completion/shells/zsh.d.mts +0 -23
  72. package/dist/core/completion/shells/zsh.mjs +0 -256
  73. package/dist/core/config/index.d.mts +0 -191
  74. package/dist/core/config/index.mjs +0 -285
  75. package/dist/core/config/package-json.d.mts +0 -179
  76. package/dist/core/config/package-json.mjs +0 -353
  77. package/dist/core/errors/index.d.mts +0 -125
  78. package/dist/core/errors/index.mjs +0 -87
  79. package/dist/core/execution/index.d.mts +0 -61
  80. package/dist/core/execution/index.mjs +0 -220
  81. package/dist/core/help/ansi.d.mts +0 -84
  82. package/dist/core/help/ansi.mjs +0 -121
  83. package/dist/core/help/index.d.mts +0 -149
  84. package/dist/core/help/index.mjs +0 -418
  85. package/dist/core/help/theme.d.mts +0 -86
  86. package/dist/core/help/theme.mjs +0 -69
  87. package/dist/core/json-schema/index.mjs +0 -1008
  88. package/dist/core/json-schema/meta-descriptions.generated.d.mts +0 -274
  89. package/dist/core/json-schema/meta-descriptions.generated.mjs +0 -136
  90. package/dist/core/output/activity.d.mts +0 -193
  91. package/dist/core/output/activity.mjs +0 -452
  92. package/dist/core/output/bind.d.mts +0 -37
  93. package/dist/core/output/bind.mjs +0 -56
  94. package/dist/core/output/contracts.d.mts +0 -82
  95. package/dist/core/output/contracts.mjs +0 -57
  96. package/dist/core/output/display-value.d.mts +0 -19
  97. package/dist/core/output/display-value.mjs +0 -32
  98. package/dist/core/output/index.d.mts +0 -344
  99. package/dist/core/output/index.mjs +0 -514
  100. package/dist/core/output/renderers.d.mts +0 -45
  101. package/dist/core/output/renderers.mjs +0 -46
  102. package/dist/core/output/writer.d.mts +0 -39
  103. package/dist/core/output/writer.mjs +0 -12
  104. package/dist/core/parse/index.d.mts +0 -178
  105. package/dist/core/parse/index.mjs +0 -850
  106. package/dist/core/parse/occurrences.d.mts +0 -90
  107. package/dist/core/parse/occurrences.mjs +0 -114
  108. package/dist/core/prompt/index.d.mts +0 -213
  109. package/dist/core/prompt/index.mjs +0 -348
  110. package/dist/core/read-flags/index.d.mts +0 -150
  111. package/dist/core/read-flags/index.mjs +0 -217
  112. package/dist/core/resolve/args.d.mts +0 -39
  113. package/dist/core/resolve/args.mjs +0 -182
  114. package/dist/core/resolve/coerce.d.mts +0 -79
  115. package/dist/core/resolve/coerce.mjs +0 -900
  116. package/dist/core/resolve/config.d.mts +0 -10
  117. package/dist/core/resolve/config.mjs +0 -19
  118. package/dist/core/resolve/contracts.d.mts +0 -146
  119. package/dist/core/resolve/errors.d.mts +0 -10
  120. package/dist/core/resolve/errors.mjs +0 -148
  121. package/dist/core/resolve/flags.d.mts +0 -74
  122. package/dist/core/resolve/flags.mjs +0 -246
  123. package/dist/core/resolve/index.d.mts +0 -44
  124. package/dist/core/resolve/index.mjs +0 -123
  125. package/dist/core/resolve/path-checks.d.mts +0 -48
  126. package/dist/core/resolve/path-checks.mjs +0 -102
  127. package/dist/core/resolve/redaction.d.mts +0 -13
  128. package/dist/core/resolve/redaction.mjs +0 -14
  129. package/dist/core/resolve/stages.d.mts +0 -86
  130. package/dist/core/resolve/stages.mjs +0 -170
  131. package/dist/core/resolve/standard.d.mts +0 -26
  132. package/dist/core/resolve/standard.mjs +0 -212
  133. package/dist/core/schema/activity.d.mts +0 -189
  134. package/dist/core/schema/arg.d.mts +0 -1461
  135. package/dist/core/schema/arg.mjs +0 -1139
  136. package/dist/core/schema/brand.d.mts +0 -17
  137. package/dist/core/schema/cardinality.d.mts +0 -302
  138. package/dist/core/schema/cardinality.mjs +0 -514
  139. package/dist/core/schema/command.d.mts +0 -1132
  140. package/dist/core/schema/command.mjs +0 -999
  141. package/dist/core/schema/flag.d.mts +0 -1495
  142. package/dist/core/schema/flag.mjs +0 -1207
  143. package/dist/core/schema/index.d.mts +0 -15
  144. package/dist/core/schema/index.mjs +0 -10
  145. package/dist/core/schema/middleware.d.mts +0 -129
  146. package/dist/core/schema/middleware.mjs +0 -41
  147. package/dist/core/schema/number-constraints.d.mts +0 -96
  148. package/dist/core/schema/number-constraints.mjs +0 -60
  149. package/dist/core/schema/prompt.d.mts +0 -135
  150. package/dist/core/schema/provenance.d.mts +0 -99
  151. package/dist/core/schema/provenance.mjs +0 -28
  152. package/dist/core/schema/run.d.mts +0 -211
  153. package/dist/core/schema/source.d.mts +0 -180
  154. package/dist/core/schema/source.mjs +0 -206
  155. package/dist/core/schema/standard.d.mts +0 -100
  156. package/dist/core/schema/standard.mjs +0 -15
  157. package/dist/core/schema/stdin.d.mts +0 -97
  158. package/dist/core/schema/stdin.mjs +0 -91
  159. package/dist/core/schema/string-constraints.d.mts +0 -108
  160. package/dist/core/schema/string-constraints.mjs +0 -86
  161. package/dist/core/schema/value-parsers.d.mts +0 -150
  162. package/dist/core/schema/value-parsers.mjs +0 -160
  163. package/dist/core/schema/value.d.mts +0 -243
  164. package/dist/core/schema/value.mjs +0 -573
  165. package/dist/core/testkit/index.d.mts +0 -63
  166. package/dist/core/testkit/index.mjs +0 -102
  167. package/dist/runtime/adapter.mjs +0 -92
  168. package/dist/runtime/auto.d.mts +0 -25
  169. package/dist/runtime/auto.mjs +0 -45
  170. package/dist/runtime/deno.d.mts +0 -99
  171. package/dist/runtime/deno.mjs +0 -265
  172. package/dist/runtime/detect.d.mts +0 -86
  173. package/dist/runtime/detect.mjs +0 -45
  174. package/dist/runtime/index.d.mts +0 -6
  175. package/dist/runtime/node.d.mts +0 -71
  176. package/dist/runtime/node.mjs +0 -228
  177. package/dist/runtime/paths.d.mts +0 -31
  178. package/dist/runtime/paths.mjs +0 -48
  179. package/dist/strings.d.mts +0 -27
  180. package/dist/strings.mjs +0 -22
  181. package/examples/basic.ts +0 -37
  182. package/examples/flag-types.ts +0 -79
  183. package/examples/gh/package.json +0 -45
  184. package/examples/gh/src/commands/auth.ts +0 -66
  185. package/examples/gh/src/commands/issue.ts +0 -120
  186. package/examples/gh/src/commands/pr.ts +0 -125
  187. package/examples/gh/src/data/issues.yaml +0 -5
  188. package/examples/gh/src/data/issues.yaml.d.ts +0 -17
  189. package/examples/gh/src/data/pull-requests.yaml +0 -7
  190. package/examples/gh/src/data/pull-requests.yaml.d.ts +0 -18
  191. package/examples/gh/src/docs.ts +0 -11
  192. package/examples/gh/src/lib/auth.ts +0 -37
  193. package/examples/gh/src/lib/utils.ts +0 -17
  194. package/examples/gh/src/main.test.ts +0 -307
  195. package/examples/gh/src/main.ts +0 -46
  196. package/examples/help-config.ts +0 -43
  197. package/examples/interactive.ts +0 -67
  198. package/examples/json-mode.ts +0 -95
  199. package/examples/middleware.ts +0 -71
  200. package/examples/multi-command.ts +0 -66
  201. package/examples/output-extras.ts +0 -46
  202. package/examples/parser-control.ts +0 -40
  203. package/examples/pwsh-demo/README.md +0 -40
  204. package/examples/pwsh-demo/package.json +0 -41
  205. package/examples/pwsh-demo/pwsh-demo.cmd +0 -3
  206. package/examples/pwsh-demo/smoke-powershell.ps1 +0 -218
  207. package/examples/pwsh-demo/src/main.test.ts +0 -45
  208. package/examples/pwsh-demo/src/main.ts +0 -140
  209. package/examples/spinner-progress.ts +0 -49
  210. package/examples/standard-schema.ts +0 -45
  211. package/examples/testing.ts +0 -147
  212. package/examples/transport-launcher.ts +0 -85
@@ -1,312 +0,0 @@
1
- import { getFlagAliasNames } from "../../schema/flag.mjs";
2
- import { flagExpectsValue } from "../../parse/index.mjs";
3
- import { getVisibleNegatedName, quoteShellArg, resolveRootCompletionSurface, sanitizeShellIdentifier, versionTag, walkCommandTree } from "./shared.mjs";
4
- //#region src/core/completion/shells/bash.ts
5
- /**
6
- * Generate a bash completion script for the CLI.
7
- *
8
- * Use this when you want a bash-specific script directly rather than routing
9
- * through {@link generateCompletion}. The generated script expects the
10
- * `bash-completion` package because it relies on `_init_completion`.
11
- *
12
- * @param schema - The CLI schema.
13
- * @param options - Optional generator configuration.
14
- * @returns A complete bash completion script.
15
- *
16
- * @example
17
- * ```ts
18
- * const script = generateBashCompletion(app.schema);
19
- * // install with: mycli completions bash > /etc/bash_completion.d/mycli
20
- * ```
21
- */
22
- function generateBashCompletion(schema, options) {
23
- const prefix = options?.functionPrefix ?? schema.name;
24
- const funcName = `_${sanitizeShellIdentifier(prefix)}_completions`;
25
- const rootSurface = resolveRootCompletionSurface(schema, options?.rootMode);
26
- const visibleCommands = rootSurface.visibleCommands;
27
- const nodes = walkCommandTree(visibleCommands);
28
- const maxDepth = nodes.reduce((max, n) => Math.max(max, n.path.length), 0);
29
- const lines = [];
30
- lines.push("#!/usr/bin/env bash");
31
- lines.push(`# Bash completion for ${schema.name}`);
32
- lines.push(`# Generated by ${versionTag()}`);
33
- lines.push("#");
34
- lines.push(`# Usage: source <(${schema.name} completions bash)`);
35
- lines.push("#");
36
- lines.push("# Install permanently:");
37
- lines.push(`# ${schema.name} completions bash > /etc/bash_completion.d/${schema.name} # Linux`);
38
- lines.push(`# ${schema.name} completions bash > $(brew --prefix)/etc/bash_completion.d/${schema.name} # macOS`);
39
- lines.push("#");
40
- lines.push("# Requires: bash-completion (provides _init_completion)");
41
- lines.push("");
42
- lines.push(`${funcName}() {`);
43
- lines.push(`\tlocal cur prev words cword`);
44
- lines.push(`\t_init_completion || return`);
45
- lines.push("");
46
- if (visibleCommands.length > 0) {
47
- const groupNodes = nodes.filter((n) => n.children.length > 0);
48
- const valueFlagPattern = collectValueFlagPattern(nodes, rootSurface);
49
- lines.push(" # Build subcommand path by scanning COMP_WORDS");
50
- lines.push(" local subcmd_path=\"\"");
51
- lines.push(" local i");
52
- lines.push(" for ((i = 1; i < cword; i++)); do");
53
- lines.push(" case \"${words[i]}\" in");
54
- lines.push(" --) break ;;");
55
- if (valueFlagPattern.length > 0) lines.push(`\t\t\t${valueFlagPattern}) ((i++)); continue ;;`);
56
- lines.push(" -*) continue ;;");
57
- lines.push(" esac");
58
- emitBashPathDetection(lines, visibleCommands, groupNodes, maxDepth);
59
- lines.push(" done");
60
- lines.push("");
61
- lines.push(" # Complete flags and subcommands for the active path");
62
- lines.push(" case \"$subcmd_path\" in");
63
- for (const node of nodes) {
64
- const pathKey = node.path.join(" ");
65
- const mergedFlags = node.mergedFlags;
66
- const enumCases = collectEnumCasesFromFlags(mergedFlags);
67
- const flagWords = collectFlagWords(mergedFlags);
68
- const childNames = dedupeWords(node.children.flatMap((child) => [child.name, ...child.aliases])).map(escapeForSingleQuote).join(" ");
69
- const escapedFlagWords = flagWords.split(" ").filter(Boolean).map(escapeForSingleQuote).join(" ");
70
- const completionWords = childNames.length > 0 ? `${childNames} ${escapedFlagWords}` : escapedFlagWords;
71
- lines.push(`\t\t${quoteShellCasePattern(pathKey)})`);
72
- if (enumCases.length > 0) {
73
- lines.push(" local enum_flag=\"\"");
74
- lines.push(" local enum_cur=\"$cur\"");
75
- lines.push(" local enum_prefix=\"\"");
76
- lines.push(" if [[ \"$cur\" == --*=* ]]; then");
77
- lines.push(`\t\t\t\tenum_flag="\${cur%%=*}"`);
78
- lines.push(`\t\t\t\tenum_cur="\${cur#*=}"`);
79
- lines.push(`\t\t\t\tenum_prefix="\${cur%%=*}="`);
80
- lines.push(" fi");
81
- lines.push(`\t\t\tcase "\${enum_flag:-$prev}" in`);
82
- for (const ec of enumCases) {
83
- lines.push(`\t\t\t\t${ec.flags})`);
84
- lines.push(formatBashEnumCompletion(ec.values, " ", "enum_cur", "enum_prefix"));
85
- lines.push(" return");
86
- lines.push(" ;;");
87
- }
88
- lines.push(" *)");
89
- lines.push(" ;;");
90
- lines.push(" esac");
91
- }
92
- lines.push(`\t\t\tCOMPREPLY=($(compgen -W '${completionWords.trim()}' -- "$cur"))`);
93
- lines.push(" return");
94
- lines.push(" ;;");
95
- }
96
- lines.push(" *)");
97
- lines.push(" ;;");
98
- lines.push(" esac");
99
- lines.push("");
100
- const rootFlagWords = collectFlagWords(rootSurface.rootFlags).split(" ").filter(Boolean);
101
- const defaultFlagWords = rootSurface.includeDefaultFlags ? collectFlagWords(rootSurface.defaultFlags).split(" ").filter(Boolean) : [];
102
- const completionWords = dedupeWords([
103
- ...visibleCommands.flatMap((command) => [command.name, ...command.aliases]),
104
- ...rootFlagWords,
105
- ...defaultFlagWords
106
- ]).map(escapeForSingleQuote).join(" ");
107
- lines.push(`\t# Root-level completions: visible root surface`);
108
- lines.push(`\tCOMPREPLY=($(compgen -W '${completionWords}' -- "$cur"))`);
109
- } else {
110
- const globalFlags = collectFlagWords({
111
- ...rootSurface.rootFlags,
112
- ...rootSurface.includeDefaultFlags ? rootSurface.defaultFlags : {}
113
- });
114
- lines.push(`\tCOMPREPLY=($(compgen -W '${globalFlags}' -- "$cur"))`);
115
- }
116
- lines.push("}");
117
- lines.push("");
118
- lines.push(`complete -F ${funcName} ${quoteShellArg(schema.name)}`);
119
- lines.push("");
120
- return lines.join("\n");
121
- }
122
- /**
123
- * Emit bash case branches for progressive subcommand path detection.
124
- *
125
- * For each nesting depth, generates a `case "$subcmd_path"` that matches
126
- * the current accumulated path and extends it when a matching child command
127
- * name is found in COMP_WORDS.
128
- *
129
- * @internal
130
- */
131
- function emitBashPathDetection(lines, visibleCommands, groupNodes, maxDepth) {
132
- lines.push(`\t\tcase "$subcmd_path" in`);
133
- lines.push(`\t\t\t'')`);
134
- lines.push(`\t\t\t\tcase "\${words[i]}" in`);
135
- for (const command of visibleCommands) {
136
- const patterns = [command.name, ...command.aliases].map(escapeBashCasePatternValue);
137
- lines.push(`\t\t\t\t\t${patterns.join("|")})`);
138
- lines.push(`\t\t\t\t\t\tsubcmd_path="${escapeBashDoubleQuotedValue(command.name)}"`);
139
- lines.push(`\t\t\t\t\t\t;;`);
140
- }
141
- lines.push(`\t\t\t\tesac`);
142
- lines.push(`\t\t\t\t;;`);
143
- if (maxDepth > 1) for (const node of groupNodes) {
144
- const pathKey = node.path.join(" ");
145
- lines.push(`\t\t\t${quoteShellCasePattern(pathKey)})`);
146
- lines.push(`\t\t\t\tcase "\${words[i]}" in`);
147
- for (const child of node.children) {
148
- const childPatterns = [child.name, ...child.aliases].map(escapeBashCasePatternValue);
149
- lines.push(`\t\t\t\t\t${childPatterns.join("|")})`);
150
- lines.push(`\t\t\t\t\t\tsubcmd_path="$subcmd_path ${escapeBashDoubleQuotedValue(child.name)}"`);
151
- lines.push(`\t\t\t\t\t\t;;`);
152
- }
153
- lines.push(`\t\t\t\tesac`);
154
- lines.push(`\t\t\t\t;;`);
155
- }
156
- lines.push(`\t\tesac`);
157
- }
158
- /**
159
- * Escape a string for use as a bash `case` pattern.
160
- *
161
- * Escapes glob metacharacters so arbitrary command, alias, and flag names are
162
- * matched literally rather than being interpreted as shell patterns.
163
- *
164
- * @internal
165
- */
166
- function quoteShellCasePattern(pattern) {
167
- if (pattern.includes(" ")) return `"${escapeBashDoubleQuotedValue(pattern)}"`;
168
- return escapeBashCasePatternValue(pattern);
169
- }
170
- /**
171
- * Escape a value for use in a bash `case` pattern.
172
- *
173
- * Escapes glob metacharacters so arbitrary command and flag names are matched
174
- * literally rather than being interpreted as shell patterns.
175
- *
176
- * @internal
177
- */
178
- function escapeBashCasePatternValue(value) {
179
- if (/^[a-zA-Z0-9_\-.]+$/.test(value)) return value;
180
- return value.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/"/g, "\\\"").replace(/\|/g, "\\|").replace(/\*/g, "\\*").replace(/\?/g, "\\?").replace(/\[/g, "\\[").replace(/\]/g, "\\]").replace(/\(/g, "\\(").replace(/\)/g, "\\)").replace(/\{/g, "\\{").replace(/\}/g, "\\}").replace(/\+/g, "\\+").replace(/!/g, "\\!").replace(/@/g, "\\@").replace(/#/g, "\\#").replace(/~/g, "\\~").replace(/\s/g, (match) => match === " " ? "\\ " : `\\${match}`);
181
- }
182
- /**
183
- * Escape a value for interpolation inside a bash double-quoted string.
184
- *
185
- * @internal
186
- */
187
- function escapeBashDoubleQuotedValue(value) {
188
- return value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/\$/g, "\\$").replace(/`/g, "\\`");
189
- }
190
- /**
191
- * Escape a string for safe embedding inside an existing single-quoted
192
- * shell literal (e.g. inside `compgen -W '...'`).
193
- *
194
- * Uses the `'\''` idiom: close quote, escaped literal quote, reopen
195
- * quote. Returns the input unchanged when it consists only of shell-safe
196
- * characters, which covers the vast majority of flag/command names.
197
- *
198
- * @internal
199
- */
200
- function escapeForSingleQuote(value) {
201
- if (/^[a-zA-Z0-9_\-.]+$/.test(value)) return value;
202
- return value.replace(/'/g, "'\\''");
203
- }
204
- /**
205
- * Format a COMPREPLY line for bash enum value completion.
206
- *
207
- * When all values are simple (no whitespace or special chars), emits a
208
- * standard `compgen -W 'v1 v2' -- "$cur"` line.
209
- *
210
- * When any value contains whitespace, single quotes, or backslashes,
211
- * uses `IFS=$'\n'` with `$'...'` quoting to split on newlines
212
- * instead of spaces, handling all special characters correctly.
213
- *
214
- * @internal
215
- */
216
- function formatBashEnumCompletion(values, indent, currentVar = "cur", prefixVar) {
217
- const lines = [];
218
- if (values.some((v) => !/^[a-zA-Z0-9_\-.]+$/.test(v))) {
219
- const joined = values.map(escapeBashDollarQuote).join("\\n");
220
- lines.push(`${indent}local IFS=$'\\n'`);
221
- lines.push(`${indent}COMPREPLY=($(compgen -W $'${joined}' -- "$${currentVar}"))`);
222
- } else lines.push(`${indent}COMPREPLY=($(compgen -W '${values.join(" ")}' -- "$${currentVar}"))`);
223
- if (prefixVar !== void 0) {
224
- lines.push(`${indent}if [[ -n "$${prefixVar}" && "\${#COMPREPLY[@]}" -gt 0 ]]; then`);
225
- lines.push(`${indent}\tlocal i`);
226
- lines.push(`${indent}\tfor ((i = 0; i < \${#COMPREPLY[@]}; i++)); do`);
227
- lines.push(`${indent}\t\tCOMPREPLY[i]="$${prefixVar}\${COMPREPLY[i]}"`);
228
- lines.push(`${indent}\tdone`);
229
- lines.push(`${indent}fi`);
230
- }
231
- return lines.join("\n");
232
- }
233
- /**
234
- * Escape a single enum value for use inside a bash `$'...'` string.
235
- *
236
- * In `$'...'` context:
237
- * - `\\` → literal backslash
238
- * - `\'` → literal single quote
239
- * - `\n` → newline (used as IFS delimiter, so must be escaped in values)
240
- *
241
- * Values that are simple identifiers pass through unescaped.
242
- *
243
- * @internal
244
- */
245
- function escapeBashDollarQuote(value) {
246
- return value.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\n/g, "\\n");
247
- }
248
- /**
249
- * Collect all `--flag` words (long + short aliases + visible negated
250
- * spellings) for a flag record.
251
- *
252
- * @internal
253
- */
254
- function collectFlagWords(flags) {
255
- const words = [];
256
- for (const [name, schema] of Object.entries(flags)) {
257
- words.push(`--${name}`);
258
- for (const alias of getFlagAliasNames(schema)) words.push(alias.length === 1 ? `-${alias}` : `--${alias}`);
259
- const negated = getVisibleNegatedName(name, schema);
260
- if (negated !== void 0) words.push(`--${negated}`);
261
- }
262
- return words.join(" ");
263
- }
264
- /**
265
- * Collect all value-taking flag forms across every node and root surface,
266
- * deduplicated and escaped for use in a bash `case` pattern.
267
- *
268
- * Returns a `|`-joined pattern like `--schema|-s|--output|-o` that the
269
- * subcommand-path walker uses to skip the operand following a value-taking
270
- * flag. Returns an empty string when no value-taking flags exist.
271
- *
272
- * @internal
273
- */
274
- function collectValueFlagPattern(nodes, rootSurface) {
275
- const forms = /* @__PURE__ */ new Set();
276
- const addFlags = (flags) => {
277
- for (const [name, schema] of Object.entries(flags)) {
278
- if (!flagExpectsValue(schema)) continue;
279
- forms.add(`--${name}`);
280
- for (const alias of getFlagAliasNames(schema, { includeHidden: true })) forms.add(alias.length === 1 ? `-${alias}` : `--${alias}`);
281
- }
282
- };
283
- for (const node of nodes) addFlags(node.mergedFlags);
284
- addFlags(rootSurface.rootFlags);
285
- if (rootSurface.includeDefaultFlags) addFlags(rootSurface.defaultFlags);
286
- return [...forms].map(escapeBashCasePatternValue).join("|");
287
- }
288
- function dedupeWords(words) {
289
- return [...new Set(words)];
290
- }
291
- /**
292
- * Collect enum flag cases from a merged flag record.
293
- *
294
- * Each enum flag produces one case entry with its long/short flag forms
295
- * as the pattern and enum values as the completions.
296
- *
297
- * @internal
298
- */
299
- function collectEnumCasesFromFlags(flags) {
300
- const cases = [];
301
- for (const [name, schema] of Object.entries(flags)) {
302
- if (schema.kind !== "enum" || schema.enumValues === void 0) continue;
303
- const flagForms = [`--${name}`, ...getFlagAliasNames(schema, { includeHidden: true }).map((alias) => alias.length === 1 ? `-${alias}` : `--${alias}`)].map(escapeBashCasePatternValue);
304
- cases.push({
305
- flags: flagForms.join("|"),
306
- values: schema.enumValues
307
- });
308
- }
309
- return cases;
310
- }
311
- //#endregion
312
- export { generateBashCompletion };
@@ -1,19 +0,0 @@
1
- import { CompletionOptions } from "./shared.mjs";
2
- import { CLISchema } from "../../cli/index.mjs";
3
- //#region src/core/completion/shells/fish.d.ts
4
- /**
5
- * Generate a fish completion script for the CLI.
6
- *
7
- * @param schema - The CLI schema.
8
- * @param options - Optional generator configuration.
9
- * @returns A complete fish completion script.
10
- *
11
- * @example
12
- * ```ts
13
- * const script = generateFishCompletion(app.schema);
14
- * // install with: mycli completions fish > ~/.config/fish/completions/mycli.fish
15
- * ```
16
- */
17
- declare function generateFishCompletion(schema: CLISchema, options?: CompletionOptions): string;
18
- //#endregion
19
- export { generateFishCompletion };
@@ -1,164 +0,0 @@
1
- import { getFlagAliasNames } from "../../schema/flag.mjs";
2
- import { flagExpectsValue } from "../../parse/index.mjs";
3
- import { getVisibleNegatedName, quoteShellArg, resolveRootCompletionSurface, sanitizeShellIdentifier, versionTag, walkCommandTree } from "./shared.mjs";
4
- import { resolvePlainHelpDescription } from "../../help/theme.mjs";
5
- //#region src/core/completion/shells/fish.ts
6
- /**
7
- * Generate a fish completion script for the CLI.
8
- *
9
- * @param schema - The CLI schema.
10
- * @param options - Optional generator configuration.
11
- * @returns A complete fish completion script.
12
- *
13
- * @example
14
- * ```ts
15
- * const script = generateFishCompletion(app.schema);
16
- * // install with: mycli completions fish > ~/.config/fish/completions/mycli.fish
17
- * ```
18
- */
19
- function generateFishCompletion(schema, options) {
20
- const prefix = options?.functionPrefix ?? schema.name;
21
- const helperPrefix = `__${sanitizeShellIdentifier(prefix)}_completions`;
22
- const pathFuncName = `${helperPrefix}_path`;
23
- const pathIsFuncName = `${helperPrefix}_path_is`;
24
- const rootSurface = resolveRootCompletionSurface(schema, options?.rootMode);
25
- const visibleCommands = rootSurface.visibleCommands;
26
- const nodes = walkCommandTree(visibleCommands);
27
- const commandName = quoteShellArg(schema.name);
28
- const lines = [];
29
- lines.push(`# Fish completion for ${schema.name}`);
30
- lines.push(`# Generated by ${versionTag()}`);
31
- lines.push("#");
32
- lines.push(`# Usage: source (${schema.name} completions fish | psub)`);
33
- lines.push("#");
34
- lines.push("# Install permanently:");
35
- lines.push(`# ${schema.name} completions fish > ~/.config/fish/completions/${schema.name}.fish`);
36
- lines.push("");
37
- lines.push(`complete -c ${commandName} -f`);
38
- lines.push("");
39
- emitFishPathHelpers(lines, pathFuncName, pathIsFuncName, visibleCommands, nodes, rootSurface);
40
- appendFishCommandCompletions(lines, commandName, pathIsFuncName, "", visibleCommands);
41
- appendFishFlagCompletions(lines, commandName, pathIsFuncName, "", rootSurface.rootFlags);
42
- if (rootSurface.includeDefaultFlags) appendFishFlagCompletions(lines, commandName, pathIsFuncName, "", rootSurface.defaultFlags);
43
- for (const node of nodes) {
44
- const path = node.path.join(" ");
45
- appendFishCommandCompletions(lines, commandName, pathIsFuncName, path, node.children);
46
- appendFishFlagCompletions(lines, commandName, pathIsFuncName, path, node.mergedFlags);
47
- }
48
- return lines.join("\n");
49
- }
50
- function emitFishPathHelpers(lines, pathFuncName, pathIsFuncName, visibleCommands, nodes, rootSurface) {
51
- const valueFlags = collectFishValueFlagPatterns(nodes, rootSurface);
52
- lines.push(`function ${pathFuncName}`);
53
- lines.push(" set -l words (commandline -opc)");
54
- lines.push(" if test (count $words) -gt 0");
55
- lines.push(" set -e words[1]");
56
- lines.push(" end");
57
- lines.push(" set -l subcmd_path ''");
58
- lines.push(" set -l expect_value 0");
59
- lines.push(" for word in $words");
60
- lines.push(" if test $expect_value -eq 1");
61
- lines.push(" set expect_value 0");
62
- lines.push(" continue");
63
- lines.push(" end");
64
- lines.push(" switch $word");
65
- lines.push(" case '--'");
66
- lines.push(" break");
67
- if (valueFlags.exact.length > 0) {
68
- lines.push(`\t\t\tcase ${valueFlags.exact.map(quoteShellArg).join(" ")}`);
69
- lines.push(" set expect_value 1");
70
- lines.push(" continue");
71
- }
72
- if (valueFlags.prefix.length > 0) {
73
- lines.push(`\t\t\tcase ${valueFlags.prefix.map(quoteShellArg).join(" ")}`);
74
- lines.push(" continue");
75
- }
76
- lines.push(" case '-*'");
77
- lines.push(" continue");
78
- lines.push(" end");
79
- lines.push(" switch \"$subcmd_path|$word\"");
80
- for (const command of visibleCommands) for (const name of [command.name, ...command.aliases]) {
81
- lines.push(`\t\t\tcase ${quoteShellArg(`|${name}`)}`);
82
- lines.push(`\t\t\t\tset subcmd_path ${quoteShellArg(command.name)}`);
83
- }
84
- for (const node of nodes) for (const child of node.children) for (const name of [child.name, ...child.aliases]) {
85
- lines.push(`\t\t\tcase ${quoteShellArg(`${node.path.join(" ")}|${name}`)}`);
86
- lines.push(`\t\t\t\tset subcmd_path ${quoteShellArg(`${node.path.join(" ")} ${child.name}`)}`);
87
- }
88
- lines.push(" case '*'");
89
- lines.push(" break");
90
- lines.push(" end");
91
- lines.push(" end");
92
- lines.push(" printf '%s\\n' \"$subcmd_path\"");
93
- lines.push("end");
94
- lines.push("");
95
- lines.push(`function ${pathIsFuncName}`);
96
- lines.push(" set -l expected \"$argv[1]\"");
97
- lines.push(`\ttest (${pathFuncName}) = "$expected"`);
98
- lines.push("end");
99
- lines.push("");
100
- }
101
- function appendFishCommandCompletions(lines, commandName, pathIsFuncName, path, commands) {
102
- const condition = buildFishCondition(pathIsFuncName, path);
103
- for (const command of commands) {
104
- const description = quoteShellArg(command.description ?? command.name);
105
- for (const name of [command.name, ...command.aliases]) lines.push(`complete -c ${commandName} -n "${condition}" -a ${quoteShellArg(name)} -d ${description}`);
106
- }
107
- if (commands.length > 0) lines.push("");
108
- }
109
- function appendFishFlagCompletions(lines, commandName, pathIsFuncName, path, flags) {
110
- const condition = buildFishCondition(pathIsFuncName, path);
111
- for (const [name, schema] of Object.entries(flags)) {
112
- const parts = [`complete -c ${commandName}`, `-n "${condition}"`];
113
- for (const alias of getFlagAliasNames(schema, { kind: "short" })) parts.push(`-s ${quoteShellArg(alias)}`);
114
- parts.push(`-l ${quoteShellArg(name)}`);
115
- for (const alias of getFlagAliasNames(schema, { kind: "long" })) parts.push(`-l ${quoteShellArg(alias)}`);
116
- const negated = getVisibleNegatedName(name, schema);
117
- if (negated !== void 0) parts.push(`-l ${quoteShellArg(negated)}`);
118
- parts.push(`-d ${quoteShellArg(schema.description === void 0 ? name : resolvePlainHelpDescription(schema.description))}`);
119
- if (flagExpectsValue(schema)) parts.push("-r", "-f");
120
- if (schema.kind === "enum" && schema.enumValues !== void 0) {
121
- for (const enumValue of schema.enumValues) lines.push([...parts, `-a ${quoteShellArg(enumValue)}`].join(" "));
122
- continue;
123
- }
124
- lines.push(parts.join(" "));
125
- }
126
- if (Object.keys(flags).length > 0) lines.push("");
127
- }
128
- function collectFishValueFlagPatterns(nodes, rootSurface) {
129
- const exact = /* @__PURE__ */ new Set();
130
- const prefix = /* @__PURE__ */ new Set();
131
- const flagSets = [
132
- rootSurface.rootFlags,
133
- ...rootSurface.includeDefaultFlags ? [rootSurface.defaultFlags] : [],
134
- ...nodes.map((node) => node.mergedFlags)
135
- ];
136
- for (const flags of flagSets) for (const [name, schema] of Object.entries(flags)) {
137
- if (!flagExpectsValue(schema)) continue;
138
- exact.add(`--${name}`);
139
- prefix.add(`--${name}=*`);
140
- for (const alias of getFlagAliasNames(schema, {
141
- kind: "short",
142
- includeHidden: true
143
- })) {
144
- exact.add(`-${alias}`);
145
- prefix.add(`-${alias}*`);
146
- }
147
- for (const alias of getFlagAliasNames(schema, {
148
- kind: "long",
149
- includeHidden: true
150
- })) {
151
- exact.add(`--${alias}`);
152
- prefix.add(`--${alias}=*`);
153
- }
154
- }
155
- return {
156
- exact: [...exact],
157
- prefix: [...prefix]
158
- };
159
- }
160
- function buildFishCondition(pathIsFuncName, path) {
161
- return `${pathIsFuncName} ${quoteShellArg(path)}`;
162
- }
163
- //#endregion
164
- export { generateFishCompletion };
@@ -1,13 +0,0 @@
1
- import { CompletionOptions } from "./shared.mjs";
2
- import { CLISchema } from "../../cli/index.mjs";
3
- //#region src/core/completion/shells/powershell.d.ts
4
- /**
5
- * Generate a PowerShell completion script for the CLI.
6
- *
7
- * @param schema - The CLI schema.
8
- * @param options - Optional generator configuration.
9
- * @returns A complete PowerShell completion script.
10
- */
11
- declare function generatePowerShellCompletion(schema: CLISchema, options?: CompletionOptions): string;
12
- //#endregion
13
- export { generatePowerShellCompletion };