Skip to content

Instantly share code, notes, and snippets.

@ramsey
Created August 11, 2020 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramsey/1b7b19356b7e542d3c885ed4f82e4d82 to your computer and use it in GitHub Desktop.
Save ramsey/1b7b19356b7e542d3c885ed4f82e4d82 to your computer and use it in GitHub Desktop.
Simple example showing how multi-line responses work with symfony/console.
<?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);
@noniagriconomie
Copy link

symfony/console version 5.2 :)

@epitre
Copy link

epitre commented Sep 29, 2020

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