From e9fb7a288515c92e9fa4314cc789dbbe380a4828 Mon Sep 17 00:00:00 2001 From: Adam Blakey Date: Mon, 15 Aug 2022 17:39:29 +0200 Subject: [PATCH 1/4] 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(-) diff --git a/core/Command/App/ListApps.php b/core/Command/App/ListApps.php index 6f8858c8858a2..2d01e9f590455 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 @@ protected function configure() { 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 @@ protected function execute(InputInterface $input, OutputInterface $output): int $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 @@ 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] = $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 @@ protected function execute(InputInterface $input, OutputInterface $output): int 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: From a676a67b9ecdb3ec83b6e2e7077a5fa68d220893 Mon Sep 17 00:00:00 2001 From: Adam Blakey Date: Mon, 15 Aug 2022 21:59:16 +0200 Subject: [PATCH 2/4] Fixed logic issue where checking for wrong option Signed-off-by: Adam Blakey --- core/Command/App/ListApps.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/core/Command/App/ListApps.php b/core/Command/App/ListApps.php index 2d01e9f590455..6cb91aae39c5c 100644 --- a/core/Command/App/ListApps.php +++ b/core/Command/App/ListApps.php @@ -75,16 +75,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int $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; + if ($input->getOption('enabled') && $input->getOption('disabled')) { + $showEnabledApps = true; + $showDisabledApps = true; } - else if ($input->getOption('enabled') !== '') { + else if ($input->getOption('enabled')) { $showEnabledApps = true; $showDisabledApps = false; } - else if ($input->getOption('disabled') !== '') { + else if ($input->getOption('disabled')) { $showEnabledApps = false; $showDisabledApps = true; } @@ -141,12 +140,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int protected function writeAppList(InputInterface $input, OutputInterface $output, $items) { switch ($input->getOption('output')) { case self::OUTPUT_FORMAT_PLAIN: - if ($items['enabled']) { + if (isset($items['enabled'])) { $output->writeln('Enabled:'); parent::writeArrayInOutputFormat($input, $output, $items['enabled']); } - if ($items['disabled']) { + if (isset($items['disabled'])) { $output->writeln('Disabled:'); parent::writeArrayInOutputFormat($input, $output, $items['disabled']); } From aa09af8410c41dd64798ce42874264e101803312 Mon Sep 17 00:00:00 2001 From: Adam Blakey Date: Mon, 18 Mar 2024 09:31:21 +0000 Subject: [PATCH 3/4] Update core/Command/App/ListApps.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refactor: changed overcomplicated if statement into two shorter lines Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com> Signed-off-by: Adam Blakey --- core/Command/App/ListApps.php | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/core/Command/App/ListApps.php b/core/Command/App/ListApps.php index a361ac6b19e1c..07fc340d59720 100644 --- a/core/Command/App/ListApps.php +++ b/core/Command/App/ListApps.php @@ -74,22 +74,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int $shippedFilter = null; } - if ($input->getOption('enabled') && $input->getOption('disabled')) { - $showEnabledApps = true; - $showDisabledApps = true; - } - else if ($input->getOption('enabled')) { - $showEnabledApps = true; - $showDisabledApps = false; - } - else if ($input->getOption('disabled')) { - $showEnabledApps = false; - $showDisabledApps = true; - } - else { - $showEnabledApps = true; - $showDisabledApps = true; - } + $showEnabledApps = $input->getOption('enabled') || !$input->getOption('disabled'); + $showDisabledApps = $input->getOption('disabled') || !$input->getOption('enabled'); $apps = \OC_App::getAllApps(); $enabledApps = $disabledApps = []; From 4744b02c40acad878aaecb636893b422e56ae7c0 Mon Sep 17 00:00:00 2001 From: Adam Blakey Date: Mon, 18 Mar 2024 15:46:39 +0000 Subject: [PATCH 4/4] style: Fixed style from composer cs:fix Signed-off-by: Adam Blakey --- core/Command/App/ListApps.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/Command/App/ListApps.php b/core/Command/App/ListApps.php index 07fc340d59720..d0b2d397e9f8c 100644 --- a/core/Command/App/ListApps.php +++ b/core/Command/App/ListApps.php @@ -101,7 +101,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int sort($enabledApps); foreach ($enabledApps as $app) { $apps['enabled'][$app] = $versions[$app] ?? true; - } + } } if ($showDisabledApps) { @@ -134,7 +134,7 @@ protected function writeAppList(InputInterface $input, OutputInterface $output, $output->writeln('Disabled:'); parent::writeArrayInOutputFormat($input, $output, $items['disabled']); } - break; + break; default: parent::writeArrayInOutputFormat($input, $output, $items);