diff --git a/config.yaml b/config.yaml
index 091d9191a..6d750b49b 100644
--- a/config.yaml
+++ b/config.yaml
@@ -122,10 +122,13 @@ commands:
- N98\Magento\Command\Design\DemoNoticeCommand
- N98\Magento\Command\Developer\Asset\ClearCommand
- N98\Magento\Command\Developer\ConsoleCommand
+ - N98\Magento\Command\Developer\Di\Preference\ListCommand
- N98\Magento\Command\Developer\EncryptCommand
- N98\Magento\Command\Developer\DecryptCommand
- N98\Magento\Command\Developer\Module\CreateCommand
- N98\Magento\Command\Developer\Module\DetectComposerDependenciesCommand
+ - N98\Magento\Command\Developer\Module\ListCommand
+ - N98\Magento\Command\Developer\Module\Observer\ListCommand
- N98\Magento\Command\Developer\Report\CountCommand
- N98\Magento\Command\Developer\SymlinksCommand
- N98\Magento\Command\Developer\TemplateHintsBlocksCommand
@@ -171,8 +174,6 @@ commands:
- N98\Magento\Command\Integration\ListCommand
- N98\Magento\Command\Integration\ShowCommand
- N98\Magento\Command\Installer\InstallCommand
- - N98\Magento\Command\Developer\Module\ListCommand
- - N98\Magento\Command\Developer\Module\Observer\ListCommand
- N98\Magento\Command\ScriptCommand
- N98\Magento\Command\SelfUpdateCommand
- N98\Magento\Command\Route\ListCommand
diff --git a/src/N98/Magento/Command/Developer/Di/Preference/ListCommand.php b/src/N98/Magento/Command/Developer/Di/Preference/ListCommand.php
new file mode 100644
index 000000000..950116882
--- /dev/null
+++ b/src/N98/Magento/Command/Developer/Di/Preference/ListCommand.php
@@ -0,0 +1,113 @@
+setName('dev:di:preferences:list')
+ ->setDescription('Lists all registered preferences')
+ ->addArgument(
+ 'area',
+ InputArgument::OPTIONAL,
+ 'Filter observers in specific area. One of [' . implode(',', $this->areas) . ']'
+ )
+ ->addOption(
+ 'format',
+ null,
+ InputOption::VALUE_OPTIONAL,
+ 'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']'
+ );
+ }
+
+ protected function interact(InputInterface $input, OutputInterface $output)
+ {
+ $area = $input->getArgument('area');
+
+ if ($area === null || !in_array($area, $this->areas)) {
+ $choices = [];
+ foreach ($this->areas as $key => $area) {
+ $choices[$key + 1] = '[' . $area . '] ';
+ }
+
+ $question = new ChoiceQuestion('Please select an area:', $choices);
+ $question->setValidator(function ($areaIndex) {
+ if (!in_array($areaIndex - 1, range(0, count($this->areas) - 1), true)) {
+ throw new InvalidArgumentException('Invalid selection.' . $areaIndex);
+ }
+
+ return $this->areas[$areaIndex - 1];
+ });
+ $area = $this->getHelper('question')->ask($input, $output, $question);
+ }
+ }
+
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ * @return int
+ * @throws Exception
+ */
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $this->detectMagento($output);
+ if (!$this->initMagento()) {
+ return Command::FAILURE;
+ }
+
+ $configLoader = $this->getObjectManager()->get(ConfigLoaderInterface::class);
+ $data = $configLoader->load($input->getArgument('area'));
+
+ $table = [];
+
+ foreach ($data['preferences'] as $for => $type) {
+ $table[] = [
+ $for,
+ $type,
+ ];
+ }
+
+ if ($input->getOption('format') == null) {
+ $this->writeSection($output, 'Magento Modules');
+ }
+
+ $this->getHelper('table')
+ ->setHeaders(['for', 'type'])
+ ->renderByFormat($output, $table, $input->getOption('format'));
+
+ return Command::SUCCESS;
+ }
+}
diff --git a/tests/N98/Magento/Command/Developer/Di/Preference/ListCommandTest.php b/tests/N98/Magento/Command/Developer/Di/Preference/ListCommandTest.php
new file mode 100644
index 000000000..51785d9ca
--- /dev/null
+++ b/tests/N98/Magento/Command/Developer/Di/Preference/ListCommandTest.php
@@ -0,0 +1,24 @@
+assertDisplayContains(
+ ['command' => 'dev:di:preference:list', 'area' => 'global'],
+ 'Magento\Store\Api\Data\StoreInterface'
+ );
+ }
+
+ public function testCrontabList()
+ {
+ $this->assertDisplayContains(
+ ['command' => 'dev:di:preference:list', 'area' => 'crontab'],
+ 'Magento\Backend\App\ConfigInterface'
+ );
+ }
+}
diff --git a/tests/bats/functional_magerun_commands.bats b/tests/bats/functional_magerun_commands.bats
index 844a80403..2d0511834 100755
--- a/tests/bats/functional_magerun_commands.bats
+++ b/tests/bats/functional_magerun_commands.bats
@@ -295,6 +295,14 @@ function cleanup_files_in_magento() {
cleanup_files_in_magento "app/code/N98/Magerun123"
}
+@test "Command: dev:di:preference:list" {
+ run $BIN "dev:di:preference:list" global
+ assert_output --partial "Magento\Store\Api\Data\StoreInterface"
+
+ run $BIN "dev:di:preference:list" crontab
+ assert_output --partial "Magento\Backend\App\ConfigInterface"
+}
+
@test "Command: dev:module:detect-composer-dependencies" {
if [ -d "${N98_MAGERUN2_TEST_MAGENTO_ROOT}/vendor/magento/module-catalog-rule" ]; then
run $BIN "dev:module:detect-composer-dependencies" "${N98_MAGERUN2_TEST_MAGENTO_ROOT}/vendor/magento/module-catalog-rule"