Skip to content

Commit b8b4ef6

Browse files
ENGCOM-2162: Enhancements to module:status command #15543
- Merge Pull Request #15543 from jissereitsma/magento2:issue-module-status-cli-enhancements - Merged commits: 1. f997a36 2. 047097b 3. ca4282e 4. fcff36e
2 parents 0383b22 + fcff36e commit b8b4ef6

File tree

1 file changed

+105
-13
lines changed

1 file changed

+105
-13
lines changed

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

Lines changed: 105 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
7+
declare(strict_types=1);
8+
69
namespace Magento\Setup\Console\Command;
710

11+
use Magento\Framework\Module\FullModuleList;
12+
use Magento\Framework\Module\ModuleList;
813
use Magento\Setup\Model\ObjectManagerProvider;
14+
use Magento\Framework\Console\Cli;
915
use Symfony\Component\Console\Input\InputInterface;
1016
use Symfony\Component\Console\Output\OutputInterface;
17+
use Symfony\Component\Console\Input\InputArgument;
1118

1219
/**
1320
* Command for displaying status of modules
@@ -38,7 +45,10 @@ public function __construct(ObjectManagerProvider $objectManagerProvider)
3845
protected function configure()
3946
{
4047
$this->setName('module:status')
41-
->setDescription('Displays status of modules');
48+
->setDescription('Displays status of modules')
49+
->addArgument('module', InputArgument::OPTIONAL, 'Optional module name')
50+
->addOption('enabled', null, null, 'Print only enabled modules')
51+
->addOption('disabled', null, null, 'Print only disabled modules');
4252
parent::configure();
4353
}
4454

@@ -47,24 +57,106 @@ protected function configure()
4757
*/
4858
protected function execute(InputInterface $input, OutputInterface $output)
4959
{
50-
$moduleList = $this->objectManagerProvider->get()->create(\Magento\Framework\Module\ModuleList::class);
51-
$output->writeln('<info>List of enabled modules:</info>');
52-
$enabledModules = $moduleList->getNames();
53-
if (count($enabledModules) === 0) {
54-
$output->writeln('None');
55-
} else {
56-
$output->writeln(join("\n", $enabledModules));
60+
$moduleName = (string)$input->getArgument('module');
61+
if ($moduleName) {
62+
return $this->showSpecificModule($moduleName, $output);
5763
}
64+
65+
$onlyEnabled = $input->getOption('enabled');
66+
if ($onlyEnabled) {
67+
return $this->showEnabledModules($output);
68+
}
69+
70+
$onlyDisabled = $input->getOption('disabled');
71+
if ($onlyDisabled) {
72+
return $this->showDisabledModules($output);
73+
}
74+
75+
$output->writeln('<info>List of enabled modules:</info>');
76+
$this->showEnabledModules($output);
5877
$output->writeln('');
5978

60-
$fullModuleList = $this->objectManagerProvider->get()->create(\Magento\Framework\Module\FullModuleList::class);
6179
$output->writeln("<info>List of disabled modules:</info>");
62-
$disabledModules = array_diff($fullModuleList->getNames(), $enabledModules);
63-
if (count($disabledModules) === 0) {
80+
$this->showDisabledModules($output);
81+
$output->writeln('');
82+
}
83+
84+
/**
85+
* @param string $moduleName
86+
* @param OutputInterface $output
87+
*/
88+
private function showSpecificModule(string $moduleName, OutputInterface $output)
89+
{
90+
$allModules = $this->getAllModules();
91+
if (!in_array($moduleName, $allModules->getNames())) {
92+
$output->writeln('<error>Module does not exist</error>');
93+
return Cli::RETURN_FAILURE;
94+
}
95+
96+
$enabledModules = $this->getEnabledModules();
97+
if (in_array($moduleName, $enabledModules->getNames())) {
98+
$output->writeln('<info>Module is enabled</info>');
99+
return Cli::RETURN_FAILURE;
100+
}
101+
102+
$output->writeln('<info>Module is disabled</info>');
103+
return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
104+
}
105+
106+
/**
107+
* @param OutputInterface $output
108+
*/
109+
private function showEnabledModules(OutputInterface $output)
110+
{
111+
$enabledModules = $this->getEnabledModules();
112+
$enabledModuleNames = $enabledModules->getNames();
113+
if (count($enabledModuleNames) === 0) {
114+
$output->writeln('None');
115+
return Cli::RETURN_FAILURE;
116+
}
117+
118+
$output->writeln(join("\n", $enabledModuleNames));
119+
return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
120+
}
121+
122+
/**
123+
* @param OutputInterface $output
124+
*/
125+
private function showDisabledModules(OutputInterface $output)
126+
{
127+
$disabledModuleNames = $this->getDisabledModuleNames();
128+
if (count($disabledModuleNames) === 0) {
64129
$output->writeln('None');
65-
} else {
66-
$output->writeln(join("\n", $disabledModules));
130+
return Cli::RETURN_FAILURE;
67131
}
132+
133+
$output->writeln(join("\n", $disabledModuleNames));
68134
return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
69135
}
136+
137+
/**
138+
* @return FullModuleList
139+
*/
140+
private function getAllModules(): FullModuleList
141+
{
142+
return $this->objectManagerProvider->get()->create(FullModuleList::class);
143+
}
144+
145+
/**
146+
* @return ModuleList
147+
*/
148+
private function getEnabledModules(): ModuleList
149+
{
150+
return $this->objectManagerProvider->get()->create(ModuleList::class);
151+
}
152+
153+
/**
154+
* @return array
155+
*/
156+
private function getDisabledModuleNames(): array
157+
{
158+
$fullModuleList = $this->getAllModules();
159+
$enabledModules = $this->getEnabledModules();
160+
return array_diff($fullModuleList->getNames(), $enabledModules->getNames());
161+
}
70162
}

0 commit comments

Comments
 (0)