Skip to content

Commit baddd60

Browse files
committed
Add dev commands: is-installed, shell (for debugging package status)
1 parent 2f09ace commit baddd60

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace StaticPHP\Command\Dev;
6+
7+
use StaticPHP\Command\BaseCommand;
8+
use StaticPHP\Package\PackageInstaller;
9+
use Symfony\Component\Console\Attribute\AsCommand;
10+
use Symfony\Component\Console\Input\InputArgument;
11+
12+
#[AsCommand('dev:is-installed', 'Check if a package is installed correctly', ['is-installed'], true)]
13+
class IsInstalledCommand extends BaseCommand
14+
{
15+
public function configure(): void
16+
{
17+
$this->no_motd = true;
18+
$this->addArgument('package', InputArgument::REQUIRED, 'The package name to check installation status');
19+
}
20+
21+
public function handle(): int
22+
{
23+
$installer = new PackageInstaller();
24+
$package = $this->input->getArgument('package');
25+
$installer->addInstallPackage($package);
26+
$installed = $installer->isPackageInstalled($package);
27+
if ($installed) {
28+
$this->output->writeln("<info>Package [{$package}] is installed correctly.</info>");
29+
return static::SUCCESS;
30+
}
31+
$this->output->writeln("<error>Package [{$package}] is not installed.</error>");
32+
return static::FAILURE;
33+
}
34+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace StaticPHP\Command\Dev;
6+
7+
use StaticPHP\Command\BaseCommand;
8+
use StaticPHP\Runtime\SystemTarget;
9+
use StaticPHP\Util\GlobalEnvManager;
10+
use Symfony\Component\Console\Attribute\AsCommand;
11+
12+
#[AsCommand('dev:shell')]
13+
class ShellCommand extends BaseCommand
14+
{
15+
public function handle(): int
16+
{
17+
// need to init global env first
18+
GlobalEnvManager::afterInit();
19+
20+
$this->output->writeln("Entering interactive shell. Type 'exit' to leave.");
21+
22+
if (SystemTarget::isUnix()) {
23+
passthru('PS1=\'[StaticPHP] > \' /bin/bash', $code);
24+
return $code;
25+
}
26+
if (SystemTarget::getTargetOS() === 'Windows') {
27+
passthru('cmd.exe', $code);
28+
return $code;
29+
}
30+
$this->output->writeln('<error>Unsupported OS for shell command.</error>');
31+
return static::FAILURE;
32+
}
33+
}

src/StaticPHP/ConsoleApplication.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use StaticPHP\Command\BuildLibsCommand;
88
use StaticPHP\Command\BuildTargetCommand;
9+
use StaticPHP\Command\Dev\IsInstalledCommand;
10+
use StaticPHP\Command\Dev\ShellCommand;
911
use StaticPHP\Command\DoctorCommand;
1012
use StaticPHP\Command\DownloadCommand;
1113
use StaticPHP\Command\ExtractCommand;
@@ -47,6 +49,10 @@ public function __construct()
4749
new BuildLibsCommand(),
4850
new ExtractCommand(),
4951
new SPCConfigCommand(),
52+
53+
// dev commands
54+
new ShellCommand(),
55+
new IsInstalledCommand(),
5056
]);
5157

5258
// add additional commands from registries

0 commit comments

Comments
 (0)