1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-10 06:58:41 +01:00
psalm/src/Psalm/Internal/Cli/Plugin.php

62 lines
1.7 KiB
PHP
Raw Normal View History

<?php
namespace Psalm\Internal\Cli;
use Composer\InstalledVersions;
use OutOfBoundsException;
use Psalm\Internal\CliUtils;
use Psalm\Internal\PluginManager\Command\DisableCommand;
use Psalm\Internal\PluginManager\Command\EnableCommand;
use Psalm\Internal\PluginManager\Command\ShowCommand;
use Psalm\Internal\PluginManager\PluginListFactory;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputOption;
use function dirname;
use function getcwd;
use const DIRECTORY_SEPARATOR;
// phpcs:disable PSR1.Files.SideEffects
require_once __DIR__ . '/../CliUtils.php';
require_once __DIR__ . '/../Composer.php';
2022-01-03 07:55:32 +01:00
/**
* @internal
*/
final class Plugin
{
public static function run(): void
{
$current_dir = (string)getcwd() . DIRECTORY_SEPARATOR;
$vendor_dir = CliUtils::getVendorDir($current_dir);
CliUtils::requireAutoloaders($current_dir, false, $vendor_dir);
2022-01-02 18:13:02 +01:00
$version = null;
try {
$version = InstalledVersions::getVersion('vimeo/psalm') ;
} catch (OutOfBoundsException $e) {
}
$app = new Application('psalm-plugin', $version ?? 'UNKNOWN');
$psalm_root = dirname(__DIR__, 4) . DIRECTORY_SEPARATOR;
$plugin_list_factory = new PluginListFactory($current_dir, $psalm_root);
$app->addCommands([
new ShowCommand($plugin_list_factory),
new EnableCommand($plugin_list_factory),
new DisableCommand($plugin_list_factory),
]);
$app->getDefinition()->addOption(
new InputOption('config', 'c', InputOption::VALUE_REQUIRED, 'Path to Psalm config file')
);
$app->setDefaultCommand('show');
$app->run();
}
}