diff --git a/README.md b/README.md index 756248d2..bb0ecee4 100644 --- a/README.md +++ b/README.md @@ -1007,9 +1007,14 @@ n98-magerun2.phar dev:translate:export [--store=] ### List modules ```sh -n98-magerun2.phar dev:module:list [--vendor=VENDOR] +n98-magerun2.phar dev:module:list [--vendor [VENDOR]] [-e|--only-enabled] [-d|--only-disabled] [--format [FORMAT]] ``` +Lists all installed modules. If `--vendor` option is set, only modules of the given vendor are listed. +If `--only-enabled` option is set, only enabled modules are listed. +If `--only-disabled` option is set, only disabled modules are listed. +Format can be `csv`, `json`, `xml` or `yaml`. + ### Encryption Encrypt the given string using Magentos crypt key diff --git a/src/N98/Magento/Command/Developer/Module/ListCommand.php b/src/N98/Magento/Command/Developer/Module/ListCommand.php index 428ad17f..3be98e75 100644 --- a/src/N98/Magento/Command/Developer/Module/ListCommand.php +++ b/src/N98/Magento/Command/Developer/Module/ListCommand.php @@ -2,6 +2,8 @@ namespace N98\Magento\Command\Developer\Module; +use Magento\Framework\Module\FullModuleList; +use Magento\Framework\Module\Manager; use N98\Magento\Command\AbstractMagentoCommand; use N98\Util\Console\Helper\Table\Renderer\RendererFactory; use Symfony\Component\Console\Command\Command; @@ -21,21 +23,31 @@ class ListCommand extends AbstractMagentoCommand protected $moduleList; /** - * @var \Magento\Framework\Module\ModuleListInterface + * @var \Magento\Framework\Module\FullModuleList */ protected $moduleListObject; + /** + * @var Manager + */ + protected $moduleManager; + + /** + * @return array + */ public function getModuleList() { return $this->moduleList; } /** - * @param \Magento\Framework\Module\ModuleListInterface $moduleList + * @param FullModuleList $moduleList + * @param Manager $moduleManager */ - public function inject(\Magento\Framework\Module\ModuleListInterface $moduleList) + public function inject(\Magento\Framework\Module\FullModuleList $moduleList, Manager $moduleManager) { $this->moduleListObject = $moduleList; + $this->moduleManager = $moduleManager; } protected function configure() @@ -49,6 +61,8 @@ protected function configure() 'Show modules of a specific vendor (case insensitive)' ) ->setDescription('List all installed modules') + ->addOption('only-enabled', 'e', InputOption::VALUE_NONE, 'Show only enabled modules') + ->addOption('only-disabled', 'd', InputOption::VALUE_NONE, 'Show only disabled modules') ->addOption( 'format', null, @@ -65,6 +79,10 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + if ($input->getOption('only-disabled') && $input->getOption('only-enabled')) { + throw new \Exception('You can only use one of the options --only-enabled or --only-disabled'); + } + $this->detectMagento($output, true); if ($input->getOption('format') == null) { @@ -72,20 +90,29 @@ protected function execute(InputInterface $input, OutputInterface $output) } $this->initMagento(); - $this->prepareModuleList($input->getOption('vendor')); + $this->prepareModuleList($input); $this->getHelper('table') - ->setHeaders(['Name', '(Schema) Version']) + ->setHeaders(['Name', '(Schema) Version', 'Status']) ->renderByFormat($output, $this->moduleList, $input->getOption('format')); return Command::SUCCESS; } - protected function prepareModuleList($vendor) + /** + * @param string $vendor + * @return void + */ + protected function prepareModuleList(InputInterface $input) { $this->moduleList = []; - foreach ($this->moduleListObject->getAll() as $moduleName => $info) { + $vendor = $input->getOption('vendor'); + + foreach ($this->moduleListObject->getNames() as $moduleName) { + + $info = $this->moduleListObject->getOne($moduleName); + // First index is (probably always) vendor $moduleNameData = explode('_', $moduleName); @@ -93,7 +120,21 @@ protected function prepareModuleList($vendor) continue; } - $this->moduleList[] = [$info['name'], $info['setup_version']]; + $isEnabled = $this->moduleManager->isEnabled($moduleName); + + if ($isEnabled && $input->getOption('only-disabled')) { + continue; + } + + if (!$isEnabled && $input->getOption('only-enabled')) { + continue; + } + + $this->moduleList[] = [ + $info['name'], + $info['setup_version'], + $isEnabled ? 'enabled' : 'disabled', + ]; } } }