OutputWithLogger : add method for “error” output

master 3.8.5
Julien Rosset 8 months ago
parent 8bb34e1b6e
commit 8055eb9132

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

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

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

Loading…
Cancel
Save