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 all 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
52 changes: 40 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 <[email protected]>
* @author Robin Appelman <[email protected]>
* @author Victor Dubiniuk <[email protected]>
* @author Adam Blakey <[email protected]>
*
* @license AGPL-3.0
*
Expand Down Expand Up @@ -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'
)
;
}

Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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:
Expand Down
Loading