* 执行命令
(
command: string,
workingDirectory: string,
options: ConfirmationOptions,
params: Record<string, any>
)
| 290 | * 执行命令 |
| 291 | */ |
| 292 | protected async executeCommand( |
| 293 | command: string, |
| 294 | workingDirectory: string, |
| 295 | options: ConfirmationOptions, |
| 296 | params: Record<string, any> |
| 297 | ): Promise<CommandExecutionResult> { |
| 298 | console.log(chalk.blue('\n⚡ 正在执行命令...')); |
| 299 | const startTime = Date.now(); |
| 300 | |
| 301 | try { |
| 302 | const result = await execAsync(command, { |
| 303 | cwd: workingDirectory, |
| 304 | timeout: options.timeout, |
| 305 | }); |
| 306 | |
| 307 | const duration = Date.now() - startTime; |
| 308 | |
| 309 | console.log(chalk.green(`✅ 命令执行成功 (${duration}ms)`)); |
| 310 | |
| 311 | if (result.stdout) { |
| 312 | console.log('\n📤 输出:'); |
| 313 | console.log(result.stdout); |
| 314 | } |
| 315 | |
| 316 | // 后处理结果 |
| 317 | const processedResult = await this.postProcessResult(result, params); |
| 318 | |
| 319 | return { |
| 320 | success: true, |
| 321 | command, |
| 322 | stdout: result.stdout, |
| 323 | stderr: result.stderr, |
| 324 | workingDirectory, |
| 325 | duration, |
| 326 | data: processedResult, |
| 327 | }; |
| 328 | } catch (error: any) { |
| 329 | console.log(chalk.red(`❌ 命令执行失败: ${error.message}`)); |
| 330 | |
| 331 | if (error.stdout) { |
| 332 | console.log('\n📤 标准输出:'); |
| 333 | console.log(error.stdout); |
| 334 | } |
| 335 | |
| 336 | if (error.stderr) { |
| 337 | console.log('\n🚨 错误输出:'); |
| 338 | console.log(error.stderr); |
| 339 | } |
| 340 | |
| 341 | return { |
| 342 | success: false, |
| 343 | error: error.message, |
| 344 | command, |
| 345 | stdout: error.stdout || '', |
| 346 | stderr: error.stderr || '', |
| 347 | exitCode: error.code, |
| 348 | workingDirectory, |
| 349 | }; |
nothing calls this directly
no test coverage detected