From 45a7a270919be9ecf0987fdd0c64036444bc3a35 Mon Sep 17 00:00:00 2001 From: Thomas Steur <tsteur@users.noreply.github.com> Date: Fri, 12 May 2017 19:08:08 +1200 Subject: [PATCH] Add possibility to filter list of plugins (#11687) By specifying an option like `--filter-plugin="Core"` it will only list plugin names that contain the filter / search term. This is useful when you have many plugins installed or when you want to do a simple check if a plugin is installed or not etc. --- plugins/CorePluginsAdmin/Commands/ListPlugins.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugins/CorePluginsAdmin/Commands/ListPlugins.php b/plugins/CorePluginsAdmin/Commands/ListPlugins.php index 0fc132e589..aefbe126ed 100644 --- a/plugins/CorePluginsAdmin/Commands/ListPlugins.php +++ b/plugins/CorePluginsAdmin/Commands/ListPlugins.php @@ -12,6 +12,7 @@ use Piwik\Plugin\ConsoleCommand; use Piwik\Plugin\Manager; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; /** @@ -23,6 +24,7 @@ class ListPlugins extends ConsoleCommand { $this->setName('plugin:list'); $this->setDescription('List installed plugins.'); + $this->addOption('filter-plugin', null, InputOption::VALUE_OPTIONAL, 'If given, prints only plugins that contain this term.'); } protected function execute(InputInterface $input, OutputInterface $output) @@ -31,6 +33,14 @@ class ListPlugins extends ConsoleCommand $plugins = $pluginManager->getInstalledPluginsName(); + $pluginFilter = $input->getOption('filter-plugin'); + + if (!empty($pluginFilter)) { + $plugins = array_filter($plugins, function ($pluginName) use ($pluginFilter) { + return strpos($pluginName, $pluginFilter) !== false; + }); + } + $plugins = array_map(function ($plugin) use ($pluginManager) { return array( '<info>' . $plugin . '</info>', -- GitLab