Created
August 11, 2020 21:43
-
-
Save ramsey/1b7b19356b7e542d3c885ed4f82e4d82 to your computer and use it in GitHub Desktop.
Simple example showing how multi-line responses work with symfony/console.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
use Symfony\Component\Console\Application; | |
use Symfony\Component\Console\Command\Command; | |
use Symfony\Component\Console\Input\ArgvInput; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Output\OutputInterface; | |
use Symfony\Component\Console\Question\Question; | |
use Symfony\Component\Console\Style\SymfonyStyle; | |
(static function (array $argv): void { | |
require __DIR__ . '/vendor/autoload.php'; | |
$command = new class('test') extends Command { | |
protected function execute(InputInterface $input, OutputInterface $output): int | |
{ | |
$style = new SymfonyStyle($input, $output); | |
$style->title('Test a Command'); | |
$question = new Question('What is the thing?'); | |
$question->setMultiline(true); | |
$thing = $style->askQuestion($question); | |
$style->block($thing ?? ''); | |
return Command::SUCCESS; | |
} | |
}; | |
$application = new Application('Test'); | |
$application->add($command); | |
$application->run(new ArgvInput($argv)); | |
})($argv); |
If I try Multiline first, and then no multiline, I have a problem.
It seems the ctrl+d is kind of "saved" and so, the command is "Aborted"
Am I the only one with this problem ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
symfony/console version 5.2
:)