* 处理预检查失败 - 提供建议选项
(
preCheckResult: CommandPreCheckResult,
workingDirectory: string,
confirmationOptions: ConfirmationOptions
)
| 189 | * 处理预检查失败 - 提供建议选项 |
| 190 | */ |
| 191 | protected async handlePreCheckFailure( |
| 192 | preCheckResult: CommandPreCheckResult, |
| 193 | workingDirectory: string, |
| 194 | confirmationOptions: ConfirmationOptions |
| 195 | ): Promise<CommandExecutionResult> { |
| 196 | console.log(chalk.yellow(`⚠️ 预检查发现问题: ${preCheckResult.message}`)); |
| 197 | |
| 198 | if (preCheckResult.suggestions && preCheckResult.suggestions.length > 0) { |
| 199 | console.log(chalk.blue('\n💡 建议的替代方案:')); |
| 200 | |
| 201 | const choices = preCheckResult.suggestions.map((suggestion, index) => ({ |
| 202 | name: `${chalk.cyan(suggestion.command)} ${chalk.gray(`- ${suggestion.description}`)}`, |
| 203 | value: index, |
| 204 | short: suggestion.command, |
| 205 | })); |
| 206 | |
| 207 | choices.push({ name: chalk.gray('取消执行'), value: -1, short: '取消' }); |
| 208 | |
| 209 | const { selectedIndex } = await inquirer.prompt([ |
| 210 | { |
| 211 | type: 'list', |
| 212 | name: 'selectedIndex', |
| 213 | message: '请选择要执行的命令:', |
| 214 | choices, |
| 215 | pageSize: 10, |
| 216 | }, |
| 217 | ]); |
| 218 | |
| 219 | if (selectedIndex === -1) { |
| 220 | return { |
| 221 | success: false, |
| 222 | error: '用户取消执行', |
| 223 | cancelled: true, |
| 224 | }; |
| 225 | } |
| 226 | |
| 227 | const selectedSuggestion = preCheckResult.suggestions[selectedIndex]; |
| 228 | return await this.executeCommand( |
| 229 | selectedSuggestion.command, |
| 230 | workingDirectory, |
| 231 | { |
| 232 | ...confirmationOptions, |
| 233 | riskLevel: selectedSuggestion.riskLevel || confirmationOptions.riskLevel, |
| 234 | }, |
| 235 | {} |
| 236 | ); |
| 237 | } |
| 238 | |
| 239 | return { |
| 240 | success: false, |
| 241 | error: preCheckResult.message || '预检查失败', |
| 242 | }; |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * 用户确认执行 |
nothing calls this directly
no test coverage detected