setDescription('Lists installed plugins') ->addOption('json', 'j', InputOption::VALUE_NONE, 'Output result in JSON'); } protected function doExecutePluginAction(InputInterface $input, OutputInterface $output) { $plugins = array_map(function (Plugin $plugin) use ($input) { if ($plugin->isErroneous()) { return $this->formatErroneousPlugin($input, $plugin); } return $this->formatPlugin($input, $plugin); }, $this->container['plugins.manager']->listPlugins()); if ($input->getOption('json')) { $output->writeln(json_encode(array('plugins' => array_values($plugins)))); } else { $table = $this->getHelperSet()->get('table'); $table ->setHeaders(array('Name', 'Version', 'Description')) ->setRows($plugins) ; $table->render($output); } return 0; } private function formatPlugin(InputInterface $input, Plugin $plugin) { if ($input->getOption('json')) { return array( 'name' => $plugin->getName(), 'version' => $plugin->getManifest()->getVersion(), 'description' => $plugin->getManifest()->getDescription(), 'error' => false, ); } return array( $plugin->getName(), $plugin->getManifest()->getVersion(), $plugin->getManifest()->getDescription(), ); } private function formatErroneousPlugin(InputInterface $input, Plugin $plugin) { if ($input->getOption('json')) { return array( 'name' => $plugin->getName(), 'error' => true, 'description' => 'Error : '.$plugin->getError()->getMessage(), 'version' => null, ); } return array( '' . $plugin->getName() . '', 'Error : ' . $plugin->getError()->getMessage() . '', '', ); } }