Skip to content

Commit 8304dd2

Browse files
authored
Merge pull request #195 from asgrim/show-all-flag
`pie show` to only show PIE exts by default
2 parents 2f8def7 + 5d5b387 commit 8304dd2

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

Diff for: src/Command/ShowCommand.php

+33-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
use Php\Pie\ComposerIntegration\PieInstalledJsonMetadataKeys;
1010
use Php\Pie\File\BinaryFile;
1111
use Php\Pie\File\BinaryFileFailedVerification;
12+
use Php\Pie\Platform as PiePlatform;
1213
use Php\Pie\Platform\InstalledPiePackages;
1314
use Php\Pie\Platform\OperatingSystem;
1415
use Psr\Container\ContainerInterface;
1516
use Symfony\Component\Console\Attribute\AsCommand;
1617
use Symfony\Component\Console\Command\Command;
1718
use Symfony\Component\Console\Input\InputInterface;
19+
use Symfony\Component\Console\Input\InputOption;
1820
use Symfony\Component\Console\Output\NullOutput;
1921
use Symfony\Component\Console\Output\OutputInterface;
2022

@@ -33,6 +35,8 @@
3335
)]
3436
final class ShowCommand extends Command
3537
{
38+
private const OPTION_ALL = 'all';
39+
3640
public function __construct(
3741
private readonly InstalledPiePackages $installedPiePackages,
3842
private readonly ContainerInterface $container,
@@ -45,12 +49,33 @@ public function configure(): void
4549
parent::configure();
4650

4751
CommandHelper::configurePhpConfigOptions($this);
52+
53+
$this->addOption(
54+
self::OPTION_ALL,
55+
null,
56+
InputOption::VALUE_NONE,
57+
'Show all extensions for the target PHP installation, even those PIE does not manage.',
58+
);
4859
}
4960

5061
public function execute(InputInterface $input, OutputInterface $output): int
5162
{
63+
$showAll = $input->hasOption(self::OPTION_ALL) && $input->getOption(self::OPTION_ALL);
5264
$targetPlatform = CommandHelper::determineTargetPlatformFromInputs($input, $output);
5365

66+
if ($output->getVerbosity() < OutputInterface::VERBOSITY_VERBOSE) {
67+
$output->writeln(
68+
sprintf(
69+
'<info>Using pie.json:</info> %s',
70+
PiePlatform::getPieJsonFilename($targetPlatform),
71+
),
72+
);
73+
}
74+
75+
if (! $showAll) {
76+
$output->writeln('Tip: to include extensions in this list that PIE does not manage, use the --all flag.');
77+
}
78+
5479
$composer = PieComposerFactory::createPieComposer(
5580
$this->container,
5681
PieComposerRequest::noOperation(
@@ -64,12 +89,17 @@ public function execute(InputInterface $input, OutputInterface $output): int
6489
$extensionPath = $targetPlatform->phpBinaryPath->extensionPath();
6590
$extensionEnding = $targetPlatform->operatingSystem === OperatingSystem::Windows ? '.dll' : '.so';
6691

67-
$output->writeln("\n" . '<info>Loaded extensions:</info>');
92+
$output->writeln(sprintf(
93+
"\n" . '<options=bold,underscore>%s:</>',
94+
$showAll ? 'All loaded extensions' : 'Loaded PIE extensions',
95+
));
6896
array_walk(
6997
$phpEnabledExtensions,
70-
static function (string $version, string $phpExtensionName) use ($output, $piePackages, $extensionPath, $extensionEnding): void {
98+
static function (string $version, string $phpExtensionName) use ($showAll, $output, $piePackages, $extensionPath, $extensionEnding): void {
7199
if (! array_key_exists($phpExtensionName, $piePackages)) {
72-
$output->writeln(sprintf(' <comment>%s:%s</comment>', $phpExtensionName, $version));
100+
if ($showAll) {
101+
$output->writeln(sprintf(' <comment>%s:%s</comment>', $phpExtensionName, $version));
102+
}
73103

74104
return;
75105
}

Diff for: test/integration/Command/ShowCommandTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function setUp(): void
2525

2626
public function testExecute(): void
2727
{
28-
$this->commandTester->execute([]);
28+
$this->commandTester->execute(['--all' => true]);
2929

3030
$this->commandTester->assertCommandIsSuccessful();
3131

0 commit comments

Comments
 (0)