Add doctor cache check and version management to ensure environment validation

This commit is contained in:
crazywhalecc
2026-02-28 10:32:50 +08:00
parent 7623b9e673
commit c218aef947
8 changed files with 94 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace StaticPHP\Command;
use StaticPHP\DI\ApplicationContext;
use StaticPHP\Doctor\Doctor;
use StaticPHP\Exception\ExceptionHandler;
use StaticPHP\Exception\SPCException;
use Symfony\Component\Console\Command\Command;
@@ -118,6 +119,21 @@ abstract class BaseCommand extends Command
}
}
/**
* Warn the user if doctor has not been run (or is outdated).
* Set SPC_SKIP_DOCTOR_CHECK=1 to suppress.
*/
protected function checkDoctorCache(): void
{
if (getenv('SPC_SKIP_DOCTOR_CHECK') || Doctor::isHealthy()) {
return;
}
$this->output->writeln('');
$this->output->writeln('<comment>[WARNING] Please run `spc doctor` first to verify your build environment.</comment>');
$this->output->writeln('');
sleep(2);
}
protected function getOption(string $name): mixed
{
return $this->input->getOption($name);

View File

@@ -44,6 +44,8 @@ class BuildLibsCommand extends BaseCommand
public function handle(): int
{
$this->checkDoctorCache();
$libs = parse_comma_list($this->input->getArgument('libraries'));
$installer = new PackageInstaller($this->input->getOptions());

View File

@@ -37,6 +37,8 @@ class BuildTargetCommand extends BaseCommand
public function handle(): int
{
$this->checkDoctorCache();
// resolve legacy options to new options
V2CompatLayer::convertOptions($this->input);

View File

@@ -26,6 +26,7 @@ class DoctorCommand extends BaseCommand
};
$doctor = new Doctor($this->output, $fix_policy);
if ($doctor->checkAll()) {
Doctor::markPassed();
$this->output->writeln('<info>Doctor check complete !</info>');
return static::SUCCESS;
}

View File

@@ -56,6 +56,8 @@ class DownloadCommand extends BaseCommand
return $this->handleClean();
}
$this->checkDoctorCache();
$downloader = new ArtifactDownloader(DownloaderOptions::extractFromConsoleOptions($this->input->getOptions()));
// arguments