mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-19 13:24:51 +08:00
Add dev commands: is-installed, shell (for debugging package status)
This commit is contained in:
parent
2f09ace82f
commit
baddd60113
34
src/StaticPHP/Command/Dev/IsInstalledCommand.php
Normal file
34
src/StaticPHP/Command/Dev/IsInstalledCommand.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Command\Dev;
|
||||
|
||||
use StaticPHP\Command\BaseCommand;
|
||||
use StaticPHP\Package\PackageInstaller;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
#[AsCommand('dev:is-installed', 'Check if a package is installed correctly', ['is-installed'], true)]
|
||||
class IsInstalledCommand extends BaseCommand
|
||||
{
|
||||
public function configure(): void
|
||||
{
|
||||
$this->no_motd = true;
|
||||
$this->addArgument('package', InputArgument::REQUIRED, 'The package name to check installation status');
|
||||
}
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$installer = new PackageInstaller();
|
||||
$package = $this->input->getArgument('package');
|
||||
$installer->addInstallPackage($package);
|
||||
$installed = $installer->isPackageInstalled($package);
|
||||
if ($installed) {
|
||||
$this->output->writeln("<info>Package [{$package}] is installed correctly.</info>");
|
||||
return static::SUCCESS;
|
||||
}
|
||||
$this->output->writeln("<error>Package [{$package}] is not installed.</error>");
|
||||
return static::FAILURE;
|
||||
}
|
||||
}
|
||||
33
src/StaticPHP/Command/Dev/ShellCommand.php
Normal file
33
src/StaticPHP/Command/Dev/ShellCommand.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Command\Dev;
|
||||
|
||||
use StaticPHP\Command\BaseCommand;
|
||||
use StaticPHP\Runtime\SystemTarget;
|
||||
use StaticPHP\Util\GlobalEnvManager;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
|
||||
#[AsCommand('dev:shell')]
|
||||
class ShellCommand extends BaseCommand
|
||||
{
|
||||
public function handle(): int
|
||||
{
|
||||
// need to init global env first
|
||||
GlobalEnvManager::afterInit();
|
||||
|
||||
$this->output->writeln("Entering interactive shell. Type 'exit' to leave.");
|
||||
|
||||
if (SystemTarget::isUnix()) {
|
||||
passthru('PS1=\'[StaticPHP] > \' /bin/bash', $code);
|
||||
return $code;
|
||||
}
|
||||
if (SystemTarget::getTargetOS() === 'Windows') {
|
||||
passthru('cmd.exe', $code);
|
||||
return $code;
|
||||
}
|
||||
$this->output->writeln('<error>Unsupported OS for shell command.</error>');
|
||||
return static::FAILURE;
|
||||
}
|
||||
}
|
||||
@ -6,6 +6,8 @@ namespace StaticPHP;
|
||||
|
||||
use StaticPHP\Command\BuildLibsCommand;
|
||||
use StaticPHP\Command\BuildTargetCommand;
|
||||
use StaticPHP\Command\Dev\IsInstalledCommand;
|
||||
use StaticPHP\Command\Dev\ShellCommand;
|
||||
use StaticPHP\Command\DoctorCommand;
|
||||
use StaticPHP\Command\DownloadCommand;
|
||||
use StaticPHP\Command\ExtractCommand;
|
||||
@ -47,6 +49,10 @@ class ConsoleApplication extends Application
|
||||
new BuildLibsCommand(),
|
||||
new ExtractCommand(),
|
||||
new SPCConfigCommand(),
|
||||
|
||||
// dev commands
|
||||
new ShellCommand(),
|
||||
new IsInstalledCommand(),
|
||||
]);
|
||||
|
||||
// add additional commands from registries
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user