8000 Issue_#607: set unused command as default while not other commands ar… · composer-unused/composer-unused@afa144b · GitHub
[go: up one dir, main page]

Skip to content

Commit afa144b

Browse files
MarcinGladkowskiMarcin Gladkowski
andauthored
Issue_#607: set unused command as default while not other commands ar… (#608)
Co-authored-by: Marcin Gladkowski <marcin.gladkowski@comeon.com>
1 parent cfbf477 commit afa144b

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

bin/composer-unused

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use Symfony\Component\Console\Input\ArgvInput;
1616
__DIR__ . '/../../vendor/autoload.php',
1717
__DIR__ . '/../../../autoload.php',
1818
] as $file) {
19-
if (file_exists($file)) {
19+
if (!defined('UNUSED_COMPOSER_INSTALL') && file_exists($file)) {
2020
define('UNUSED_COMPOSER_INSTALL', $file);
2121

2222
break;
@@ -61,7 +61,12 @@ use Symfony\Component\Console\Input\ArgvInput;
6161
$application->add($container->get(UnusedCommand::class));
6262
$application->add($container->get(DebugConsumedSymbolsCommand::class));
6363
$application->add($container->get(DebugProvidedSymbolsCommand::class));
64-
$application->setDefaultCommand('unused');
6564

66-
$application->run(new ArgvInput($argv));
65+
$argvInput = new ArgvInput($argv);
66+
67+
if (!in_array($argvInput->getFirstArgument(), [DebugProvidedSymbolsCommand::getDefaultName(), DebugConsumedSymbolsCommand::getDefaultName()], true)) {
68+
$application->setDefaultCommand('unused', true);
69+
}
70+
71+
$application->run($argvInput);
6772
})($argv);

src/Console/Command/DebugConsumedSymbolsCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
use ComposerUnused\ComposerUnused\Command\Handler\CollectConsumedSymbolsCommandHandler;
99
use ComposerUnused\ComposerUnused\Composer\ConfigFactory;
1010
use ComposerUnused\ComposerUnused\Composer\PackageFactory;
11-
use ComposerUnused\ComposerUnused\Configuration\Configuration;
1211
use ComposerUnused\ComposerUnused\Configuration\ConfigurationProvider;
1312
use ComposerUnused\SymbolParser\Symbol\SymbolInterface;
13+
use Symfony\Component\Console\Attribute\AsCommand;
1414
use Symfony\Component\Console\Command\Command;
15-
use Symfony\Component\Console\Input\InputArgument;
1615
use Symfony\Component\Console\Input\InputInterface;
1716
use Symfony\Component\Console\Input\InputOption;
1817
use Symfony\Component\Console\Output\OutputInterface;
1918
use Symfony\Component\Console\Style\SymfonyStyle;
2019

20+
#[AsCommand(name: 'debug:consumed-symbols')]
2121
final class DebugConsumedSymbolsCommand extends Command
2222
{
2323
private CollectConsumedSymbolsCommandHandler $collectConsumedSymbolsCommandHandler;
@@ -31,7 +31,7 @@ public function __construct(
3131
PackageFactory $packageFactory,
3232
ConfigurationProvider $configurationProvider
3333
) {
34-
parent::__construct('debug:consumed-symbols');
34+
parent::__construct(self::getDefaultName());
3535
$this->collectConsumedSymbolsCommandHandler = $collectConsumedSymbolsCommandHandler;
3636
$this->packageFactory = $packageFactory;
3737
$this->configFactory = $configFactory;

src/Console/Command/DebugProvidedSymbolsCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
use ComposerUnused\ComposerUnused\PackageResolver;
1414
use ComposerUnused\ComposerUnused\Symbol\ProvidedSymbolLoaderBuilder;
1515
use ComposerUnused\SymbolParser\Symbol\SymbolInterface;
16+
use Symfony\Component\Console\Attribute\AsCommand;
1617
use Symfony\Component\Console\Command\Command;
1718
use Symfony\Component\Console\Input\InputArgument;
1819
use Symfony\Component\Console\Input\InputInterface;
1920
use Symfony\Component\Console\Input\InputOption;
2021
use Symfony\Component\Console\Output\OutputInterface;
2122
use Symfony\Component\Console\Style\SymfonyStyle;
2223

24+
#[AsCommand(name: 'debug:provided-symbols')]
2325
final class DebugProvidedSymbolsCommand extends Command
2426
{
2527
private ConfigFactory $configFactory;
@@ -35,7 +37,7 @@ public function __construct(
3537
LocalRepositoryFactory $localRepositoryFactory,
3638
ConfigurationProvider $configurationProvider
3739
) {
38-
parent::__construct('debug:provided-symbols');
40+
parent::__construct(self::getDefaultName());
3941
$this->configFactory = $configFactory;
4042
$this->packageResolver = $packageResolver;
4143
$this->providedSymbolLoaderBuilder = $providedSymbolLoaderBuilder;

src/Console/Command/UnusedCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use ComposerUnused\ComposerUnused\Filter\FilterCollection;
2222
use ComposerUnused\ComposerUnused\OutputFormatter\FormatterFactory;
2323
use InvalidArgumentException;
24+
use Symfony\Component\Console\Attribute\AsCommand;
2425
use Symfony\Component\Console\Command\Command;
2526
use Symfony\Component\Console\Input\InputArgument;
2627
use Symfony\Component\Console\Input\InputInterface;
@@ -37,6 +38,7 @@
3738

3839
use const DIRECTORY_SEPARATOR;
3940

41+
#[AsCommand(name: 'unused')]
4042
final class UnusedCommand extends Command
4143
{
4244
private CollectConsumedSymbolsCommandHandler $collectConsumedSymbolsCommandHandler;
@@ -56,7 +58,7 @@ public function __construct(
5658
PackageFactory $packageFactory,
5759
ConfigurationProvider $configurationProvider
5860
) {
59-
parent::__construct('unused');
61+
parent::__construct(self::getDefaultName());
6062
$this->configFactory = $configFactory;
6163
$this->collectConsumedSymbolsCommandHandler = $collectConsumedSymbolsCommandHandler;
6264
$this->collectRequiredDependenciesCommandHandler = $collectRequiredDependenciesCommandHandler;

0 commit comments

Comments
 (0)
0