aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJérémy Benoist <j0k3r@users.noreply.github.com>2017-07-30 08:31:04 +0200
committerGitHub <noreply@github.com>2017-07-30 08:31:04 +0200
commit882da5c5eb283cbc7a869182b26a69b8fbebda2b (patch)
treeaae7d4b497a77a1b2eeb5b82c1a0f2d56865e64b
parent4fc7eba34904a062cddf1e61956c48f27cb2e06c (diff)
parente1b33efb3dd7c9ebb4dcfb23a2ca5efbda0a05f6 (diff)
downloadwallabag-882da5c5eb283cbc7a869182b26a69b8fbebda2b.tar.gz
wallabag-882da5c5eb283cbc7a869182b26a69b8fbebda2b.tar.zst
wallabag-882da5c5eb283cbc7a869182b26a69b8fbebda2b.zip
Merge pull request #3297 from nclsHart/commands-better-rendering
Better rendering for all core commands
-rw-r--r--src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php19
-rw-r--r--src/Wallabag/CoreBundle/Command/ExportCommand.php11
-rw-r--r--src/Wallabag/CoreBundle/Command/InstallCommand.php87
-rw-r--r--src/Wallabag/CoreBundle/Command/ShowUserCommand.php10
-rw-r--r--src/Wallabag/CoreBundle/Command/TagAllCommand.php14
-rw-r--r--tests/Wallabag/CoreBundle/Command/ExportCommandTest.php3
-rw-r--r--tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php8
-rw-r--r--tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php3
8 files changed, 78 insertions, 77 deletions
diff --git a/src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php b/src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php
index b4aa4e47..1caaa391 100644
--- a/src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php
+++ b/src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php
@@ -7,13 +7,14 @@ use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7use Symfony\Component\Console\Input\InputArgument; 7use Symfony\Component\Console\Input\InputArgument;
8use Symfony\Component\Console\Input\InputInterface; 8use Symfony\Component\Console\Input\InputInterface;
9use Symfony\Component\Console\Output\OutputInterface; 9use Symfony\Component\Console\Output\OutputInterface;
10use Symfony\Component\Console\Style\SymfonyStyle;
10use Wallabag\CoreBundle\Entity\Entry; 11use Wallabag\CoreBundle\Entity\Entry;
11use Wallabag\UserBundle\Entity\User; 12use Wallabag\UserBundle\Entity\User;
12 13
13class CleanDuplicatesCommand extends ContainerAwareCommand 14class CleanDuplicatesCommand extends ContainerAwareCommand
14{ 15{
15 /** @var OutputInterface */ 16 /** @var SymfonyStyle */
16 protected $output; 17 protected $io;
17 18
18 protected $duplicates = 0; 19 protected $duplicates = 0;
19 20
@@ -32,7 +33,7 @@ class CleanDuplicatesCommand extends ContainerAwareCommand
32 33
33 protected function execute(InputInterface $input, OutputInterface $output) 34 protected function execute(InputInterface $input, OutputInterface $output)
34 { 35 {
35 $this->output = $output; 36 $this->io = new SymfonyStyle($input, $output);
36 37
37 $username = $input->getArgument('username'); 38 $username = $input->getArgument('username');
38 39
@@ -41,20 +42,22 @@ class CleanDuplicatesCommand extends ContainerAwareCommand
41 $user = $this->getUser($username); 42 $user = $this->getUser($username);
42 $this->cleanDuplicates($user); 43 $this->cleanDuplicates($user);
43 } catch (NoResultException $e) { 44 } catch (NoResultException $e) {
44 $output->writeln(sprintf('<error>User "%s" not found.</error>', $username)); 45 $this->io->error(sprintf('User "%s" not found.', $username));
45 46
46 return 1; 47 return 1;
47 } 48 }
49
50 $this->io->success('Finished cleaning.');
48 } else { 51 } else {
49 $users = $this->getContainer()->get('wallabag_user.user_repository')->findAll(); 52 $users = $this->getContainer()->get('wallabag_user.user_repository')->findAll();
50 53
51 $output->writeln(sprintf('Cleaning through %d user accounts', count($users))); 54 $this->io->text(sprintf('Cleaning through <info>%d</info> user accounts', count($users)));
52 55
53 foreach ($users as $user) { 56 foreach ($users as $user) {
54 $output->writeln(sprintf('Processing user %s', $user->getUsername())); 57 $this->io->text(sprintf('Processing user <info>%s</info>', $user->getUsername()));
55 $this->cleanDuplicates($user); 58 $this->cleanDuplicates($user);
56 } 59 }
57 $output->writeln(sprintf('Finished cleaning. %d duplicates found in total', $this->duplicates)); 60 $this->io->success(sprintf('Finished cleaning. %d duplicates found in total', $this->duplicates));
58 } 61 }
59 62
60 return 0; 63 return 0;
@@ -88,7 +91,7 @@ class CleanDuplicatesCommand extends ContainerAwareCommand
88 91
89 $this->duplicates += $duplicatesCount; 92 $this->duplicates += $duplicatesCount;
90 93
91 $this->output->writeln(sprintf('Cleaned %d duplicates for user %s', $duplicatesCount, $user->getUserName())); 94 $this->io->text(sprintf('Cleaned <info>%d</info> duplicates for user <info>%s</info>', $duplicatesCount, $user->getUserName()));
92 } 95 }
93 96
94 private function similarUrl($url) 97 private function similarUrl($url)
diff --git a/src/Wallabag/CoreBundle/Command/ExportCommand.php b/src/Wallabag/CoreBundle/Command/ExportCommand.php
index 291926e4..b07087c8 100644
--- a/src/Wallabag/CoreBundle/Command/ExportCommand.php
+++ b/src/Wallabag/CoreBundle/Command/ExportCommand.php
@@ -7,6 +7,7 @@ use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7use Symfony\Component\Console\Input\InputArgument; 7use Symfony\Component\Console\Input\InputArgument;
8use Symfony\Component\Console\Input\InputInterface; 8use Symfony\Component\Console\Input\InputInterface;
9use Symfony\Component\Console\Output\OutputInterface; 9use Symfony\Component\Console\Output\OutputInterface;
10use Symfony\Component\Console\Style\SymfonyStyle;
10 11
11class ExportCommand extends ContainerAwareCommand 12class ExportCommand extends ContainerAwareCommand
12{ 13{
@@ -31,10 +32,12 @@ class ExportCommand extends ContainerAwareCommand
31 32
32 protected function execute(InputInterface $input, OutputInterface $output) 33 protected function execute(InputInterface $input, OutputInterface $output)
33 { 34 {
35 $io = new SymfonyStyle($input, $output);
36
34 try { 37 try {
35 $user = $this->getContainer()->get('wallabag_user.user_repository')->findOneByUserName($input->getArgument('username')); 38 $user = $this->getContainer()->get('wallabag_user.user_repository')->findOneByUserName($input->getArgument('username'));
36 } catch (NoResultException $e) { 39 } catch (NoResultException $e) {
37 $output->writeln(sprintf('<error>User "%s" not found.</error>', $input->getArgument('username'))); 40 $io->error(sprintf('User "%s" not found.', $input->getArgument('username')));
38 41
39 return 1; 42 return 1;
40 } 43 }
@@ -44,7 +47,7 @@ class ExportCommand extends ContainerAwareCommand
44 ->getQuery() 47 ->getQuery()
45 ->getResult(); 48 ->getResult();
46 49
47 $output->write(sprintf('Exporting %d entrie(s) for user « <comment>%s</comment> »... ', count($entries), $user->getUserName())); 50 $io->text(sprintf('Exporting <info>%d</info> entrie(s) for user <info>%s</info>...', count($entries), $user->getUserName()));
48 51
49 $filePath = $input->getArgument('filepath'); 52 $filePath = $input->getArgument('filepath');
50 53
@@ -60,12 +63,12 @@ class ExportCommand extends ContainerAwareCommand
60 ->exportJsonData(); 63 ->exportJsonData();
61 file_put_contents($filePath, $data); 64 file_put_contents($filePath, $data);
62 } catch (\InvalidArgumentException $e) { 65 } catch (\InvalidArgumentException $e) {
63 $output->writeln(sprintf('<error>Error: "%s"</error>', $e->getMessage())); 66 $io->error(sprintf('Error: "%s"', $e->getMessage()));
64 67
65 return 1; 68 return 1;
66 } 69 }
67 70
68 $output->writeln('<info>Done.</info>'); 71 $io->success('Done.');
69 72
70 return 0; 73 return 0;
71 } 74 }
diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php
index c7809053..877dbfa2 100644
--- a/src/Wallabag/CoreBundle/Command/InstallCommand.php
+++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php
@@ -6,14 +6,13 @@ use Craue\ConfigBundle\Entity\Setting;
6use FOS\UserBundle\Event\UserEvent; 6use FOS\UserBundle\Event\UserEvent;
7use FOS\UserBundle\FOSUserEvents; 7use FOS\UserBundle\FOSUserEvents;
8use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; 8use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
9use Symfony\Component\Console\Helper\Table;
10use Symfony\Component\Console\Input\ArrayInput; 9use Symfony\Component\Console\Input\ArrayInput;
11use Symfony\Component\Console\Input\InputInterface; 10use Symfony\Component\Console\Input\InputInterface;
12use Symfony\Component\Console\Input\InputOption; 11use Symfony\Component\Console\Input\InputOption;
13use Symfony\Component\Console\Output\BufferedOutput; 12use Symfony\Component\Console\Output\BufferedOutput;
14use Symfony\Component\Console\Output\OutputInterface; 13use Symfony\Component\Console\Output\OutputInterface;
15use Symfony\Component\Console\Question\ConfirmationQuestion;
16use Symfony\Component\Console\Question\Question; 14use Symfony\Component\Console\Question\Question;
15use Symfony\Component\Console\Style\SymfonyStyle;
17 16
18class InstallCommand extends ContainerAwareCommand 17class InstallCommand extends ContainerAwareCommand
19{ 18{
@@ -23,9 +22,9 @@ class InstallCommand extends ContainerAwareCommand
23 protected $defaultInput; 22 protected $defaultInput;
24 23
25 /** 24 /**
26 * @var OutputInterface 25 * @var SymfonyStyle
27 */ 26 */
28 protected $defaultOutput; 27 protected $io;
29 28
30 /** 29 /**
31 * @var array 30 * @var array
@@ -52,10 +51,10 @@ class InstallCommand extends ContainerAwareCommand
52 protected function execute(InputInterface $input, OutputInterface $output) 51 protected function execute(InputInterface $input, OutputInterface $output)
53 { 52 {
54 $this->defaultInput = $input; 53 $this->defaultInput = $input;
55 $this->defaultOutput = $output;
56 54
57 $output->writeln('<info>Installing wallabag...</info>'); 55 $this->io = new SymfonyStyle($input, $output);
58 $output->writeln(''); 56
57 $this->io->title('Wallabag installer');
59 58
60 $this 59 $this
61 ->checkRequirements() 60 ->checkRequirements()
@@ -65,13 +64,14 @@ class InstallCommand extends ContainerAwareCommand
65 ->runMigrations() 64 ->runMigrations()
66 ; 65 ;
67 66
68 $output->writeln('<info>wallabag has been successfully installed.</info>'); 67 $this->io->success('Wallabag has been successfully installed.');
69 $output->writeln('<comment>Just execute `php bin/console server:run --env=prod` for using wallabag: http://localhost:8000</comment>'); 68 $this->io->note('Just execute `php bin/console server:run --env=prod` for using wallabag: http://localhost:8000');
70 } 69 }
71 70
72 protected function checkRequirements() 71 protected function checkRequirements()
73 { 72 {
74 $this->defaultOutput->writeln('<info><comment>Step 1 of 5.</comment> Checking system requirements.</info>'); 73 $this->io->section('Step 1 of 5: Checking system requirements.');
74
75 $doctrineManager = $this->getContainer()->get('doctrine')->getManager(); 75 $doctrineManager = $this->getContainer()->get('doctrine')->getManager();
76 76
77 $rows = []; 77 $rows = [];
@@ -156,30 +156,24 @@ class InstallCommand extends ContainerAwareCommand
156 $rows[] = [$label, $status, $help]; 156 $rows[] = [$label, $status, $help];
157 } 157 }
158 158
159 $table = new Table($this->defaultOutput); 159 $this->io->table(['Checked', 'Status', 'Recommendation'], $rows);
160 $table
161 ->setHeaders(['Checked', 'Status', 'Recommendation'])
162 ->setRows($rows)
163 ->render();
164 160
165 if (!$fulfilled) { 161 if (!$fulfilled) {
166 throw new \RuntimeException('Some system requirements are not fulfilled. Please check output messages and fix them.'); 162 throw new \RuntimeException('Some system requirements are not fulfilled. Please check output messages and fix them.');
167 } 163 }
168 164
169 $this->defaultOutput->writeln('<info>Success! Your system can run wallabag properly.</info>'); 165 $this->io->success('Success! Your system can run wallabag properly.');
170
171 $this->defaultOutput->writeln('');
172 166
173 return $this; 167 return $this;
174 } 168 }
175 169
176 protected function setupDatabase() 170 protected function setupDatabase()
177 { 171 {
178 $this->defaultOutput->writeln('<info><comment>Step 2 of 5.</comment> Setting up database.</info>'); 172 $this->io->section('Step 2 of 5: Setting up database.');
179 173
180 // user want to reset everything? Don't care about what is already here 174 // user want to reset everything? Don't care about what is already here
181 if (true === $this->defaultInput->getOption('reset')) { 175 if (true === $this->defaultInput->getOption('reset')) {
182 $this->defaultOutput->writeln('Dropping database, creating database and schema, clearing the cache'); 176 $this->io->text('Dropping database, creating database and schema, clearing the cache');
183 177
184 $this 178 $this
185 ->runCommand('doctrine:database:drop', ['--force' => true]) 179 ->runCommand('doctrine:database:drop', ['--force' => true])
@@ -188,13 +182,13 @@ class InstallCommand extends ContainerAwareCommand
188 ->runCommand('cache:clear') 182 ->runCommand('cache:clear')
189 ; 183 ;
190 184
191 $this->defaultOutput->writeln(''); 185 $this->io->newLine();
192 186
193 return $this; 187 return $this;
194 } 188 }
195 189
196 if (!$this->isDatabasePresent()) { 190 if (!$this->isDatabasePresent()) {
197 $this->defaultOutput->writeln('Creating database and schema, clearing the cache'); 191 $this->io->text('Creating database and schema, clearing the cache');
198 192
199 $this 193 $this
200 ->runCommand('doctrine:database:create') 194 ->runCommand('doctrine:database:create')
@@ -202,16 +196,13 @@ class InstallCommand extends ContainerAwareCommand
202 ->runCommand('cache:clear') 196 ->runCommand('cache:clear')
203 ; 197 ;
204 198
205 $this->defaultOutput->writeln(''); 199 $this->io->newLine();
206 200
207 return $this; 201 return $this;
208 } 202 }
209 203
210 $questionHelper = $this->getHelper('question'); 204 if ($this->io->confirm('It appears that your database already exists. Would you like to reset it?', false)) {
211 $question = new ConfirmationQuestion('It appears that your database already exists. Would you like to reset it? (y/N)', false); 205 $this->io->text('Dropping database, creating database and schema...');
212
213 if ($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)) {
214 $this->defaultOutput->writeln('Dropping database, creating database and schema');
215 206
216 $this 207 $this
217 ->runCommand('doctrine:database:drop', ['--force' => true]) 208 ->runCommand('doctrine:database:drop', ['--force' => true])
@@ -219,9 +210,8 @@ class InstallCommand extends ContainerAwareCommand
219 ->runCommand('doctrine:schema:create') 210 ->runCommand('doctrine:schema:create')
220 ; 211 ;
221 } elseif ($this->isSchemaPresent()) { 212 } elseif ($this->isSchemaPresent()) {
222 $question = new ConfirmationQuestion('Seems like your database contains schema. Do you want to reset it? (y/N)', false); 213 if ($this->io->confirm('Seems like your database contains schema. Do you want to reset it?', false)) {
223 if ($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)) { 214 $this->io->text('Dropping schema and creating schema...');
224 $this->defaultOutput->writeln('Dropping schema and creating schema');
225 215
226 $this 216 $this
227 ->runCommand('doctrine:schema:drop', ['--force' => true]) 217 ->runCommand('doctrine:schema:drop', ['--force' => true])
@@ -229,29 +219,27 @@ class InstallCommand extends ContainerAwareCommand
229 ; 219 ;
230 } 220 }
231 } else { 221 } else {
232 $this->defaultOutput->writeln('Creating schema'); 222 $this->io->text('Creating schema...');
233 223
234 $this 224 $this
235 ->runCommand('doctrine:schema:create') 225 ->runCommand('doctrine:schema:create')
236 ; 226 ;
237 } 227 }
238 228
239 $this->defaultOutput->writeln('Clearing the cache'); 229 $this->io->text('Clearing the cache...');
240 $this->runCommand('cache:clear'); 230 $this->runCommand('cache:clear');
241 231
242 $this->defaultOutput->writeln(''); 232 $this->io->newLine();
233 $this->io->text('<info>Database successfully setup.</info>');
243 234
244 return $this; 235 return $this;
245 } 236 }
246 237
247 protected function setupAdmin() 238 protected function setupAdmin()
248 { 239 {
249 $this->defaultOutput->writeln('<info><comment>Step 3 of 5.</comment> Administration setup.</info>'); 240 $this->io->section('Step 3 of 5: Administration setup.');
250
251 $questionHelper = $this->getHelperSet()->get('question');
252 $question = new ConfirmationQuestion('Would you like to create a new admin user (recommended) ? (Y/n)', true);
253 241
254 if (!$questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)) { 242 if (!$this->io->confirm('Would you like to create a new admin user (recommended)?', true)) {
255 return $this; 243 return $this;
256 } 244 }
257 245
@@ -260,14 +248,13 @@ class InstallCommand extends ContainerAwareCommand
260 $userManager = $this->getContainer()->get('fos_user.user_manager'); 248 $userManager = $this->getContainer()->get('fos_user.user_manager');
261 $user = $userManager->createUser(); 249 $user = $userManager->createUser();
262 250
263 $question = new Question('Username (default: wallabag) :', 'wallabag'); 251 $user->setUsername($this->io->ask('Username', 'wallabag'));
264 $user->setUsername($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question));
265 252
266 $question = new Question('Password (default: wallabag) :', 'wallabag'); 253 $question = new Question('Password', 'wallabag');
267 $user->setPlainPassword($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)); 254 $question->setHidden(true);
255 $user->setPlainPassword($this->io->askQuestion($question));
268 256
269 $question = new Question('Email:', ''); 257 $user->setEmail($this->io->ask('Email', ''));
270 $user->setEmail($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question));
271 258
272 $user->setEnabled(true); 259 $user->setEnabled(true);
273 $user->addRole('ROLE_SUPER_ADMIN'); 260 $user->addRole('ROLE_SUPER_ADMIN');
@@ -278,14 +265,14 @@ class InstallCommand extends ContainerAwareCommand
278 $event = new UserEvent($user); 265 $event = new UserEvent($user);
279 $this->getContainer()->get('event_dispatcher')->dispatch(FOSUserEvents::USER_CREATED, $event); 266 $this->getContainer()->get('event_dispatcher')->dispatch(FOSUserEvents::USER_CREATED, $event);
280 267
281 $this->defaultOutput->writeln(''); 268 $this->io->text('<info>Administration successfully setup.</info>');
282 269
283 return $this; 270 return $this;
284 } 271 }
285 272
286 protected function setupConfig() 273 protected function setupConfig()
287 { 274 {
288 $this->defaultOutput->writeln('<info><comment>Step 4 of 5.</comment> Config setup.</info>'); 275 $this->io->section('Step 4 of 5: Config setup.');
289 $em = $this->getContainer()->get('doctrine.orm.entity_manager'); 276 $em = $this->getContainer()->get('doctrine.orm.entity_manager');
290 277
291 // cleanup before insert new stuff 278 // cleanup before insert new stuff
@@ -301,18 +288,20 @@ class InstallCommand extends ContainerAwareCommand
301 288
302 $em->flush(); 289 $em->flush();
303 290
304 $this->defaultOutput->writeln(''); 291 $this->io->text('<info>Config successfully setup.</info>');
305 292
306 return $this; 293 return $this;
307 } 294 }
308 295
309 protected function runMigrations() 296 protected function runMigrations()
310 { 297 {
311 $this->defaultOutput->writeln('<info><comment>Step 5 of 5.</comment> Run migrations.</info>'); 298 $this->io->section('Step 5 of 5: Run migrations.');
312 299
313 $this 300 $this
314 ->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true]); 301 ->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true]);
315 302
303 $this->io->text('<info>Migrations successfully executed.</info>');
304
316 return $this; 305 return $this;
317 } 306 }
318 307
diff --git a/src/Wallabag/CoreBundle/Command/ShowUserCommand.php b/src/Wallabag/CoreBundle/Command/ShowUserCommand.php
index 090309d9..2dca32c4 100644
--- a/src/Wallabag/CoreBundle/Command/ShowUserCommand.php
+++ b/src/Wallabag/CoreBundle/Command/ShowUserCommand.php
@@ -52,11 +52,11 @@ class ShowUserCommand extends ContainerAwareCommand
52 private function showUser(User $user) 52 private function showUser(User $user)
53 { 53 {
54 $this->io->listing([ 54 $this->io->listing([
55 sprintf('Username : %s', $user->getUsername()), 55 sprintf('Username: %s', $user->getUsername()),
56 sprintf('Email : %s', $user->getEmail()), 56 sprintf('Email: %s', $user->getEmail()),
57 sprintf('Display name : %s', $user->getName()), 57 sprintf('Display name: %s', $user->getName()),
58 sprintf('Creation date : %s', $user->getCreatedAt()->format('Y-m-d H:i:s')), 58 sprintf('Creation date: %s', $user->getCreatedAt()->format('Y-m-d H:i:s')),
59 sprintf('Last login : %s', $user->getLastLogin() !== null ? $user->getLastLogin()->format('Y-m-d H:i:s') : 'never'), 59 sprintf('Last login: %s', $user->getLastLogin() !== null ? $user->getLastLogin()->format('Y-m-d H:i:s') : 'never'),
60 sprintf('2FA activated: %s', $user->isTwoFactorAuthentication() ? 'yes' : 'no'), 60 sprintf('2FA activated: %s', $user->isTwoFactorAuthentication() ? 'yes' : 'no'),
61 ]); 61 ]);
62 } 62 }
diff --git a/src/Wallabag/CoreBundle/Command/TagAllCommand.php b/src/Wallabag/CoreBundle/Command/TagAllCommand.php
index 9843674e..4afac2d4 100644
--- a/src/Wallabag/CoreBundle/Command/TagAllCommand.php
+++ b/src/Wallabag/CoreBundle/Command/TagAllCommand.php
@@ -7,6 +7,7 @@ use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7use Symfony\Component\Console\Input\InputArgument; 7use Symfony\Component\Console\Input\InputArgument;
8use Symfony\Component\Console\Input\InputInterface; 8use Symfony\Component\Console\Input\InputInterface;
9use Symfony\Component\Console\Output\OutputInterface; 9use Symfony\Component\Console\Output\OutputInterface;
10use Symfony\Component\Console\Style\SymfonyStyle;
10 11
11class TagAllCommand extends ContainerAwareCommand 12class TagAllCommand extends ContainerAwareCommand
12{ 13{
@@ -25,21 +26,22 @@ class TagAllCommand extends ContainerAwareCommand
25 26
26 protected function execute(InputInterface $input, OutputInterface $output) 27 protected function execute(InputInterface $input, OutputInterface $output)
27 { 28 {
29 $io = new SymfonyStyle($input, $output);
30
28 try { 31 try {
29 $user = $this->getUser($input->getArgument('username')); 32 $user = $this->getUser($input->getArgument('username'));
30 } catch (NoResultException $e) { 33 } catch (NoResultException $e) {
31 $output->writeln(sprintf('<error>User "%s" not found.</error>', $input->getArgument('username'))); 34 $io->error(sprintf('User "%s" not found.', $input->getArgument('username')));
32 35
33 return 1; 36 return 1;
34 } 37 }
35 $tagger = $this->getContainer()->get('wallabag_core.rule_based_tagger'); 38 $tagger = $this->getContainer()->get('wallabag_core.rule_based_tagger');
36 39
37 $output->write(sprintf('Tagging entries for user « <comment>%s</comment> »... ', $user->getUserName())); 40 $io->text(sprintf('Tagging entries for user <info>%s</info>...', $user->getUserName()));
38 41
39 $entries = $tagger->tagAllForUser($user); 42 $entries = $tagger->tagAllForUser($user);
40 43
41 $output->writeln('<info>Done.</info>'); 44 $io->text('Persist entries... ');
42 $output->write(sprintf('Persist entries ... ', $user->getUserName()));
43 45
44 $em = $this->getDoctrine()->getManager(); 46 $em = $this->getDoctrine()->getManager();
45 foreach ($entries as $entry) { 47 foreach ($entries as $entry) {
@@ -47,7 +49,9 @@ class TagAllCommand extends ContainerAwareCommand
47 } 49 }
48 $em->flush(); 50 $em->flush();
49 51
50 $output->writeln('<info>Done.</info>'); 52 $io->success('Done.');
53
54 return 0;
51 } 55 }
52 56
53 /** 57 /**
diff --git a/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php
index 25de2730..210b2ab6 100644
--- a/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php
+++ b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php
@@ -55,7 +55,8 @@ class ExportCommandTest extends WallabagCoreTestCase
55 'username' => 'admin', 55 'username' => 'admin',
56 ]); 56 ]);
57 57
58 $this->assertContains('Exporting 5 entrie(s) for user « admin »... Done', $tester->getDisplay()); 58 $this->assertContains('Exporting 5 entrie(s) for user admin...', $tester->getDisplay());
59 $this->assertContains('Done', $tester->getDisplay());
59 $this->assertFileExists('admin-export.json'); 60 $this->assertFileExists('admin-export.json');
60 } 61 }
61 62
diff --git a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php
index c0a4acfa..9b34f2a0 100644
--- a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php
+++ b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php
@@ -56,9 +56,9 @@ class ShowUserCommandTest extends WallabagCoreTestCase
56 'username' => 'admin', 56 'username' => 'admin',
57 ]); 57 ]);
58 58
59 $this->assertContains('Username : admin', $tester->getDisplay()); 59 $this->assertContains('Username: admin', $tester->getDisplay());
60 $this->assertContains('Email : bigboss@wallabag.org', $tester->getDisplay()); 60 $this->assertContains('Email: bigboss@wallabag.org', $tester->getDisplay());
61 $this->assertContains('Display name : Big boss', $tester->getDisplay()); 61 $this->assertContains('Display name: Big boss', $tester->getDisplay());
62 $this->assertContains('2FA activated: no', $tester->getDisplay()); 62 $this->assertContains('2FA activated: no', $tester->getDisplay());
63 } 63 }
64 64
@@ -88,6 +88,6 @@ class ShowUserCommandTest extends WallabagCoreTestCase
88 'username' => 'admin', 88 'username' => 'admin',
89 ]); 89 ]);
90 90
91 $this->assertContains('Display name : Bug boss', $tester->getDisplay()); 91 $this->assertContains('Display name: Bug boss', $tester->getDisplay());
92 } 92 }
93} 93}
diff --git a/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php b/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php
index 96d0e91f..b1e56a10 100644
--- a/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php
+++ b/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php
@@ -55,6 +55,7 @@ class TagAllCommandTest extends WallabagCoreTestCase
55 'username' => 'admin', 55 'username' => 'admin',
56 ]); 56 ]);
57 57
58 $this->assertContains('Tagging entries for user « admin »... Done', $tester->getDisplay()); 58 $this->assertContains('Tagging entries for user admin...', $tester->getDisplay());
59 $this->assertContains('Done', $tester->getDisplay());
59 } 60 }
60} 61}