aboutsummaryrefslogtreecommitdiffstats
path: root/core/Command/Group/ListCommand.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/Command/Group/ListCommand.php')
-rw-r--r--core/Command/Group/ListCommand.php34
1 files changed, 18 insertions, 16 deletions
diff --git a/core/Command/Group/ListCommand.php b/core/Command/Group/ListCommand.php
index bea6d08c76f..01522a23f7f 100644
--- a/core/Command/Group/ListCommand.php
+++ b/core/Command/Group/ListCommand.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -8,6 +9,7 @@ namespace OC\Core\Command\Group;
use OC\Core\Command\Base;
use OCP\IGroup;
use OCP\IGroupManager;
+use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
@@ -23,6 +25,12 @@ class ListCommand extends Base {
$this
->setName('group:list')
->setDescription('list configured groups')
+ ->addArgument(
+ 'searchstring',
+ InputArgument::OPTIONAL,
+ 'Filter the groups to only those matching the search string',
+ ''
+ )
->addOption(
'limit',
'l',
@@ -50,7 +58,7 @@ class ListCommand extends Base {
}
protected function execute(InputInterface $input, OutputInterface $output): int {
- $groups = $this->groupManager->search('', (int)$input->getOption('limit'), (int)$input->getOption('offset'));
+ $groups = $this->groupManager->search((string)$input->getArgument('searchstring'), (int)$input->getOption('limit'), (int)$input->getOption('offset'));
$this->writeArrayInOutputFormat($input, $output, $this->formatGroups($groups, (bool)$input->getOption('info')));
return 0;
}
@@ -68,25 +76,19 @@ class ListCommand extends Base {
/**
* @param IGroup[] $groups
- * @return array
*/
- private function formatGroups(array $groups, bool $addInfo = false) {
- $keys = array_map(function (IGroup $group) {
- return $group->getGID();
- }, $groups);
-
- if ($addInfo) {
- $values = array_map(function (IGroup $group) {
- return [
+ private function formatGroups(array $groups, bool $addInfo = false): \Generator {
+ foreach ($groups as $group) {
+ if ($addInfo) {
+ $value = [
+ 'displayName' => $group->getDisplayName(),
'backends' => $group->getBackendNames(),
'users' => $this->usersForGroup($group),
];
- }, $groups);
- } else {
- $values = array_map(function (IGroup $group) {
- return $this->usersForGroup($group);
- }, $groups);
+ } else {
+ $value = $this->usersForGroup($group);
+ }
+ yield $group->getGID() => $value;
}
- return array_combine($keys, $values);
}
}