Move all interactive input to construct

This commit is contained in:
crazywhalecc
2026-03-09 11:04:18 +08:00
parent 1f768ffc64
commit 77e129881a
11 changed files with 96 additions and 61 deletions

View File

@@ -18,7 +18,7 @@ use function Laravel\Prompts\confirm;
readonly class Doctor
{
public function __construct(private ?OutputInterface $output = null, private int $auto_fix = FIX_POLICY_PROMPT)
public function __construct(private ?OutputInterface $output = null, private int $auto_fix = FIX_POLICY_PROMPT, public readonly bool $interactive = true)
{
// debug shows all loaded doctor items
$items = DoctorLoader::getDoctorItems();
@@ -53,13 +53,13 @@ readonly class Doctor
* Check all valid check items.
* @return bool true if all checks passed, false otherwise
*/
public function checkAll(bool $interactive = true): bool
public function checkAll(): bool
{
if ($interactive) {
if ($this->interactive) {
InteractiveTerm::notice('Starting doctor checks ...');
}
foreach ($this->getValidCheckList() as $check) {
if (!$this->checkItem($check, $interactive)) {
if (!$this->checkItem($check)) {
return false;
}
}
@@ -72,7 +72,7 @@ readonly class Doctor
* @param CheckItem|string $check The check item to be checked
* @return bool True if the check passed or was fixed, false otherwise
*/
public function checkItem(CheckItem|string $check, bool $interactive = true): bool
public function checkItem(CheckItem|string $check): bool
{
if (is_string($check)) {
$found = null;
@@ -88,7 +88,7 @@ readonly class Doctor
}
$check = $found;
}
$prepend = $interactive ? ' - ' : '';
$prepend = $this->interactive ? ' - ' : '';
$this->output?->write("{$prepend}Checking <comment>{$check->item_name}</comment> ... ");
// call check

View File

@@ -59,8 +59,8 @@ class LinuxMuslCheck
#[FixItem('fix-musl-wrapper')]
public function fixMusl(): bool
{
$downloader = new ArtifactDownloader();
$downloader->add('musl-wrapper')->download(false);
$downloader = new ArtifactDownloader(interactive: false);
$downloader->add('musl-wrapper')->download();
$extractor = new ArtifactExtractor(ApplicationContext::get(ArtifactCache::class));
$extractor->extract('musl-wrapper');
@@ -96,9 +96,9 @@ class LinuxMuslCheck
Shell::passthruCallback(function () {
InteractiveTerm::advance();
});
$downloader = new ArtifactDownloader();
$downloader = new ArtifactDownloader(interactive: false);
$extractor = new ArtifactExtractor(ApplicationContext::get(ArtifactCache::class));
$downloader->add('musl-toolchain')->download(false);
$downloader->add('musl-toolchain')->download();
$extractor->extract('musl-toolchain');
$pkg_root = PKG_ROOT_PATH . '/musl-toolchain';
f_passthru("{$prefix}cp -rf {$pkg_root}/* /usr/local/musl");

View File

@@ -45,9 +45,9 @@ class PkgConfigCheck
public function fix(): bool
{
ApplicationContext::set('elephant', true);
$installer = new PackageInstaller(['dl-binary-only' => true]);
$installer = new PackageInstaller(['dl-binary-only' => true], interactive: false);
$installer->addInstallPackage('pkg-config');
$installer->run(false, true);
$installer->run(true);
return true;
}
}

View File

@@ -30,9 +30,9 @@ class Re2cVersionCheck
#[FixItem('build-re2c')]
public function buildRe2c(): bool
{
$installer = new PackageInstaller();
$installer = new PackageInstaller(interactive: false);
$installer->addInstallPackage('re2c');
$installer->run(false);
$installer->run(true);
return true;
}
}

View File

@@ -107,7 +107,7 @@ class WindowsToolCheck
{
$installer = new PackageInstaller();
$installer->addInstallPackage('strawberry-perl');
$installer->run(false);
$installer->run(true);
GlobalEnvManager::addPathIfNotExists(PKG_ROOT_PATH . '\strawberry-perl');
return true;
}
@@ -116,27 +116,27 @@ class WindowsToolCheck
public function installSDK(): bool
{
FileSystem::removeDir(getenv('PHP_SDK_PATH'));
$installer = new PackageInstaller();
$installer = new PackageInstaller(interactive: false);
$installer->addInstallPackage('php-sdk-binary-tools');
$installer->run(false);
$installer->run(true);
return true;
}
#[FixItem('install-nasm')]
public function installNasm(): bool
{
$installer = new PackageInstaller();
$installer = new PackageInstaller(interactive: false);
$installer->addInstallPackage('nasm');
$installer->run(false);
$installer->run(true);
return true;
}
#[FixItem('install-vswhere')]
public function installVSWhere(): bool
{
$installer = new PackageInstaller();
$installer = new PackageInstaller(interactive: false);
$installer->addInstallPackage('vswhere');
$installer->run(false);
$installer->run(true);
return true;
}
}

View File

@@ -34,9 +34,9 @@ class ZigCheck
#[FixItem('install-zig')]
public function installZig(): bool
{
$installer = new PackageInstaller();
$installer = new PackageInstaller(interactive: false);
$installer->addInstallPackage('zig');
$installer->run(false);
$installer->run(true);
return $installer->isPackageInstalled('zig');
}
}