You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ListCommand.php 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Robin Appelman <robin@icewind.nl>
  4. *
  5. * @author Robin Appelman <robin@icewind.nl>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace OC\Core\Command\User;
  24. use OC\Core\Command\Base;
  25. use OCP\IUser;
  26. use OCP\IUserManager;
  27. use Symfony\Component\Console\Command\Command;
  28. use Symfony\Component\Console\Input\InputInterface;
  29. use Symfony\Component\Console\Input\InputOption;
  30. use Symfony\Component\Console\Output\OutputInterface;
  31. class ListCommand extends Base {
  32. /** @var IUserManager */
  33. protected $userManager;
  34. /**
  35. * @param IUserManager $userManager
  36. */
  37. public function __construct(IUserManager $userManager) {
  38. $this->userManager = $userManager;
  39. parent::__construct();
  40. }
  41. protected function configure() {
  42. $this
  43. ->setName('user:list')
  44. ->setDescription('list configured users')
  45. ->addOption(
  46. 'limit',
  47. 'l',
  48. InputOption::VALUE_OPTIONAL,
  49. 'Number of users to retrieve',
  50. 500
  51. )->addOption(
  52. 'offset',
  53. 'o',
  54. InputOption::VALUE_OPTIONAL,
  55. 'Offset for retrieving users',
  56. 0
  57. )->addOption(
  58. 'output',
  59. null,
  60. InputOption::VALUE_OPTIONAL,
  61. 'Output format (plain, json or json_pretty, default is plain)',
  62. $this->defaultOutputFormat
  63. );
  64. }
  65. protected function execute(InputInterface $input, OutputInterface $output) {
  66. $users = $this->userManager->search('', (int)$input->getOption('limit'), (int)$input->getOption('offset'));
  67. $this->writeArrayInOutputFormat($input, $output, $this->formatUsers($users));
  68. }
  69. /**
  70. * @param IUser[] $users
  71. * @return array
  72. */
  73. private function formatUsers(array $users) {
  74. $keys = array_map(function (IUser $user) {
  75. return $user->getUID();
  76. }, $users);
  77. $values = array_map(function (IUser $user) {
  78. return $user->getDisplayName();
  79. }, $users);
  80. return array_combine($keys, $values);
  81. }
  82. }