Skip to content

Commit fcde3b2

Browse files
authored
Merge pull request #33546 from adam-blakey/show-enabled-and-disabled-apps
2 parents b083a8c + 4744b02 commit fcde3b2

1 file changed

Lines changed: 40 additions & 12 deletions

File tree

core/Command/App/ListApps.php

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* @author Morris Jobke <hey@morrisjobke.de>
88
* @author Robin Appelman <robin@icewind.nl>
99
* @author Victor Dubiniuk <dubiniuk@owncloud.com>
10+
* @author Adam Blakey <adam@blakey.family>
1011
*
1112
* @license AGPL-3.0
1213
*
@@ -51,6 +52,18 @@ protected function configure(): void {
5152
InputOption::VALUE_REQUIRED,
5253
'true - limit to shipped apps only, false - limit to non-shipped apps only'
5354
)
55+
->addOption(
56+
'enabled',
57+
null,
58+
InputOption::VALUE_NONE,
59+
'shows only enabled apps'
60+
)
61+
->addOption(
62+
'disabled',
63+
null,
64+
InputOption::VALUE_NONE,
65+
'shows only disabled apps'
66+
)
5467
;
5568
}
5669

@@ -61,6 +74,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6174
$shippedFilter = null;
6275
}
6376

77+
$showEnabledApps = $input->getOption('enabled') || !$input->getOption('disabled');
78+
$showDisabledApps = $input->getOption('disabled') || !$input->getOption('enabled');
79+
6480
$apps = \OC_App::getAllApps();
6581
$enabledApps = $disabledApps = [];
6682
$versions = \OC_App::getAppVersions();
@@ -77,16 +93,24 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7793
}
7894
}
7995

80-
$apps = ['enabled' => [], 'disabled' => []];
96+
$apps = [];
97+
98+
if ($showEnabledApps) {
99+
$apps['enabled'] = [];
81100

82-
sort($enabledApps);
83-
foreach ($enabledApps as $app) {
84-
$apps['enabled'][$app] = $versions[$app] ?? true;
101+
sort($enabledApps);
102+
foreach ($enabledApps as $app) {
103+
$apps['enabled'][$app] = $versions[$app] ?? true;
104+
}
85105
}
86106

87-
sort($disabledApps);
88-
foreach ($disabledApps as $app) {
89-
$apps['disabled'][$app] = $this->manager->getAppVersion($app) . (isset($versions[$app]) ? ' (installed ' . $versions[$app] . ')' : '');
107+
if ($showDisabledApps) {
108+
$apps['disabled'] = [];
109+
110+
sort($disabledApps);
111+
foreach ($disabledApps as $app) {
112+
$apps['disabled'][$app] = $this->manager->getAppVersion($app) . (isset($versions[$app]) ? ' (installed ' . $versions[$app] . ')' : '');
113+
}
90114
}
91115

92116
$this->writeAppList($input, $output, $apps);
@@ -101,11 +125,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
101125
protected function writeAppList(InputInterface $input, OutputInterface $output, $items): void {
102126
switch ($input->getOption('output')) {
103127
case self::OUTPUT_FORMAT_PLAIN:
104-
$output->writeln('Enabled:');
105-
parent::writeArrayInOutputFormat($input, $output, $items['enabled']);
106-
107-
$output->writeln('Disabled:');
108-
parent::writeArrayInOutputFormat($input, $output, $items['disabled']);
128+
if (isset($items['enabled'])) {
129+
$output->writeln('Enabled:');
130+
parent::writeArrayInOutputFormat($input, $output, $items['enabled']);
131+
}
132+
133+
if (isset($items['disabled'])) {
134+
$output->writeln('Disabled:');
135+
parent::writeArrayInOutputFormat($input, $output, $items['disabled']);
136+
}
109137
break;
110138

111139
default:

0 commit comments

Comments
 (0)