diff options
Diffstat (limited to 'core/Command/Group/ListCommand.php')
-rw-r--r-- | core/Command/Group/ListCommand.php | 81 |
1 files changed, 35 insertions, 46 deletions
diff --git a/core/Command/Group/ListCommand.php b/core/Command/Group/ListCommand.php index db7493fe8d4..01522a23f7f 100644 --- a/core/Command/Group/ListCommand.php +++ b/core/Command/Group/ListCommand.php @@ -1,45 +1,23 @@ <?php + /** - * @copyright Copyright (c) 2016 Robin Appelman <robin@icewind.nl> - * - * @author Joas Schilling <coding@schilljs.com> - * @author Johannes Leuker <j.leuker@hosting.de> - * @author Robin Appelman <robin@icewind.nl> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ 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; class ListCommand extends Base { - /** @var IGroupManager */ - protected $groupManager; - - /** - * @param IGroupManager $groupManager - */ - public function __construct(IGroupManager $groupManager) { - $this->groupManager = $groupManager; + public function __construct( + protected IGroupManager $groupManager, + ) { parent::__construct(); } @@ -47,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', @@ -74,32 +58,37 @@ 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; } /** - * @param IGroup[] $groups - * @return array + * @param IGroup $group + * @return string[] */ - private function formatGroups(array $groups, bool $addInfo = false) { - $keys = array_map(function (IGroup $group) { - return $group->getGID(); - }, $groups); + public function usersForGroup(IGroup $group) { + $users = array_keys($group->getUsers()); + return array_map(function ($userId) { + return (string)$userId; + }, $users); + } - if ($addInfo) { - $values = array_map(function (IGroup $group) { - return [ + /** + * @param IGroup[] $groups + */ + private function formatGroups(array $groups, bool $addInfo = false): \Generator { + foreach ($groups as $group) { + if ($addInfo) { + $value = [ + 'displayName' => $group->getDisplayName(), 'backends' => $group->getBackendNames(), - 'users' => array_keys($group->getUsers()), + 'users' => $this->usersForGroup($group), ]; - }, $groups); - } else { - $values = array_map(function (IGroup $group) { - return array_keys($group->getUsers()); - }, $groups); + } else { + $value = $this->usersForGroup($group); + } + yield $group->getGID() => $value; } - return array_combine($keys, $values); } } |