1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @copyright Copyright (c) 2021, hosting.de, Johannes Leuker <[email protected]> |
7
|
|
|
* |
8
|
|
|
* @author Johannes Leuker <[email protected]> |
9
|
|
|
* |
10
|
|
|
* @license GNU AGPL version 3 or any later version |
11
|
|
|
* |
12
|
|
|
* This program is free software: you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU Affero General Public License as |
14
|
|
|
* published by the Free Software Foundation, either version 3 of the |
15
|
|
|
* License, or (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* This program is distributed in the hope that it will be useful, |
18
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
19
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20
|
|
|
* GNU Affero General Public License for more details. |
21
|
|
|
* |
22
|
|
|
* You should have received a copy of the GNU Affero General Public License |
23
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
24
|
|
|
* |
25
|
|
|
*/ |
26
|
|
|
namespace OC\Core\Command\Group; |
27
|
|
|
|
28
|
|
|
use OC\Core\Command\Base; |
29
|
|
|
use OCP\IGroup; |
30
|
|
|
use OCP\IGroupManager; |
31
|
|
|
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; |
32
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
33
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
34
|
|
|
use Symfony\Component\Console\Input\InputOption; |
35
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
36
|
|
|
|
37
|
|
|
class Info extends Base { |
38
|
|
|
/** @var IGroupManager */ |
39
|
|
|
protected $groupManager; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param IGroupManager $groupManager |
43
|
|
|
*/ |
44
|
|
|
public function __construct(IGroupManager $groupManager) { |
45
|
|
|
$this->groupManager = $groupManager; |
46
|
|
|
parent::__construct(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
protected function configure() { |
50
|
|
|
$this |
51
|
|
|
->setName('group:info') |
52
|
|
|
->setDescription('Show information about a group') |
53
|
|
|
->addArgument( |
54
|
|
|
'groupid', |
55
|
|
|
InputArgument::REQUIRED, |
56
|
|
|
'Group id' |
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
|
|
|
|
66
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int { |
67
|
|
|
$gid = $input->getArgument('groupid'); |
68
|
|
|
$group = $this->groupManager->get($gid); |
69
|
|
|
if (!$group instanceof IGroup) { |
70
|
|
|
$output->writeln('<error>Group "' . $gid . '" does not exist.</error>'); |
71
|
|
|
return 1; |
72
|
|
|
} else { |
73
|
|
|
$groupOutput = [ |
74
|
|
|
'groupID' => $gid, |
75
|
|
|
'displayName' => $group->getDisplayName(), |
76
|
|
|
'backends' => $group->getBackendNames(), |
77
|
|
|
]; |
78
|
|
|
|
79
|
|
|
$this->writeArrayInOutputFormat($input, $output, $groupOutput); |
80
|
|
|
return 0; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param string $argumentName |
86
|
|
|
* @param CompletionContext $context |
87
|
|
|
* @return string[] |
88
|
|
|
*/ |
89
|
|
|
public function completeArgumentValues($argumentName, CompletionContext $context) { |
90
|
|
|
if ($argumentName === 'groupid') { |
91
|
|
|
return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord())); |
92
|
|
|
} |
93
|
|
|
return []; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|