Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added --enabled and --disabled options to occ app:list #33546

Merged
merged 5 commits into from
Mar 19, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 54 additions & 12 deletions core/Command/App/ListApps.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @author Morris Jobke <hey@morrisjobke.de>
* @author Robin Appelman <robin@icewind.nl>
* @author Victor Dubiniuk <dubiniuk@owncloud.com>
* @author Adam Blakey <adam@blakey.family>
*
* @license AGPL-3.0
*
Expand Down Expand Up @@ -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'
)
;
}

Expand All @@ -62,6 +75,23 @@ 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;
}
adam-blakey marked this conversation as resolved.
Show resolved Hide resolved

$apps = \OC_App::getAllApps();
$enabledApps = $disabledApps = [];
$versions = \OC_App::getAppVersions();
Expand All @@ -78,16 +108,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);
Expand All @@ -102,11 +140,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 (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:
Expand Down