Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/Console/ConsoleApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,34 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Webmozart\Assert\Assert;

final class ConsoleApplication extends Application
{
private const string NAME = 'Rector';

/**
* @var array<string|null>
*/
private const array ALLOWED_COMMANDS = [
// null is for example: bin/rector --version
null,

// default commands
'custom-rule',
'process',
'list',
'setup-ci',
'worker',
'help',
'completion',
];

/**
* @param Command[] $commands
*/
public function __construct(array $commands)
public function __construct(array $commands, private readonly SymfonyStyle $symfonyStyle)
{
parent::__construct(self::NAME, VersionResolver::PACKAGE_VERSION);

Expand Down Expand Up @@ -73,6 +91,16 @@ public function doRun(InputInterface $input, OutputInterface $output): int
$tokens = $privatesAccessor->getPrivateProperty($input, 'tokens');
$tokens = array_merge(['process'], $tokens);
$privatesAccessor->setPrivateProperty($input, 'tokens', $tokens);
} elseif (! in_array($commandName, self::ALLOWED_COMMANDS, true)) {
$this->symfonyStyle->error(
sprintf(
'The following given path does not match any files or directories: %s%s',
"\n\n - ",
$commandName
)
);

return ExitCode::FAILURE;
}

return parent::doRun($input, $output);
Expand Down