33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6+
7+ declare (strict_types=1 );
8+
69namespace Magento \Setup \Console \Command ;
710
11+ use Magento \Framework \Module \FullModuleList ;
12+ use Magento \Framework \Module \ModuleList ;
813use Magento \Setup \Model \ObjectManagerProvider ;
14+ use Magento \Framework \Console \Cli ;
915use Symfony \Component \Console \Input \InputInterface ;
1016use 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 ) {
64114 $ output ->writeln ('None ' );
65- } else {
66- $ output ->writeln (join ("\n" , $ disabledModules ));
115+ return Cli::RETURN_FAILURE ;
67116 }
117+
118+ $ output ->writeln (join ("\n" , $ enabledModuleNames ));
68119 return \Magento \Framework \Console \Cli::RETURN_SUCCESS ;
69120 }
121+
122+ /**
123+ * @param OutputInterface $output
124+ */
125+ private function showDisabledModules (OutputInterface $ output )
126+ {
127+ $ disabledModuleNames = $ this ->getDisabledModuleNames ();
128+ if (count ($ disabledModuleNames ) === 0 ) {
129+ $ output ->writeln ('None ' );
130+ return Cli::RETURN_FAILURE ;
131+ }
132+
133+ $ output ->writeln (join ("\n" , $ disabledModuleNames ));
134+ return \Magento \Framework \Console \Cli::RETURN_SUCCESS ;
135+ }
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