8000 Use SymfonyStyle · symfony/symfony@f8a816d · GitHub
[go: up one dir, main page]

Skip to content

Commit f8a816d

Browse files
committed
Use SymfonyStyle
1 parent 1b9f9eb commit f8a816d

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
use Symfony\Component\Console\Exception\CommandNotFoundException;
4242
use Symfony\Component\Console\Exception\LogicException;
4343
use Symfony\Component\Console\Question\ConfirmationQuestion;
44+
use Symfony\Component\Console\Style\SymfonyStyle;
4445
use Symfony\Component\Debug\ErrorHandler;
4546
use Symfony\Component\Debug\Exception\FatalThrowableError;
4647
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -241,9 +242,10 @@ public function doRun(InputInterface $input, OutputInterface $output)
241242
}
242243

243244
$alternative = $alternatives[0];
244-
$question = new ConfirmationQuestion(sprintf("<error>Command \"%s\" is not defined.</error>\n\nDo you want to run \"%s\" instead? [y/n] ", $name, $alternative), false);
245245

246-
if (!(new QuestionHelper())->ask($input, $output, $question)) {
246+
$style = new SymfonyStyle($input, $output);
247+
$style->block(sprintf("\nCommand \"%s\" is not defined.\n", $name), null, 'error');
248+
if (!$style->confirm(sprintf("Do you want to run \"%s\" instead? ", $alternative), false)) {
247249
if (null !== $this->dispatcher) {
248250
$event = new ConsoleErrorEvent($input, $output, $e);
249251
$this->dispatcher->dispatch(ConsoleEvents::ERROR, $event);

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,18 @@ public function testCanRunAlternativeCommandName()
485485
$tester = new ApplicationTester($application);
486486
$tester->setInputs(array('y'));
487487
$tester->run(array('command' => 'foos'), array('decorated' => false));
488-
$this->assertSame("Command \"foos\" is not defined.\n\nDo you want to run \"foo\" instead? [y/n] called\n", $tester->getDisplay(true));
488+
$this->assertSame(<<<OUTPUT
489+
490+
491+
Command "foos" is not defined.
492+
493+
494+
Do you want to run "foo" instead? (yes/no) [no]:
495+
>
496+
called
497+
498+
OUTPUT
499+
, $tester->getDisplay(true));
489500
}
490501

491502
public function testDontRunAlternativeCommandName()
@@ -497,7 +508,17 @@ public function testDontRunAlternativeCommandName()
497508
$tester->setInputs(array('n'));
498509
$exitCode = $tester->run(array('command' => 'foos'), array('decorated' => false));
499510
$this->assertSame(1, $exitCode);
500-
$this->assertSame("Command \"foos\" is not defined.\n\nDo you want to run \"foo\" instead? [y/n] ", $tester->getDisplay(true));
511+
$this->assertSame(<<<OUTPUT
512+
513+
514+
Command "foos" is not defined.
515+
516+
517+
Do you want to run "foo" instead? (yes/no) [no]:
518+
>
519+
520+
OUTPUT
521+
, $tester->getDisplay(true));
501522
}
502523

503524
public function provideInvalidCommandNamesSingle()

0 commit comments

Comments
 (0)
0