From e9fb7a288515c92e9fa4314cc789dbbe380a4828 Mon Sep 17 00:00:00 2001 From: Adam Blakey Date: Mon, 15 Aug 2022 17:39:29 +0200 Subject: added --enabled and --disabled options to occ app:list Signed-off-by: Adam Blakey --- core/Command/App/ListApps.php | 67 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 12 deletions(-) (limited to 'core/Command/App') diff --git a/core/Command/App/ListApps.php b/core/Command/App/ListApps.php index 6f8858c8858..2d01e9f5904 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 * @@ -52,6 +53,18 @@ class ListApps extends Base { 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' + ) ; } @@ -62,6 +75,24 @@ class ListApps extends Base { $shippedFilter = null; } + if ($input->getOption('enabled') !== '' && $input->getOption('disabled') !== '') { + $output->writeln('You can only use at most one of the options ' . + '"enabled" or "disabled"'); + return 1; + } + else if ($input->getOption('enabled') !== '') { + $showEnabledApps = true; + $showDisabledApps = false; + } + else if ($input->getOption('disabled') !== '') { + $showEnabledApps = false; + $showDisabledApps = true; + } + else { + $showEnabledApps = true; + $showDisabledApps = true; + } + $apps = \OC_App::getAllApps(); $enabledApps = $disabledApps = []; $versions = \OC_App::getAppVersions(); @@ -78,16 +109,24 @@ class ListApps extends Base { } } - $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] = $versions[$app] ?? null; + if ($showDisabledApps) { + $apps['disabled'] = []; + + sort($disabledApps); + foreach ($disabledApps as $app) { + $apps['disabled'][$app] = $versions[$app] ?? null; + } } $this->writeAppList($input, $output, $apps); @@ -102,11 +141,15 @@ class ListApps extends Base { protected function writeAppList(InputInterface $input, OutputInterface $output, $items) { 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 ($items['enabled']) { + $output->writeln('Enabled:'); + parent::writeArrayInOutputFormat($input, $output, $items['enabled']); + } + + if ($items['disabled']) { + $output->writeln('Disabled:'); + parent::writeArrayInOutputFormat($input, $output, $items['disabled']); + } break; default: -- cgit v1.2.3