MCPcopy
hub / github.com/Fission-AI/OpenSpec / resolveShellOrExit

Method resolveShellOrExit

src/commands/completion.ts:42–74  ·  view source on GitHub ↗

* Resolve shell parameter or exit with error * * @param shell - The shell parameter (may be undefined) * @param operationName - Name of the operation (for error messages) * @returns Resolved shell or null if should exit

(shell: string | undefined, operationName: string)

Source from the content-addressed store, hash-verified

40 * @returns Resolved shell or null if should exit
41 */
42 private resolveShellOrExit(shell: string | undefined, operationName: string): SupportedShell | null {
43 const normalizedShell = this.normalizeShell(shell);
44
45 if (!normalizedShell) {
46 const detectionResult = detectShell();
47
48 if (detectionResult.shell && CompletionFactory.isSupported(detectionResult.shell)) {
49 return detectionResult.shell;
50 }
51
52 // Shell was detected but not supported
53 if (detectionResult.detected && !detectionResult.shell) {
54 console.error(`Error: Shell '${detectionResult.detected}' is not supported yet. Currently supported: ${CompletionFactory.getSupportedShells().join(', ')}`);
55 process.exitCode = 1;
56 return null;
57 }
58
59 // No shell specified and cannot auto-detect
60 console.error('Error: Could not auto-detect shell. Please specify shell explicitly.');
61 console.error(`Usage: openspec completion ${operationName} [shell]`);
62 console.error(`Currently supported: ${CompletionFactory.getSupportedShells().join(', ')}`);
63 process.exitCode = 1;
64 return null;
65 }
66
67 if (!CompletionFactory.isSupported(normalizedShell)) {
68 console.error(`Error: Shell '${normalizedShell}' is not supported yet. Currently supported: ${CompletionFactory.getSupportedShells().join(', ')}`);
69 process.exitCode = 1;
70 return null;
71 }
72
73 return normalizedShell;
74 }
75
76 /**
77 * Generate completion script and output to stdout

Callers 3

generateMethod · 0.95
installMethod · 0.95
uninstallMethod · 0.95

Calls 4

normalizeShellMethod · 0.95
detectShellFunction · 0.85
isSupportedMethod · 0.80
getSupportedShellsMethod · 0.80

Tested by

no test coverage detected