@canonical/summon 0.36.0 → 0.38.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 (40) hide show
  1. package/dist/src/components/App.js +24 -2
  2. package/dist/src/components/App.js.map +1 -1
  3. package/dist/src/index.d.ts +15 -0
  4. package/dist/src/index.js +16 -0
  5. package/dist/src/index.js.map +1 -0
  6. package/dist/src/registration/registerFromBarrel.js +13 -0
  7. package/dist/src/registration/registerFromBarrel.js.map +1 -1
  8. package/package.json +22 -14
  9. package/src/bin.tsx +238 -0
  10. package/src/completion.test.ts +202 -0
  11. package/src/completion.ts +492 -0
  12. package/src/components/App.askMissing.test.tsx +164 -0
  13. package/src/components/App.confirmGate.test.tsx +111 -0
  14. package/src/components/App.escBack.test.tsx +98 -0
  15. package/src/components/App.invalidAnswer.test.tsx +71 -0
  16. package/src/components/App.tsx +1305 -0
  17. package/src/components/ExecutionProgress.tsx +222 -0
  18. package/src/components/FileTreePreview.tsx +97 -0
  19. package/src/components/PromptSequence.tsx +558 -0
  20. package/src/components/Spinner.tsx +36 -0
  21. package/src/components/index.ts +16 -0
  22. package/src/components/undoPlan.test.ts +99 -0
  23. package/src/components/undoPlan.ts +70 -0
  24. package/src/discovery/index.ts +1 -0
  25. package/src/discovery/loadGenerator.ts +40 -0
  26. package/src/display/index.ts +2 -0
  27. package/src/display/printGeneratorHelp.ts +130 -0
  28. package/src/display/printNode.ts +76 -0
  29. package/src/index.ts +16 -0
  30. package/src/registration/buildCommandBarrel.test.ts +80 -0
  31. package/src/registration/buildCommandBarrel.ts +66 -0
  32. package/src/registration/conformance.subprocess.test.ts +192 -0
  33. package/src/registration/index.ts +2 -0
  34. package/src/registration/interaction.subprocess.test.ts +458 -0
  35. package/src/registration/registerFromBarrel.tsx +501 -0
  36. package/src/registration/resolveMode.test.ts +118 -0
  37. package/src/registration/resolveMode.ts +52 -0
  38. package/src/testing/globalSetup.test.ts +165 -0
  39. package/src/testing/globalSetup.ts +501 -0
  40. package/src/ui/index.tsx +31 -0
@@ -0,0 +1,202 @@
1
+ /**
2
+ * Tests for shell autocompletion utilities
3
+ */
4
+
5
+ import type { PromptDefinition } from "@canonical/summon-core";
6
+ import { describe, expect, it } from "vitest";
7
+ import { getArgumentCompletions, isPathPrompt } from "./completion.js";
8
+
9
+ // =============================================================================
10
+ // isPathPrompt
11
+ // =============================================================================
12
+
13
+ describe("isPathPrompt", () => {
14
+ it("detects path in prompt name", () => {
15
+ expect(
16
+ isPathPrompt({ name: "componentPath", type: "text", message: "Enter:" }),
17
+ ).toBe(true);
18
+ });
19
+
20
+ it("detects dir in prompt name", () => {
21
+ expect(
22
+ isPathPrompt({ name: "outputDir", type: "text", message: "Enter:" }),
23
+ ).toBe(true);
24
+ });
25
+
26
+ it("detects directory in prompt name", () => {
27
+ expect(
28
+ isPathPrompt({
29
+ name: "outputDirectory",
30
+ type: "text",
31
+ message: "Enter:",
32
+ }),
33
+ ).toBe(true);
34
+ });
35
+
36
+ it("detects file in prompt name", () => {
37
+ expect(
38
+ isPathPrompt({ name: "configFile", type: "text", message: "Enter:" }),
39
+ ).toBe(true);
40
+ });
41
+
42
+ it("detects folder in prompt message", () => {
43
+ expect(
44
+ isPathPrompt({
45
+ name: "output",
46
+ type: "text",
47
+ message: "Choose output folder:",
48
+ }),
49
+ ).toBe(true);
50
+ });
51
+
52
+ it("detects location in prompt message", () => {
53
+ expect(
54
+ isPathPrompt({
55
+ name: "output",
56
+ type: "text",
57
+ message: "File location:",
58
+ }),
59
+ ).toBe(true);
60
+ });
61
+
62
+ it("returns false for non-path prompts", () => {
63
+ expect(
64
+ isPathPrompt({ name: "name", type: "text", message: "Package name:" }),
65
+ ).toBe(false);
66
+ });
67
+
68
+ it("returns false for confirm prompts", () => {
69
+ expect(
70
+ isPathPrompt({
71
+ name: "withStyles",
72
+ type: "confirm",
73
+ message: "Include styles?",
74
+ }),
75
+ ).toBe(false);
76
+ });
77
+
78
+ it("is case-insensitive", () => {
79
+ expect(
80
+ isPathPrompt({ name: "MyPath", type: "text", message: "Enter:" }),
81
+ ).toBe(true);
82
+ });
83
+ });
84
+
85
+ // =============================================================================
86
+ // getArgumentCompletions
87
+ // =============================================================================
88
+
89
+ describe("getArgumentCompletions", () => {
90
+ const prompts: PromptDefinition[] = [
91
+ { name: "componentPath", type: "text", message: "Component path:" },
92
+ {
93
+ name: "withStyles",
94
+ type: "confirm",
95
+ message: "Include styles?",
96
+ default: true,
97
+ },
98
+ {
99
+ name: "withStories",
100
+ type: "confirm",
101
+ message: "Include stories?",
102
+ default: true,
103
+ },
104
+ {
105
+ name: "type",
106
+ type: "select",
107
+ message: "Package type:",
108
+ choices: [
109
+ { value: "library", label: "Library" },
110
+ { value: "tool-ts", label: "Tool" },
111
+ { value: "css", label: "CSS" },
112
+ ],
113
+ },
114
+ ];
115
+
116
+ it("returns flag completions when completing a flag name", () => {
117
+ const completions = getArgumentCompletions(
118
+ prompts,
119
+ "summon test --comp",
120
+ "--comp",
121
+ );
122
+
123
+ expect(completions).toContain("--component-path");
124
+ });
125
+
126
+ it("shows --no-X for confirm prompts with default true", () => {
127
+ const completions = getArgumentCompletions(
128
+ prompts,
129
+ "summon test --no-",
130
+ "--no-",
131
+ );
132
+
133
+ expect(completions).toContain("--no-with-styles");
134
+ expect(completions).toContain("--no-with-stories");
135
+ });
136
+
137
+ it("returns select choices when completing a flag value", () => {
138
+ const completions = getArgumentCompletions(
139
+ prompts,
140
+ "summon test --type=",
141
+ "",
142
+ );
143
+
144
+ expect(completions).toContain("library");
145
+ expect(completions).toContain("tool-ts");
146
+ expect(completions).toContain("css");
147
+ });
148
+
149
+ it("filters select choices by partial value", () => {
150
+ const completions = getArgumentCompletions(
151
+ prompts,
152
+ "summon test --type=lib",
153
+ "",
154
+ );
155
+
156
+ expect(completions).toContain("library");
157
+ expect(completions).not.toContain("tool-ts");
158
+ expect(completions).not.toContain("css");
159
+ });
160
+
161
+ it("includes built-in flags", () => {
162
+ const completions = getArgumentCompletions(
163
+ prompts,
164
+ "summon test --dry",
165
+ "--dry",
166
+ );
167
+
168
+ expect(completions).toContain("--dry-run");
169
+ });
170
+
171
+ it("shows all flags when showAll is true", () => {
172
+ const completions = getArgumentCompletions(
173
+ prompts,
174
+ "summon test",
175
+ "",
176
+ true,
177
+ );
178
+
179
+ expect(completions).toContain("--component-path");
180
+ expect(completions).toContain("--dry-run");
181
+ expect(completions).toContain("--help");
182
+ });
183
+
184
+ it("returns empty array when no matches", () => {
185
+ const completions = getArgumentCompletions(
186
+ prompts,
187
+ "summon test --zzz",
188
+ "--zzz",
189
+ );
190
+
191
+ expect(completions).toHaveLength(0);
192
+ });
193
+
194
+ it("includes --yes and --verbose in built-in flags", () => {
195
+ const completions = getArgumentCompletions([], "summon test --", "--");
196
+
197
+ expect(completions).toContain("--yes");
198
+ expect(completions).toContain("--verbose");
199
+ expect(completions).toContain("--llm");
200
+ expect(completions).toContain("--help");
201
+ });
202
+ });
@@ -0,0 +1,492 @@
1
+ /**
2
+ * Shell Autocompletion Support for Summon CLI
3
+ *
4
+ * Uses omelette to provide TAB completion for:
5
+ * - Generator names (navigating the command tree)
6
+ * - Generator arguments (based on prompt definitions)
7
+ * - File/folder paths for path-related prompts
8
+ *
9
+ * Supports Bash, Zsh, and Fish shells.
10
+ */
11
+
12
+ import * as fs from "node:fs";
13
+ import * as path from "node:path";
14
+ import type {
15
+ GeneratorDefinition,
16
+ PromptDefinition,
17
+ } from "@canonical/summon-core";
18
+ import omelette from "omelette";
19
+
20
+ // =============================================================================
21
+ // Types
22
+ // =============================================================================
23
+
24
+ /** Represents a node in the generator tree (simplified for completion) */
25
+ export interface CompletionNode {
26
+ name: string;
27
+ indexPath?: string;
28
+ children: Map<string, CompletionNode>;
29
+ }
30
+
31
+ /** Flattened generator info for completion */
32
+ interface GeneratorInfo {
33
+ path: string[];
34
+ prompts: PromptDefinition[];
35
+ }
36
+
37
+ // =============================================================================
38
+ // Path Detection
39
+ // =============================================================================
40
+
41
+ /**
42
+ * Detect if a prompt expects a file/folder path based on its name or message.
43
+ */
44
+ export const isPathPrompt = (prompt: PromptDefinition): boolean => {
45
+ const pathIndicators = [
46
+ "path",
47
+ "dir",
48
+ "directory",
49
+ "file",
50
+ "folder",
51
+ "location",
52
+ ];
53
+ const nameLower = prompt.name.toLowerCase();
54
+ const messageLower = prompt.message.toLowerCase();
55
+
56
+ return pathIndicators.some(
57
+ (ind) => nameLower.includes(ind) || messageLower.includes(ind),
58
+ );
59
+ };
60
+
61
+ // =============================================================================
62
+ // Filesystem Completion
63
+ // =============================================================================
64
+
65
+ /**
66
+ * Get filesystem path completions for a partial path.
67
+ */
68
+ export const getPathCompletions = (partial: string): string[] => {
69
+ try {
70
+ // Handle empty or relative paths
71
+ const searchPath = partial || ".";
72
+ const dir = path.dirname(searchPath);
73
+ const prefix = path.basename(searchPath);
74
+
75
+ // Try to read the directory
76
+ const dirToRead = partial.endsWith("/") ? searchPath : dir;
77
+ const entries = fs.readdirSync(dirToRead, { withFileTypes: true });
78
+
79
+ // Filter entries that match the prefix
80
+ const matches = entries
81
+ .filter((entry) => {
82
+ // If partial ends with /, show all entries
83
+ if (partial.endsWith("/")) return true;
84
+ // Otherwise filter by prefix
85
+ return entry.name.startsWith(prefix);
86
+ })
87
+ .map((entry) => {
88
+ const name = entry.name;
89
+ const basePath = partial.endsWith("/") ? searchPath : dir;
90
+ const fullPath = basePath === "." ? name : path.join(basePath, name);
91
+
92
+ // Append / for directories to enable continued completion
93
+ return entry.isDirectory() ? `${fullPath}/` : fullPath;
94
+ })
95
+ .slice(0, 50); // Limit results
96
+
97
+ return matches;
98
+ } catch {
99
+ // Directory doesn't exist or can't be read
100
+ return [];
101
+ }
102
+ };
103
+
104
+ // =============================================================================
105
+ // Argument Completion
106
+ // =============================================================================
107
+
108
+ /**
109
+ * Convert camelCase to kebab-case for CLI flags.
110
+ */
111
+ const toKebabCase = (str: string): string =>
112
+ str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
113
+
114
+ /**
115
+ * Get completions for generator arguments based on prompt definitions.
116
+ *
117
+ * @param prompts - The prompt definitions for the generator
118
+ * @param line - The current command line
119
+ * @param before - The word before the cursor
120
+ * @param showAll - If true, show all flags even if line doesn't contain --
121
+ */
122
+ export const getArgumentCompletions = (
123
+ prompts: PromptDefinition[],
124
+ line: string,
125
+ before: string,
126
+ showAll = false,
127
+ ): string[] => {
128
+ const completions: string[] = [];
129
+
130
+ // Check if we're completing a flag value (e.g., --type=<TAB> or --type <TAB>)
131
+ const flagValueMatch = line.match(/--([a-z-]+)(?:=|\s+)([^\s]*)$/i);
132
+ if (flagValueMatch) {
133
+ const flagName = flagValueMatch[1];
134
+ const partial = flagValueMatch[2] || "";
135
+
136
+ // Find the corresponding prompt
137
+ const prompt = prompts.find(
138
+ (p) => toKebabCase(p.name) === flagName || p.name === flagName,
139
+ );
140
+
141
+ if (prompt) {
142
+ // For select/multiselect, return choices
143
+ if (
144
+ (prompt.type === "select" || prompt.type === "multiselect") &&
145
+ prompt.choices
146
+ ) {
147
+ return prompt.choices
148
+ .map((c) => c.value)
149
+ .filter((v) => v.startsWith(partial));
150
+ }
151
+
152
+ // For text prompts that look like paths, return path completions
153
+ if (prompt.type === "text" && isPathPrompt(prompt)) {
154
+ return getPathCompletions(partial);
155
+ }
156
+ }
157
+ }
158
+
159
+ // Check if we're completing a flag name (--<TAB>) or showing all flags
160
+ const flagNameMatch = line.match(/--([a-z-]*)$/i);
161
+ const shouldShowFlags =
162
+ showAll ||
163
+ flagNameMatch ||
164
+ before === "--" ||
165
+ before.startsWith("--") ||
166
+ before.startsWith("-");
167
+
168
+ if (shouldShowFlags) {
169
+ // Extract partial from the flag name match, or from 'before' if it starts with --
170
+ let partial = flagNameMatch?.[1] || "";
171
+ if (!partial && before.startsWith("--")) {
172
+ partial = before.slice(2);
173
+ } else if (!partial && before.startsWith("-")) {
174
+ partial = before.slice(1);
175
+ }
176
+
177
+ for (const prompt of prompts) {
178
+ const kebabName = toKebabCase(prompt.name);
179
+
180
+ if (prompt.type === "confirm") {
181
+ // For confirm prompts, show --no-X if default is true, --X if default is false
182
+ if (prompt.default === true) {
183
+ const flag = `no-${kebabName}`;
184
+ if (flag.startsWith(partial)) {
185
+ completions.push(`--${flag}`);
186
+ }
187
+ } else {
188
+ if (kebabName.startsWith(partial)) {
189
+ completions.push(`--${kebabName}`);
190
+ }
191
+ }
192
+ } else {
193
+ if (kebabName.startsWith(partial)) {
194
+ completions.push(`--${kebabName}`);
195
+ }
196
+ }
197
+ }
198
+
199
+ // Add built-in flags
200
+ const builtinFlags = [
201
+ "--dry-run",
202
+ "--yes",
203
+ "--verbose",
204
+ "--no-preview",
205
+ "--no-generated-stamp",
206
+ "--llm",
207
+ "--help",
208
+ ];
209
+ for (const flag of builtinFlags) {
210
+ if (flag.startsWith(`--${partial}`)) {
211
+ completions.push(flag);
212
+ }
213
+ }
214
+ }
215
+
216
+ return completions;
217
+ };
218
+
219
+ // =============================================================================
220
+ // Tree Building
221
+ // =============================================================================
222
+
223
+ /**
224
+ * Generator loader function type - passed in to avoid circular dependencies.
225
+ */
226
+ export type GeneratorLoader = (
227
+ indexPath: string,
228
+ ) => Promise<GeneratorDefinition>;
229
+
230
+ /**
231
+ * Get completions for a specific position in the command.
232
+ */
233
+ const getCompletionsAtPosition = (
234
+ node: CompletionNode,
235
+ args: string[],
236
+ generators: Map<string, GeneratorInfo>,
237
+ ): string[] => {
238
+ // Navigate to the correct position in the tree
239
+ let current = node;
240
+ const pathSoFar: string[] = [];
241
+
242
+ for (const arg of args) {
243
+ // Skip flags and empty args
244
+ if (arg.startsWith("-") || !arg) continue;
245
+
246
+ const child = current.children.get(arg);
247
+ if (child) {
248
+ current = child;
249
+ pathSoFar.push(arg);
250
+ } else {
251
+ // Partial match - don't add to path, keep current node
252
+ break;
253
+ }
254
+ }
255
+
256
+ // Check if we have subcommands available
257
+ const subcommands = [...current.children.keys()];
258
+
259
+ // Check if we're at a generator
260
+ const generatorKey = pathSoFar.join("/");
261
+ const generatorInfo = generators.get(generatorKey);
262
+
263
+ // Get the last arg for context
264
+ const lastArg = args[args.length - 1] || "";
265
+ const line = args.join(" ");
266
+
267
+ // If we're at a generator
268
+ if (generatorInfo) {
269
+ // If the last arg starts with -, provide flag completions
270
+ if (lastArg.startsWith("-")) {
271
+ return getArgumentCompletions(generatorInfo.prompts, line, lastArg);
272
+ }
273
+
274
+ // Check if this generator has a positional prompt
275
+ const positionalPrompt = generatorInfo.prompts.find((p) => p.positional);
276
+
277
+ // If there are no subcommands and this is a leaf generator
278
+ if (subcommands.length === 0) {
279
+ // Count non-flag args after the generator path
280
+ const nonFlagArgs = args.filter((a) => !a.startsWith("-"));
281
+ const argsAfterGenerator = nonFlagArgs.length - pathSoFar.length;
282
+
283
+ // If we have a positional prompt and haven't provided the positional arg yet
284
+ if (positionalPrompt && argsAfterGenerator === 0) {
285
+ // If the positional is a path, provide path completions
286
+ if (isPathPrompt(positionalPrompt)) {
287
+ return getPathCompletions(lastArg || "");
288
+ }
289
+ // Otherwise show flags (they can type the positional or use flags)
290
+ return getArgumentCompletions(generatorInfo.prompts, line, "", true);
291
+ }
292
+
293
+ // If positional already provided or no positional, show flags
294
+ return getArgumentCompletions(generatorInfo.prompts, line, "", true);
295
+ }
296
+
297
+ // If there are both subcommands and this is a generator,
298
+ // show subcommands (user might want to go deeper)
299
+ return subcommands;
300
+ }
301
+
302
+ // Not at a generator, show subcommands
303
+ // Only filter if the last arg is a partial (not in pathSoFar)
304
+ const lastPathSeg = pathSoFar[pathSoFar.length - 1];
305
+ const isPartialArg =
306
+ lastArg && !lastArg.startsWith("-") && lastArg !== lastPathSeg;
307
+
308
+ if (isPartialArg) {
309
+ return subcommands.filter((cmd) => cmd.startsWith(lastArg));
310
+ }
311
+
312
+ return subcommands;
313
+ };
314
+
315
+ /**
316
+ * Load all generators and cache their prompts.
317
+ */
318
+ const loadAllGenerators = async (
319
+ node: CompletionNode,
320
+ loadGenerator: GeneratorLoader,
321
+ currentPath: string[] = [],
322
+ cache: Map<string, GeneratorInfo> = new Map(),
323
+ ): Promise<Map<string, GeneratorInfo>> => {
324
+ for (const [name, child] of node.children) {
325
+ const childPath = [...currentPath, name];
326
+ const pathKey = childPath.join("/");
327
+
328
+ if (child.indexPath) {
329
+ try {
330
+ const generator = await loadGenerator(child.indexPath);
331
+ cache.set(pathKey, {
332
+ path: childPath,
333
+ prompts: generator.prompts,
334
+ });
335
+ } catch {
336
+ // Failed to load generator, skip
337
+ }
338
+ }
339
+
340
+ if (child.children.size > 0) {
341
+ await loadAllGenerators(child, loadGenerator, childPath, cache);
342
+ }
343
+ }
344
+
345
+ return cache;
346
+ };
347
+
348
+ // =============================================================================
349
+ // Completion Initialization
350
+ // =============================================================================
351
+
352
+ /**
353
+ * Initialize shell completion for the summon CLI.
354
+ *
355
+ * This should be called early in the CLI lifecycle, before commander parsing,
356
+ * because omelette needs to intercept completion requests.
357
+ *
358
+ * @param generatorTree - The root of the generator tree
359
+ * @param loadGenerator - Function to load a generator from its path
360
+ * @returns The omelette instance (for setup/cleanup methods)
361
+ */
362
+ export const initCompletion = async (
363
+ generatorTree: CompletionNode,
364
+ loadGenerator: GeneratorLoader,
365
+ ): Promise<omelette.Instance> => {
366
+ // Load all generators to get their prompts
367
+ const generators = await loadAllGenerators(generatorTree, loadGenerator);
368
+
369
+ // Create the completion instance
370
+ // We use a template with multiple segments to handle deep hierarchies
371
+ // The "complete" event fires for all positions
372
+ const complete = omelette("summon <arg1> <arg2> <arg3> <arg4> <arg5>");
373
+
374
+ // Handle completion dynamically for all positions
375
+ // The "complete" event receives the fragment name (arg1, arg2, etc.) and context
376
+ complete.on("complete", (fragment, { line, reply, before }) => {
377
+ // Parse the current line to determine what to complete
378
+ // Remove 'summon' and filter out internal flags like --generators
379
+ let args = line.split(/\s+/).filter(Boolean).slice(1);
380
+
381
+ // Filter out internal CLI flags that shouldn't be part of completion context
382
+ const internalFlags = [
383
+ "--generators",
384
+ "-g",
385
+ "--compbash",
386
+ "--compzsh",
387
+ "--compfish",
388
+ "--compgen",
389
+ ];
390
+ args = args.filter((arg, idx) => {
391
+ // Skip internal flags and their values
392
+ if (internalFlags.includes(arg)) return false;
393
+ // Skip the value after an internal flag
394
+ if (idx > 0 && internalFlags.includes(args[idx - 1])) return false;
395
+ return true;
396
+ });
397
+
398
+ // Debug logging (only when SUMMON_DEBUG is set)
399
+ if (process.env.SUMMON_DEBUG) {
400
+ console.error("[completion] fragment:", fragment);
401
+ console.error("[completion] line:", line);
402
+ console.error("[completion] before:", before);
403
+ console.error("[completion] args (filtered):", args);
404
+ }
405
+
406
+ // If before is empty, we're at the start of a new argument
407
+ // If not, we're completing a partial argument
408
+ const completions = getCompletionsAtPosition(
409
+ generatorTree,
410
+ args,
411
+ generators,
412
+ );
413
+
414
+ if (process.env.SUMMON_DEBUG) {
415
+ console.error("[completion] completions:", completions);
416
+ }
417
+
418
+ reply(completions);
419
+ });
420
+
421
+ // Initialize omelette (this intercepts --completion args)
422
+ complete.init();
423
+
424
+ return complete;
425
+ };
426
+
427
+ /**
428
+ * Check if the current invocation is a completion request.
429
+ * This allows us to skip normal CLI processing for completion.
430
+ */
431
+ export const isCompletionRequest = (): boolean => {
432
+ const args = process.argv;
433
+ return (
434
+ args.includes("--completion") ||
435
+ args.includes("--completion-fish") ||
436
+ args.includes("--compzsh") ||
437
+ args.includes("--compbash") ||
438
+ args.includes("--compfish") ||
439
+ // Omelette internal completion trigger
440
+ args.some((arg) => arg.startsWith("--compgen"))
441
+ );
442
+ };
443
+
444
+ /**
445
+ * Check if this is a setup or cleanup request.
446
+ */
447
+ export const isSetupRequest = (): boolean => {
448
+ const args = process.argv;
449
+ return (
450
+ args.includes("--setup-completion") || args.includes("--cleanup-completion")
451
+ );
452
+ };
453
+
454
+ /**
455
+ * Handle setup/cleanup requests.
456
+ */
457
+ export const handleSetupRequest = (complete: omelette.Instance): void => {
458
+ const args = process.argv;
459
+
460
+ if (args.includes("--setup-completion")) {
461
+ try {
462
+ complete.setupShellInitFile();
463
+ console.log("Shell completion installed successfully!");
464
+ console.log(
465
+ "Please restart your shell or run: source ~/.zshrc (or ~/.bashrc)",
466
+ );
467
+ } catch (err) {
468
+ console.error("Failed to install completion:", (err as Error).message);
469
+ console.error("\nManual installation:");
470
+ console.error(" Zsh: echo '. <(summon --completion)' >> ~/.zshrc");
471
+ console.error(
472
+ " Bash: summon --completion >> ~/.summon-completion.sh && echo 'source ~/.summon-completion.sh' >> ~/.bash_profile",
473
+ );
474
+ console.error(
475
+ " Fish: echo 'summon --completion-fish | source' >> ~/.config/fish/config.fish",
476
+ );
477
+ process.exit(1);
478
+ }
479
+ process.exit(0);
480
+ }
481
+
482
+ if (args.includes("--cleanup-completion")) {
483
+ try {
484
+ complete.cleanupShellInitFile();
485
+ console.log("Shell completion removed successfully!");
486
+ } catch (err) {
487
+ console.error("Failed to remove completion:", (err as Error).message);
488
+ process.exit(1);
489
+ }
490
+ process.exit(0);
491
+ }
492
+ };