diff --git a/core/Command/App/ListApps.php b/core/Command/App/ListApps.php index 2db781418e591..d0b2d397e9f8c 100644 --- a/core/Command/App/ListApps.php +++ b/core/Command/App/ListApps.php @@ -7,6 +7,7 @@ * @author Morris Jobke * @author Robin Appelman * @author Victor Dubiniuk + * @author Adam Blakey * * @license AGPL-3.0 * @@ -51,6 +52,18 @@ protected function configure(): void { InputOption::VALUE_REQUIRED, 'true - limit to shipped apps only, false - limit to non-shipped apps only' ) + ->addOption( + 'enabled', + null, + InputOption::VALUE_NONE, + 'shows only enabled apps' + ) + ->addOption( + 'disabled', + null, + InputOption::VALUE_NONE, + 'shows only disabled apps' + ) ; } @@ -61,6 +74,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int $shippedFilter = null; } + $showEnabledApps = $input->getOption('enabled') || !$input->getOption('disabled'); + $showDisabledApps = $input->getOption('disabled') || !$input->getOption('enabled'); + $apps = \OC_App::getAllApps(); $enabledApps = $disabledApps = []; $versions = \OC_App::getAppVersions(); @@ -77,16 +93,24 @@ protected function execute(InputInterface $input, OutputInterface $output): int } } - $apps = ['enabled' => [], 'disabled' => []]; + $apps = []; + + if ($showEnabledApps) { + $apps['enabled'] = []; - sort($enabledApps); - foreach ($enabledApps as $app) { - $apps['enabled'][$app] = $versions[$app] ?? true; + sort($enabledApps); + foreach ($enabledApps as $app) { + $apps['enabled'][$app] = $versions[$app] ?? true; + } } - sort($disabledApps); - foreach ($disabledApps as $app) { - $apps['disabled'][$app] = $this->manager->getAppVersion($app) . (isset($versions[$app]) ? ' (installed ' . $versions[$app] . ')' : ''); + if ($showDisabledApps) { + $apps['disabled'] = []; + + sort($disabledApps); + foreach ($disabledApps as $app) { + $apps['disabled'][$app] = $this->manager->getAppVersion($app) . (isset($versions[$app]) ? ' (installed ' . $versions[$app] . ')' : ''); + } } $this->writeAppList($input, $output, $apps); @@ -101,11 +125,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int protected function writeAppList(InputInterface $input, OutputInterface $output, $items): void { switch ($input->getOption('output')) { case self::OUTPUT_FORMAT_PLAIN: - $output->writeln('Enabled:'); - parent::writeArrayInOutputFormat($input, $output, $items['enabled']); - - $output->writeln('Disabled:'); - parent::writeArrayInOutputFormat($input, $output, $items['disabled']); + if (isset($items['enabled'])) { + $output->writeln('Enabled:'); + parent::writeArrayInOutputFormat($input, $output, $items['enabled']); + } + + if (isset($items['disabled'])) { + $output->writeln('Disabled:'); + parent::writeArrayInOutputFormat($input, $output, $items['disabled']); + } break; default: