diff --git a/src/Command/ShowCommand.php b/src/Command/ShowCommand.php index 6bf3a9a7..37d93602 100644 --- a/src/Command/ShowCommand.php +++ b/src/Command/ShowCommand.php @@ -9,12 +9,14 @@ use Php\Pie\ComposerIntegration\PieInstalledJsonMetadataKeys; use Php\Pie\File\BinaryFile; use Php\Pie\File\BinaryFileFailedVerification; +use Php\Pie\Platform as PiePlatform; use Php\Pie\Platform\InstalledPiePackages; use Php\Pie\Platform\OperatingSystem; use Psr\Container\ContainerInterface; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Output\OutputInterface; @@ -33,6 +35,8 @@ )] final class ShowCommand extends Command { + private const OPTION_ALL = 'all'; + public function __construct( private readonly InstalledPiePackages $installedPiePackages, private readonly ContainerInterface $container, @@ -45,12 +49,33 @@ public function configure(): void parent::configure(); CommandHelper::configurePhpConfigOptions($this); + + $this->addOption( + self::OPTION_ALL, + null, + InputOption::VALUE_NONE, + 'Show all extensions for the target PHP installation, even those PIE does not manage.', + ); } public function execute(InputInterface $input, OutputInterface $output): int { + $showAll = $input->hasOption(self::OPTION_ALL) && $input->getOption(self::OPTION_ALL); $targetPlatform = CommandHelper::determineTargetPlatformFromInputs($input, $output); + if ($output->getVerbosity() < OutputInterface::VERBOSITY_VERBOSE) { + $output->writeln( + sprintf( + 'Using pie.json: %s', + PiePlatform::getPieJsonFilename($targetPlatform), + ), + ); + } + + if (! $showAll) { + $output->writeln('Tip: to include extensions in this list that PIE does not manage, use the --all flag.'); + } + $composer = PieComposerFactory::createPieComposer( $this->container, PieComposerRequest::noOperation( @@ -64,12 +89,17 @@ public function execute(InputInterface $input, OutputInterface $output): int $extensionPath = $targetPlatform->phpBinaryPath->extensionPath(); $extensionEnding = $targetPlatform->operatingSystem === OperatingSystem::Windows ? '.dll' : '.so'; - $output->writeln("\n" . 'Loaded extensions:'); + $output->writeln(sprintf( + "\n" . '%s:', + $showAll ? 'All loaded extensions' : 'Loaded PIE extensions', + )); array_walk( $phpEnabledExtensions, - static function (string $version, string $phpExtensionName) use ($output, $piePackages, $extensionPath, $extensionEnding): void { + static function (string $version, string $phpExtensionName) use ($showAll, $output, $piePackages, $extensionPath, $extensionEnding): void { if (! array_key_exists($phpExtensionName, $piePackages)) { - $output->writeln(sprintf(' %s:%s', $phpExtensionName, $version)); + if ($showAll) { + $output->writeln(sprintf(' %s:%s', $phpExtensionName, $version)); + } return; } diff --git a/test/integration/Command/ShowCommandTest.php b/test/integration/Command/ShowCommandTest.php index 065ad08b..4790d354 100644 --- a/test/integration/Command/ShowCommandTest.php +++ b/test/integration/Command/ShowCommandTest.php @@ -25,7 +25,7 @@ public function setUp(): void public function testExecute(): void { - $this->commandTester->execute([]); + $this->commandTester->execute(['--all' => true]); $this->commandTester->assertCommandIsSuccessful();