Info.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Core\Command\Group;
  8. use OC\Core\Command\Base;
  9. use OCP\IGroup;
  10. use OCP\IGroupManager;
  11. use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
  12. use Symfony\Component\Console\Input\InputArgument;
  13. use Symfony\Component\Console\Input\InputInterface;
  14. use Symfony\Component\Console\Input\InputOption;
  15. use Symfony\Component\Console\Output\OutputInterface;
  16. class Info extends Base {
  17. public function __construct(
  18. protected IGroupManager $groupManager,
  19. ) {
  20. parent::__construct();
  21. }
  22. protected function configure() {
  23. $this
  24. ->setName('group:info')
  25. ->setDescription('Show information about a group')
  26. ->addArgument(
  27. 'groupid',
  28. InputArgument::REQUIRED,
  29. 'Group id'
  30. )->addOption(
  31. 'output',
  32. null,
  33. InputOption::VALUE_OPTIONAL,
  34. 'Output format (plain, json or json_pretty, default is plain)',
  35. $this->defaultOutputFormat
  36. );
  37. }
  38. protected function execute(InputInterface $input, OutputInterface $output): int {
  39. $gid = $input->getArgument('groupid');
  40. $group = $this->groupManager->get($gid);
  41. if (!$group instanceof IGroup) {
  42. $output->writeln('<error>Group "' . $gid . '" does not exist.</error>');
  43. return 1;
  44. } else {
  45. $groupOutput = [
  46. 'groupID' => $gid,
  47. 'displayName' => $group->getDisplayName(),
  48. 'backends' => $group->getBackendNames(),
  49. ];
  50. $this->writeArrayInOutputFormat($input, $output, $groupOutput);
  51. return 0;
  52. }
  53. }
  54. /**
  55. * @param string $argumentName
  56. * @param CompletionContext $context
  57. * @return string[]
  58. */
  59. public function completeArgumentValues($argumentName, CompletionContext $context) {
  60. if ($argumentName === 'groupid') {
  61. return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord()));
  62. }
  63. return [];
  64. }
  65. }