88
99namespace Magento \Setup \Console \Command ;
1010
11+ use Magento \Framework \Console \Cli ;
1112use Magento \Framework \Module \FullModuleList ;
1213use Magento \Framework \Module \ModuleList ;
1314use Magento \Setup \Model \ObjectManagerProvider ;
14- use Magento \ Framework \Console \Cli ;
15+ use Symfony \ Component \Console \Input \ InputArgument ;
1516use Symfony \Component \Console \Input \InputInterface ;
1617use Symfony \Component \Console \Output \OutputInterface ;
17- use Symfony \Component \Console \Input \InputArgument ;
1818
1919/**
2020 * Command for displaying status of modules
2121 */
2222class ModuleStatusCommand extends AbstractSetupCommand
2323{
2424 /**
25- * Object manager provider
26- *
2725 * @var ObjectManagerProvider
2826 */
2927 private $ objectManagerProvider ;
3028
3129 /**
32- * Inject dependencies
33- *
3430 * @param ObjectManagerProvider $objectManagerProvider
3531 */
3632 public function __construct (ObjectManagerProvider $ objectManagerProvider )
@@ -40,26 +36,33 @@ public function __construct(ObjectManagerProvider $objectManagerProvider)
4036 }
4137
4238 /**
43- * { @inheritdoc}
39+ * @inheritdoc
4440 */
4541 protected function configure ()
4642 {
4743 $ this ->setName ('module:status ' )
4844 ->setDescription ('Displays status of modules ' )
49- ->addArgument ('module ' , InputArgument::OPTIONAL , 'Optional module name ' )
45+ ->addArgument (
46+ 'module-names ' ,
47+ InputArgument::OPTIONAL | InputArgument::IS_ARRAY ,
48+ 'Optional module name '
49+ )
5050 ->addOption ('enabled ' , null , null , 'Print only enabled modules ' )
5151 ->addOption ('disabled ' , null , null , 'Print only disabled modules ' );
5252 parent ::configure ();
5353 }
5454
5555 /**
56- * { @inheritdoc}
56+ * @inheritdoc
5757 */
5858 protected function execute (InputInterface $ input , OutputInterface $ output )
5959 {
60- $ moduleName = (string )$ input ->getArgument ('module ' );
61- if ($ moduleName ) {
62- return $ this ->showSpecificModule ($ moduleName , $ output );
60+ $ moduleNames = $ input ->getArgument ('module-names ' );
61+ if (!empty ($ moduleNames )) {
62+ foreach ($ moduleNames as $ moduleName ) {
63+ $ this ->showSpecificModule ($ moduleName , $ output );
64+ }
65+ return Cli::RETURN_SUCCESS ;
6366 }
6467
6568 $ onlyEnabled = $ input ->getOption ('enabled ' );
@@ -79,34 +82,42 @@ protected function execute(InputInterface $input, OutputInterface $output)
7982 $ output ->writeln ("<info>List of disabled modules:</info> " );
8083 $ this ->showDisabledModules ($ output );
8184 $ output ->writeln ('' );
85+
86+ return Cli::RETURN_SUCCESS ;
8287 }
8388
8489 /**
90+ * Specific module show
91+ *
8592 * @param string $moduleName
8693 * @param OutputInterface $output
94+ * @return int
8795 */
88- private function showSpecificModule (string $ moduleName , OutputInterface $ output )
96+ private function showSpecificModule (string $ moduleName , OutputInterface $ output ): int
8997 {
9098 $ allModules = $ this ->getAllModules ();
91- if (!in_array ($ moduleName , $ allModules ->getNames ())) {
92- $ output ->writeln (' <error>Module does not exist</error> ' );
99+ if (!in_array ($ moduleName , $ allModules ->getNames (), true )) {
100+ $ output ->writeln ($ moduleName . ' : <error>Module does not exist</error> ' );
93101 return Cli::RETURN_FAILURE ;
94102 }
95103
96104 $ enabledModules = $ this ->getEnabledModules ();
97- if (in_array ($ moduleName , $ enabledModules ->getNames ())) {
98- $ output ->writeln (' <info>Module is enabled</info> ' );
105+ if (in_array ($ moduleName , $ enabledModules ->getNames (), true )) {
106+ $ output ->writeln ($ moduleName . ' : <info>Module is enabled</info> ' );
99107 return Cli::RETURN_FAILURE ;
100108 }
101109
102- $ output ->writeln (' <info>Module is disabled</info> ' );
103- return \ Magento \ Framework \ Console \ Cli::RETURN_SUCCESS ;
110+ $ output ->writeln ($ moduleName . ' : <info> Module is disabled</info> ' );
111+ return Cli::RETURN_SUCCESS ;
104112 }
105113
106114 /**
115+ * Enable modules show
116+ *
107117 * @param OutputInterface $output
118+ * @return int
108119 */
109- private function showEnabledModules (OutputInterface $ output )
120+ private function showEnabledModules (OutputInterface $ output ): int
110121 {
111122 $ enabledModules = $ this ->getEnabledModules ();
112123 $ enabledModuleNames = $ enabledModules ->getNames ();
@@ -116,13 +127,17 @@ private function showEnabledModules(OutputInterface $output)
116127 }
117128
118129 $ output ->writeln (join ("\n" , $ enabledModuleNames ));
119- return \Magento \Framework \Console \Cli::RETURN_SUCCESS ;
130+
131+ return Cli::RETURN_SUCCESS ;
120132 }
121133
122134 /**
135+ * Disabled modules show
136+ *
123137 * @param OutputInterface $output
138+ * @return int
124139 */
125- private function showDisabledModules (OutputInterface $ output )
140+ private function showDisabledModules (OutputInterface $ output ): int
126141 {
127142 $ disabledModuleNames = $ this ->getDisabledModuleNames ();
128143 if (count ($ disabledModuleNames ) === 0 ) {
@@ -131,32 +146,42 @@ private function showDisabledModules(OutputInterface $output)
131146 }
132147
133148 $ output ->writeln (join ("\n" , $ disabledModuleNames ));
134- return \Magento \Framework \Console \Cli::RETURN_SUCCESS ;
149+
150+ return Cli::RETURN_SUCCESS ;
135151 }
136152
137153 /**
154+ * Returns all modules
155+ *
138156 * @return FullModuleList
139157 */
140158 private function getAllModules (): FullModuleList
141159 {
142- return $ this ->objectManagerProvider ->get ()->create (FullModuleList::class);
160+ return $ this ->objectManagerProvider ->get ()
161+ ->create (FullModuleList::class);
143162 }
144163
145164 /**
165+ * Returns enabled modules
166+ *
146167 * @return ModuleList
147168 */
148169 private function getEnabledModules (): ModuleList
149170 {
150- return $ this ->objectManagerProvider ->get ()->create (ModuleList::class);
171+ return $ this ->objectManagerProvider ->get ()
172+ ->create (ModuleList::class);
151173 }
152174
153175 /**
176+ * Returns disabled module names
177+ *
154178 * @return array
155179 */
156180 private function getDisabledModuleNames (): array
157181 {
158182 $ fullModuleList = $ this ->getAllModules ();
159183 $ enabledModules = $ this ->getEnabledModules ();
184+
160185 return array_diff ($ fullModuleList ->getNames (), $ enabledModules ->getNames ());
161186 }
162187}
0 commit comments