Skip to content

Commit f997a36

Browse files
committed
Enhancements to module:status command
1 parent 0c0393d commit f997a36

File tree

1 file changed

+96
-11
lines changed

1 file changed

+96
-11
lines changed

setup/src/Magento/Setup/Console/Command/ModuleStatusCommand.php

Lines changed: 96 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Setup\Console\Command;
78

9+
use Magento\Framework\Module\FullModuleList;
10+
use Magento\Framework\Module\ModuleList;
811
use Magento\Setup\Model\ObjectManagerProvider;
912
use Symfony\Component\Console\Input\InputInterface;
1013
use Symfony\Component\Console\Output\OutputInterface;
14+
use Symfony\Component\Console\Input\InputArgument;
1115

1216
/**
1317
* Command for displaying status of modules
@@ -38,7 +42,10 @@ public function __construct(ObjectManagerProvider $objectManagerProvider)
3842
protected function configure()
3943
{
4044
$this->setName('module:status')
41-
->setDescription('Displays status of modules');
45+
->setDescription('Displays status of modules')
46+
->addArgument('module', InputArgument::OPTIONAL, 'Optional module name')
47+
->addOption('enabled', null, null, 'Print only enabled modules')
48+
->addOption('disabled', null, null, 'Print only disabled modules');
4249
parent::configure();
4350
}
4451

@@ -47,23 +54,101 @@ protected function configure()
4754
*/
4855
protected function execute(InputInterface $input, OutputInterface $output)
4956
{
50-
$moduleList = $this->objectManagerProvider->get()->create(\Magento\Framework\Module\ModuleList::class);
57+
$moduleName = (string)$input->getArgument('module');
58+
if ($moduleName) {
59+
return $this->showSpecificModule($moduleName, $output);
60+
}
61+
62+
$onlyEnabled = $input->getOption('enabled');
63+
if ($onlyEnabled) {
64+
return $this->showEnabledModules($output);
65+
}
66+
67+
$onlyDisabled = $input->getOption('disabled');
68+
if ($onlyDisabled) {
69+
return $this->showDisabledModules($output);
70+
}
71+
5172
$output->writeln('<info>List of enabled modules:</info>');
52-
$enabledModules = $moduleList->getNames();
53-
if (count($enabledModules) === 0) {
73+
$this->showEnabledModules($output);
74+
$output->writeln('');
75+
76+
$output->writeln("<info>List of disabled modules:</info>");
77+
$this->showDisabledModules($output);
78+
$output->writeln('');
79+
}
80+
81+
/**
82+
* @param string $moduleName
83+
* @param OutputInterface $output
84+
*/
85+
private function showSpecificModule(string $moduleName, OutputInterface $output)
86+
{
87+
$allModules = $this->getAllModules();
88+
if (!in_array($moduleName, $allModules->getNames())) {
89+
$output->writeln('<error>Module does not exist</error>');
90+
return;
91+
}
92+
93+
$enabledModules = $this->getEnabledModules();
94+
if (in_array($moduleName, $enabledModules->getNames())) {
95+
$output->writeln('<info>Module is enabled</info>');
96+
return;
97+
}
98+
99+
$output->writeln('<info>Module is disabled</info>');
100+
}
101+
102+
/**
103+
* @param OutputInterface $output
104+
*/
105+
private function showEnabledModules(OutputInterface $output)
106+
{
107+
$enabledModules = $this->getEnabledModules();
108+
$enabledModuleNames = $enabledModules->getNames();
109+
if (count($enabledModuleNames) === 0) {
54110
$output->writeln('None');
55111
} else {
56-
$output->writeln(join("\n", $enabledModules));
112+
$output->writeln(join("\n", $enabledModuleNames));
57113
}
58-
$output->writeln('');
114+
}
59115

60-
$fullModuleList = $this->objectManagerProvider->get()->create(\Magento\Framework\Module\FullModuleList::class);
61-
$output->writeln("<info>List of disabled modules:</info>");
62-
$disabledModules = array_diff($fullModuleList->getNames(), $enabledModules);
63-
if (count($disabledModules) === 0) {
116+
/**
117+
* @param OutputInterface $output
118+
*/
119+
private function showDisabledModules(OutputInterface $output)
120+
{
121+
$disabledModuleNames = $this->getDisabledModuleNames();
122+
if (count($disabledModuleNames) === 0) {
64123
$output->writeln('None');
65124
} else {
66-
$output->writeln(join("\n", $disabledModules));
125+
$output->writeln(join("\n", $disabledModuleNames));
67126
}
68127
}
128+
129+
/**
130+
* @return FullModuleList
131+
*/
132+
private function getAllModules(): FullModuleList
133+
{
134+
return $this->objectManagerProvider->get()->create(FullModuleList::class);
135+
}
136+
137+
/**
138+
* @return ModuleList
139+
*/
140+
private function getEnabledModules(): ModuleList
141+
{
142+
return $this->objectManagerProvider->get()->create(ModuleList::class);
143+
}
144+
145+
/**
146+
* @return array
147+
*/
148+
private function getDisabledModuleNames(): array
149+
{
150+
$fullModuleList = $this->getAllModules();
151+
$enabledModules = $this->getEnabledModules();
152+
return array_diff($fullModuleList->getNames(), $enabledModules->getNames());
153+
}
69154
}

0 commit comments

Comments
 (0)