OutputWithLogger : add method for “error” output

2.x 2.7.3
Julien Rosset 8 months ago
parent fda925927b
commit 7fe0eea59d

@ -2,6 +2,7 @@
namespace jrosset\CliProgram;
use jrosset\CliProgram\Output\OutputWrapper;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
@ -19,7 +20,7 @@ abstract class CliHelper {
* @return OutputInterface The “error” output if exists, else the output itself
*/
public static final function getErrorOutput (OutputInterface $output): OutputInterface {
return $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output;
return $output instanceof ConsoleOutputInterface || $output instanceof OutputWrapper ? $output->getErrorOutput() : $output;
}
/**

@ -3,6 +3,7 @@
namespace jrosset\CliProgram\Output;
use InvalidArgumentException;
use jrosset\CliProgram\CliHelper;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Output\OutputInterface;
@ -38,6 +39,13 @@ class OutputWithLogger extends OutputWrapper {
$this->setLogger($logger);
}
/**
* @inheritDoc
*/
public function getErrorOutput (): self {
return new static(CliHelper::getErrorOutput($this), $this->logger);
}
/**
* The logger
*

@ -2,6 +2,7 @@
namespace jrosset\CliProgram\Output;
use jrosset\CliProgram\CliHelper;
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
use Symfony\Component\Console\Output\OutputInterface;
@ -31,6 +32,14 @@ abstract class OutputWrapper implements OutputInterface {
public function getOutput (): OutputInterface {
return $this->output;
}
/**
* The “error” output
*
* @return static The “error” output
*/
public function getErrorOutput (): self {
return new static(CliHelper::getErrorOutput($this));
}
/**
* @inheritDoc

Loading…
Cancel
Save