2023-04-22 17:45:43 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace SPC\command;
|
|
|
|
|
|
2023-04-22 21:23:12 +08:00
|
|
|
use SPC\doctor\CheckListHandler;
|
2023-04-22 17:45:43 +08:00
|
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
|
|
|
|
|
|
|
|
|
#[AsCommand('doctor', 'Diagnose whether the current environment can compile normally')]
|
|
|
|
|
class DoctorCommand extends BaseCommand
|
|
|
|
|
{
|
2023-07-17 21:10:49 +08:00
|
|
|
public function configure()
|
|
|
|
|
{
|
|
|
|
|
$this->addOption('auto-fix', null, null, 'Automatically fix failed items (if possible)');
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-22 17:45:43 +08:00
|
|
|
public function handle(): int
|
|
|
|
|
{
|
2023-04-22 21:23:12 +08:00
|
|
|
try {
|
|
|
|
|
$checker = new CheckListHandler($this->input, $this->output);
|
2023-07-17 21:10:49 +08:00
|
|
|
$checker->runCheck($this->input->getOption('auto-fix') ? FIX_POLICY_AUTOFIX : FIX_POLICY_PROMPT);
|
2023-04-22 21:23:12 +08:00
|
|
|
$this->output->writeln('<info>Doctor check complete !</info>');
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
$this->output->writeln('<error>' . $e->getMessage() . '</error>');
|
2023-04-30 12:42:19 +08:00
|
|
|
pcntl_signal(SIGINT, SIG_IGN);
|
2023-08-06 10:43:20 +08:00
|
|
|
return static::FAILURE;
|
2023-04-22 21:23:12 +08:00
|
|
|
}
|
2023-08-06 10:43:20 +08:00
|
|
|
return static::SUCCESS;
|
2023-04-22 17:45:43 +08:00
|
|
|
}
|
|
|
|
|
}
|