* 用户确认执行
(
command: string,
workingDirectory: string,
options: ConfirmationOptions,
params: Record<string, any>
)
| 246 | * 用户确认执行 |
| 247 | */ |
| 248 | protected async confirmExecution( |
| 249 | command: string, |
| 250 | workingDirectory: string, |
| 251 | options: ConfirmationOptions, |
| 252 | params: Record<string, any> |
| 253 | ): Promise<boolean> { |
| 254 | // 显示命令信息 |
| 255 | console.log(chalk.blue('\n📋 建议执行以下命令:')); |
| 256 | console.log(chalk.cyan(` ${command}`)); |
| 257 | |
| 258 | // 显示额外信息 |
| 259 | const description = this.getExecutionDescription(params); |
| 260 | if (description) { |
| 261 | console.log(chalk.gray(` 说明: ${description}`)); |
| 262 | } |
| 263 | |
| 264 | console.log(chalk.gray(` 工作目录: ${workingDirectory}`)); |
| 265 | console.log(chalk.gray(` 风险级别: ${this.getRiskLevelDisplay(options.riskLevel!)}`)); |
| 266 | |
| 267 | // 显示预览信息 |
| 268 | if (options.showPreview) { |
| 269 | const previewInfo = await this.getExecutionPreview(command, workingDirectory, params); |
| 270 | if (previewInfo) { |
| 271 | console.log(chalk.blue('\n🔍 执行预览:')); |
| 272 | console.log(chalk.gray(previewInfo)); |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | // 用户确认 |
| 277 | const { confirm } = await inquirer.prompt([ |
| 278 | { |
| 279 | type: 'confirm', |
| 280 | name: 'confirm', |
| 281 | message: options.confirmMessage || '是否执行此命令?', |
| 282 | default: false, |
| 283 | }, |
| 284 | ]); |
| 285 | |
| 286 | return confirm; |
| 287 | } |
| 288 | |
| 289 | /** |
| 290 | * 执行命令 |
nothing calls this directly
no test coverage detected