use prompts to ask

This commit is contained in:
crazywhalecc 2023-10-31 01:48:49 +08:00
parent 98b906db40
commit e637cce6f2
No known key found for this signature in database
GPG Key ID: 1F4BDD59391F2680

View File

@ -8,8 +8,8 @@ use SPC\doctor\CheckListHandler;
use SPC\doctor\CheckResult; use SPC\doctor\CheckResult;
use SPC\exception\RuntimeException; use SPC\exception\RuntimeException;
use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Question\ConfirmationQuestion; use function Laravel\Prompts\confirm;
#[AsCommand('doctor', 'Diagnose whether the current environment can compile normally')] #[AsCommand('doctor', 'Diagnose whether the current environment can compile normally')]
class DoctorCommand extends BaseCommand class DoctorCommand extends BaseCommand
@ -49,9 +49,8 @@ class DoctorCommand extends BaseCommand
throw new RuntimeException('Some check items can not be fixed !'); throw new RuntimeException('Some check items can not be fixed !');
case FIX_POLICY_PROMPT: case FIX_POLICY_PROMPT:
if ($result->getFixItem() !== '') { if ($result->getFixItem() !== '') {
$helper = new QuestionHelper(); $question = confirm('Do you want to fix it?');
$question = new ConfirmationQuestion('Do you want to fix it? [Y/n] ', true); if ($question) {
if ($helper->ask($this->input, $this->output, $question)) {
$checker->emitFix($this->output, $result); $checker->emitFix($this->output, $result);
} else { } else {
throw new RuntimeException('You cancelled fix'); throw new RuntimeException('You cancelled fix');