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.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2021, hosting.de, Johannes Leuker <developers@hosting.de>
  4. *
  5. * @author Johannes Leuker <j.leuker@hosting.de>
  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\SystemTag;
  24. use OC\Core\Command\Base;
  25. use OCP\SystemTag\ISystemTagManager;
  26. use OCP\SystemTag\ISystemTag;
  27. use Symfony\Component\Console\Input\InputInterface;
  28. use Symfony\Component\Console\Input\InputOption;
  29. use Symfony\Component\Console\Output\OutputInterface;
  30. class ListCommand extends Base {
  31. protected ISystemTagManager $systemTagManager;
  32. public function __construct(ISystemTagManager $systemTagManager) {
  33. $this->systemTagManager = $systemTagManager;
  34. parent::__construct();
  35. }
  36. protected function configure() {
  37. $this
  38. ->setName('tag:list')
  39. ->setDescription('list tags')
  40. ->addOption(
  41. 'visibilityFilter',
  42. null,
  43. InputOption::VALUE_OPTIONAL,
  44. 'filter by visibility (1,0)'
  45. )
  46. ->addOption(
  47. 'nameSearchPattern',
  48. null,
  49. InputOption::VALUE_OPTIONAL,
  50. 'optional search pattern for the tag name (infix)'
  51. );
  52. parent::configure();
  53. }
  54. protected function execute(InputInterface $input, OutputInterface $output): int {
  55. $tags = $this->systemTagManager->getAllTags(
  56. $input->getOption('visibilityFilter'),
  57. $input->getOption('nameSearchPattern')
  58. );
  59. $this->writeArrayInOutputFormat($input, $output, $this->formatTags($tags));
  60. return 0;
  61. }
  62. /**
  63. * @param ISystemtag[] $tags
  64. * @return array
  65. */
  66. private function formatTags(array $tags) {
  67. foreach ($tags as $tag) {
  68. $result[$tag->getId()] = [
  69. 'name' => $tag->getName(),
  70. 'access' => ISystemTag::ACCESS_LEVEL_LOOKUP[$tag->getAccessLevel()],
  71. ];
  72. }
  73. return $result;
  74. }
  75. }