mirror of
https://github.com/nextcloud/server.git
synced 2026-06-14 19:20:35 -04:00
feat(occ): Add support for iterable in Base and use in in group:list and user:list
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
7a7f259f3c
commit
db16a32ac3
3 changed files with 20 additions and 31 deletions
|
|
@ -37,17 +37,17 @@ class Base extends Command implements CompletionAwareInterface {
|
|||
;
|
||||
}
|
||||
|
||||
protected function writeArrayInOutputFormat(InputInterface $input, OutputInterface $output, array $items, string $prefix = ' - '): void {
|
||||
protected function writeArrayInOutputFormat(InputInterface $input, OutputInterface $output, iterable $items, string $prefix = ' - '): void {
|
||||
switch ($input->getOption('output')) {
|
||||
case self::OUTPUT_FORMAT_JSON:
|
||||
$output->writeln(json_encode($items));
|
||||
$output->writeln(json_encode(iterator_to_array($items)));
|
||||
break;
|
||||
case self::OUTPUT_FORMAT_JSON_PRETTY:
|
||||
$output->writeln(json_encode($items, JSON_PRETTY_PRINT));
|
||||
$output->writeln(json_encode(iterator_to_array($items), JSON_PRETTY_PRINT));
|
||||
break;
|
||||
default:
|
||||
foreach ($items as $key => $item) {
|
||||
if (is_array($item)) {
|
||||
if (is_iterable($item)) {
|
||||
$output->writeln($prefix . $key . ':');
|
||||
$this->writeArrayInOutputFormat($input, $output, $item, ' ' . $prefix);
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -68,25 +68,18 @@ class ListCommand extends Base {
|
|||
|
||||
/**
|
||||
* @param IGroup[] $groups
|
||||
* @return array
|
||||
*/
|
||||
private function formatGroups(array $groups, bool $addInfo = false) {
|
||||
$keys = array_map(function (IGroup $group) {
|
||||
return $group->getGID();
|
||||
}, $groups);
|
||||
|
||||
if ($addInfo) {
|
||||
$values = array_map(function (IGroup $group) {
|
||||
return [
|
||||
private function formatGroups(array $groups, bool $addInfo = false): \Generator {
|
||||
foreach ($groups as $group) {
|
||||
if ($addInfo) {
|
||||
$value = [
|
||||
'backends' => $group->getBackendNames(),
|
||||
'users' => $this->usersForGroup($group),
|
||||
];
|
||||
}, $groups);
|
||||
} else {
|
||||
$values = array_map(function (IGroup $group) {
|
||||
return $this->usersForGroup($group);
|
||||
}, $groups);
|
||||
} else {
|
||||
$value = $this->usersForGroup($group);
|
||||
}
|
||||
yield $group->getGID() => $value;
|
||||
}
|
||||
return array_combine($keys, $values);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,18 +69,13 @@ class ListCommand extends Base {
|
|||
|
||||
/**
|
||||
* @param IUser[] $users
|
||||
* @param bool [$detailed=false]
|
||||
* @return array
|
||||
* @return \Generator<string,string|array>
|
||||
*/
|
||||
private function formatUsers(array $users, bool $detailed = false) {
|
||||
$keys = array_map(function (IUser $user) {
|
||||
return $user->getUID();
|
||||
}, $users);
|
||||
|
||||
$values = array_map(function (IUser $user) use ($detailed) {
|
||||
private function formatUsers(array $users, bool $detailed = false): \Generator {
|
||||
foreach ($users as $user) {
|
||||
if ($detailed) {
|
||||
$groups = $this->groupManager->getUserGroupIds($user);
|
||||
return [
|
||||
$value = [
|
||||
'user_id' => $user->getUID(),
|
||||
'display_name' => $user->getDisplayName(),
|
||||
'email' => (string)$user->getSystemEMailAddress(),
|
||||
|
|
@ -92,9 +87,10 @@ class ListCommand extends Base {
|
|||
'user_directory' => $user->getHome(),
|
||||
'backend' => $user->getBackendClassName()
|
||||
];
|
||||
} else {
|
||||
$value = $user->getDisplayName();
|
||||
}
|
||||
return $user->getDisplayName();
|
||||
}, $users);
|
||||
return array_combine($keys, $values);
|
||||
yield $user->getUID() => $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue