diff --git a/src/cli/discovery.ts b/src/cli/discovery.ts index 9a8a1183bf9..9308e497c79 100644 --- a/src/cli/discovery.ts +++ b/src/cli/discovery.ts @@ -164,6 +164,9 @@ const renderedAnswer = (text: string, exitCode = 0): DiscoveryAnswer => ({ text, exitCode, }); +const failureAnswer = ( + ...inputs: Parameters +): DiscoveryAnswer => renderedAnswer(renderFailure(...inputs), 1); const markupAnswer = (text: string): DiscoveryAnswer => ({ kind: "markup", text, @@ -268,14 +271,11 @@ const schemaAnswer = ( return answer(`Error: ${failure.message}`, 1); // A selected format receives the same structured diagnostic as any // other unknown command, not terminal text. - return renderedAnswer( - renderFailure( - failure, - { command, duration: `${Math.round(performance.now() - started)}ms` }, - cta, - cliFailurePresentation(controls, false), - ), - 1, + return failureAnswer( + failure, + { command, duration: `${Math.round(performance.now() - started)}ms` }, + cta, + cliFailurePresentation(controls, false), ); } if (!validation.ok) @@ -321,28 +321,25 @@ const retiredMcpAnswer = ( const controls = readCliOutputArguments(global); const sensitive = declaredSensitiveValues(global.command); const text = (value: string): string => redactExplicitText(value, sensitive); - return renderedAnswer( - renderFailure( - { - code: "MCP_MODE_REMOVED", - message: text( - `Per-command --mcp has been removed. Use '${cli.name} mcp' to start REA's MCP server.`, - ), - }, - { - command: text(global.command[0] ?? cli.name), - duration: `${Math.round(performance.now() - invocation.started)}ms`, - }, - { - description: text("Suggested command:"), - commands: [{ command: text(`${cli.name} mcp`) }], - }, - cliFailurePresentation( - controls, - invocation.stdoutIsTerminal && !controls.formatExplicit, + return failureAnswer( + { + code: "MCP_MODE_REMOVED", + message: text( + `Per-command --mcp has been removed. Use '${cli.name} mcp' to start REA's MCP server.`, ), + }, + { + command: text(global.command[0] ?? cli.name), + duration: `${Math.round(performance.now() - invocation.started)}ms`, + }, + { + description: text("Suggested command:"), + commands: [{ command: text(`${cli.name} mcp`) }], + }, + cliFailurePresentation( + controls, + invocation.stdoutIsTerminal && !controls.formatExplicit, ), - 1, ); }; @@ -379,17 +376,14 @@ const unknownCommandAnswer = ( suggestion, additionalCommands: notice, }); - return renderedAnswer( - renderFailure( - failure, - { - command, - duration: `${Math.round(performance.now() - started)}ms`, - }, - cta, - cliFailurePresentation(controls, human, selectedFormat), - ), - 1, + return failureAnswer( + failure, + { + command, + duration: `${Math.round(performance.now() - started)}ms`, + }, + cta, + cliFailurePresentation(controls, human, selectedFormat), ); };