forked from wallabag/wallabag
add search argument and limit option to list users command
This commit is contained in:
@ -3,7 +3,9 @@
|
||||
namespace Wallabag\CoreBundle\Command;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
@ -15,6 +17,8 @@ class ListUserCommand extends ContainerAwareCommand
|
||||
->setName('wallabag:user:list')
|
||||
->setDescription('List all users')
|
||||
->setHelp('This command list all existing users')
|
||||
->addArgument('search', InputArgument::OPTIONAL, 'Filter list by given search term')
|
||||
->addOption('limit', 'l', InputOption::VALUE_REQUIRED, 'Max number of displayed users', 100)
|
||||
;
|
||||
}
|
||||
|
||||
@ -22,7 +26,14 @@ class ListUserCommand extends ContainerAwareCommand
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
$users = $this->getContainer()->get('wallabag_user.user_repository')->findAll();
|
||||
$users = $this->getContainer()->get('wallabag_user.user_repository')
|
||||
->getQueryBuilderForSearch($input->getArgument('search'))
|
||||
->setMaxResults($input->getOption('limit'))
|
||||
->getQuery()
|
||||
->getResult();
|
||||
|
||||
$nbUsers = $this->getContainer()->get('wallabag_user.user_repository')
|
||||
->getSumUsers();
|
||||
|
||||
$rows = [];
|
||||
foreach ($users as $user) {
|
||||
@ -36,7 +47,14 @@ class ListUserCommand extends ContainerAwareCommand
|
||||
|
||||
$io->table(['username', 'email', 'is enabled?', 'is admin?'], $rows);
|
||||
|
||||
$io->success(sprintf('%s user(s) displayed.', count($users)));
|
||||
$io->success(
|
||||
sprintf(
|
||||
'%s/%s%s user(s) displayed.',
|
||||
count($users),
|
||||
$nbUsers,
|
||||
$input->getArgument('search') === null ? '' : ' (filtered)'
|
||||
)
|
||||
);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user