diff options
author | Nicolas Hart <contact@nclshart.net> | 2017-07-31 23:20:41 +0200 |
---|---|---|
committer | Nicolas Hart <contact@nclshart.net> | 2017-07-31 23:20:41 +0200 |
commit | f7a4b441361404b378c30b7788b3699c208537ad (patch) | |
tree | 6e0b786d397dbafdc1e6845e6ce59344f8d65f76 /src/Wallabag/CoreBundle/Command | |
parent | af31cfed769538fcb7d283cb1fad80ac8d07b663 (diff) | |
download | wallabag-f7a4b441361404b378c30b7788b3699c208537ad.tar.gz wallabag-f7a4b441361404b378c30b7788b3699c208537ad.tar.zst wallabag-f7a4b441361404b378c30b7788b3699c208537ad.zip |
add search argument and limit option to list users command
Diffstat (limited to 'src/Wallabag/CoreBundle/Command')
-rw-r--r-- | src/Wallabag/CoreBundle/Command/ListUserCommand.php | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/Wallabag/CoreBundle/Command/ListUserCommand.php b/src/Wallabag/CoreBundle/Command/ListUserCommand.php index 852e93b7..20660d18 100644 --- a/src/Wallabag/CoreBundle/Command/ListUserCommand.php +++ b/src/Wallabag/CoreBundle/Command/ListUserCommand.php | |||
@@ -3,7 +3,9 @@ | |||
3 | namespace Wallabag\CoreBundle\Command; | 3 | namespace Wallabag\CoreBundle\Command; |
4 | 4 | ||
5 | use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | 5 | use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
6 | use Symfony\Component\Console\Input\InputArgument; | ||
6 | use Symfony\Component\Console\Input\InputInterface; | 7 | use Symfony\Component\Console\Input\InputInterface; |
8 | use Symfony\Component\Console\Input\InputOption; | ||
7 | use Symfony\Component\Console\Output\OutputInterface; | 9 | use Symfony\Component\Console\Output\OutputInterface; |
8 | use Symfony\Component\Console\Style\SymfonyStyle; | 10 | use Symfony\Component\Console\Style\SymfonyStyle; |
9 | 11 | ||
@@ -15,6 +17,8 @@ class ListUserCommand extends ContainerAwareCommand | |||
15 | ->setName('wallabag:user:list') | 17 | ->setName('wallabag:user:list') |
16 | ->setDescription('List all users') | 18 | ->setDescription('List all users') |
17 | ->setHelp('This command list all existing users') | 19 | ->setHelp('This command list all existing users') |
20 | ->addArgument('search', InputArgument::OPTIONAL, 'Filter list by given search term') | ||
21 | ->addOption('limit', 'l', InputOption::VALUE_REQUIRED, 'Max number of displayed users', 100) | ||
18 | ; | 22 | ; |
19 | } | 23 | } |
20 | 24 | ||
@@ -22,7 +26,14 @@ class ListUserCommand extends ContainerAwareCommand | |||
22 | { | 26 | { |
23 | $io = new SymfonyStyle($input, $output); | 27 | $io = new SymfonyStyle($input, $output); |
24 | 28 | ||
25 | $users = $this->getContainer()->get('wallabag_user.user_repository')->findAll(); | 29 | $users = $this->getContainer()->get('wallabag_user.user_repository') |
30 | ->getQueryBuilderForSearch($input->getArgument('search')) | ||
31 | ->setMaxResults($input->getOption('limit')) | ||
32 | ->getQuery() | ||
33 | ->getResult(); | ||
34 | |||
35 | $nbUsers = $this->getContainer()->get('wallabag_user.user_repository') | ||
36 | ->getSumUsers(); | ||
26 | 37 | ||
27 | $rows = []; | 38 | $rows = []; |
28 | foreach ($users as $user) { | 39 | foreach ($users as $user) { |
@@ -36,7 +47,14 @@ class ListUserCommand extends ContainerAwareCommand | |||
36 | 47 | ||
37 | $io->table(['username', 'email', 'is enabled?', 'is admin?'], $rows); | 48 | $io->table(['username', 'email', 'is enabled?', 'is admin?'], $rows); |
38 | 49 | ||
39 | $io->success(sprintf('%s user(s) displayed.', count($users))); | 50 | $io->success( |
51 | sprintf( | ||
52 | '%s/%s%s user(s) displayed.', | ||
53 | count($users), | ||
54 | $nbUsers, | ||
55 | $input->getArgument('search') === null ? '' : ' (filtered)' | ||
56 | ) | ||
57 | ); | ||
40 | 58 | ||
41 | return 0; | 59 | return 0; |
42 | } | 60 | } |