-
Notifications
You must be signed in to change notification settings - Fork 659
/
ShowCommand.php
96 lines (84 loc) · 2.57 KB
/
ShowCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
namespace Psalm\Internal\PluginManager\Command;
use function array_keys;
use function array_map;
use function array_values;
use function count;
use const DIRECTORY_SEPARATOR;
use function getcwd;
use function is_string;
use Psalm\Internal\PluginManager\PluginListFactory;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
* @internal
*/
class ShowCommand extends Command
{
/** @var PluginListFactory */
private $plugin_list_factory;
public function __construct(PluginListFactory $plugin_list_factory)
{
$this->plugin_list_factory = $plugin_list_factory;
parent::__construct();
}
/**
* @return void
*/
protected function configure()
{
$this
->setName('show')
->setDescription('Lists enabled and available plugins')
->addUsage('[-c path/to/psalm.xml]');
}
/**
* @return int
*/
protected function execute(InputInterface $i, OutputInterface $o)
{
$io = new SymfonyStyle($i, $o);
$current_dir = (string) getcwd() . DIRECTORY_SEPARATOR;
$config_file_path = $i->getOption('config');
if ($config_file_path !== null && !is_string($config_file_path)) {
throw new \UnexpectedValueException('Config file path should be a string');
}
$plugin_list = ($this->plugin_list_factory)($current_dir, $config_file_path);
$enabled = $plugin_list->getEnabled();
$available = $plugin_list->getAvailable();
$formatRow =
/** @param null|string $package */
function (string $class, $package): array {
return [$package, $class];
};
$io->section('Enabled');
if (count($enabled)) {
$io->table(
['Package', 'Class'],
array_map(
$formatRow,
array_keys($enabled),
array_values($enabled)
)
);
} else {
$io->note('No plugins enabled');
}
$io->section('Available');
if (count($available)) {
$io->table(
['Package', 'Class'],
array_map(
$formatRow,
array_keys($available),
array_values($available)
)
);
} else {
$io->note('No plugins available');
}
return 0;
}
}