setName('group:removeuser') ->setDescription('remove a user from a group') ->addArgument( 'group', InputArgument::REQUIRED, 'group to remove the user from' )->addArgument( 'user', InputArgument::REQUIRED + InputArgument::IS_ARRAY, 'users to remove from the group' ); } #[\Override] protected function execute(InputInterface $input, OutputInterface $output): int { $group = $this->groupManager->get($input->getArgument('group')); if (is_null($group)) { $output->writeln('group not found'); return Base::FAILURE; } $allUsersFound = true; $noUserFound = true; $users = (array)$input->getArgument('user'); foreach ($users as $userId) { $user = $this->userManager->get($userId); if (is_null($user)) { $output->writeln('user ' . $userId . ' not found'); $allUsersFound = false; continue; } $noUserFound = false; $group->removeUser($user); unset($user); $output->writeln('user ' . $userId . ' removed'); } if (!$allUsersFound && !$noUserFound) { $output->writeln('Some users were not found, all others where removed from the group.'); return Base::FAILURE; } if ($noUserFound) { return Base::FAILURE; } return Base::SUCCESS; } /** * @param string $argumentName * @param CompletionContext $context * @return string[] */ #[\Override] public function completeArgumentValues($argumentName, CompletionContext $context) { if ($argumentName === 'group') { return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord())); } if ($argumentName === 'user') { $groupId = $context->getWordAtIndex($context->getWordIndex() - 1); $group = $this->groupManager->get($groupId); if ($group === null) { return []; } return array_map(static fn (IUser $user) => $user->getUID(), $group->searchUsers($context->getCurrentWord())); } return []; } }