mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-08 17:35:36 +08:00
Add doctor cache check and version management to ensure environment validation
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -37,6 +37,8 @@ class BuildTargetCommand extends BaseCommand
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$this->checkDoctorCache();
|
||||
|
||||
// resolve legacy options to new options
|
||||
V2CompatLayer::convertOptions($this->input);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -56,6 +56,8 @@ class DownloadCommand extends BaseCommand
|
||||
return $this->handleClean();
|
||||
}
|
||||
|
||||
$this->checkDoctorCache();
|
||||
|
||||
$downloader = new ArtifactDownloader(DownloaderOptions::extractFromConsoleOptions($this->input->getOptions()));
|
||||
|
||||
// arguments
|
||||
|
||||
Reference in New Issue
Block a user