Add more details on verbose output #52
Dieser Commit ist enthalten in:
@ -3,6 +3,7 @@
|
||||
use Symfony\Component\Console\Command\Command as SymfonyCommand;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Todaymade\Daux\Daux;
|
||||
|
||||
class DauxCommand extends SymfonyCommand
|
||||
@ -50,9 +51,9 @@ class DauxCommand extends SymfonyCommand
|
||||
}
|
||||
}
|
||||
|
||||
protected function prepareDaux(InputInterface $input)
|
||||
protected function prepareDaux(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$daux = new Daux(Daux::STATIC_MODE);
|
||||
$daux = new Daux(Daux::STATIC_MODE, $output);
|
||||
|
||||
// Set the format if requested
|
||||
if ($input->hasOption('format') && $input->getOption('format')) {
|
||||
|
@ -42,7 +42,7 @@ class Generate extends DauxCommand
|
||||
$input = new ArgvInput($argv, $this->getDefinition());
|
||||
}
|
||||
|
||||
$daux = $this->prepareDaux($input);
|
||||
$daux = $this->prepareDaux($input, $output);
|
||||
|
||||
$width = (new Terminal)->getWidth();
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php namespace Todaymade\Daux\Console;
|
||||
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Todaymade\Daux\Daux;
|
||||
|
||||
trait RunAction
|
||||
{
|
||||
@ -8,23 +9,33 @@ trait RunAction
|
||||
return function_exists('mb_strlen') ? mb_strlen($content) : strlen($content);
|
||||
}
|
||||
|
||||
protected function runAction($title, OutputInterface $output, $width, \Closure $closure)
|
||||
protected function runAction($title, $width, \Closure $closure)
|
||||
{
|
||||
$output->write($title);
|
||||
$verbose = Daux::getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE;
|
||||
|
||||
Daux::write($title, $verbose);
|
||||
|
||||
// 8 is the length of the label + 2 let it breathe
|
||||
$padding = $width - $this->getLength($title) - 10;
|
||||
|
||||
try {
|
||||
$response = $closure(function ($content) use ($output, &$padding) {
|
||||
$response = $closure(function ($content) use (&$padding) {
|
||||
$padding -= $this->getLength($content);
|
||||
$output->write($content);
|
||||
Daux::write($content, $verbose);
|
||||
});
|
||||
} catch (\Exception $e) {
|
||||
$output->writeln(str_pad(' ', $padding) . '[ <fg=red>FAIL</fg=red> ]');
|
||||
$this->status($padding, '[ <fg=red>FAIL</fg=red> ]');
|
||||
throw $e;
|
||||
}
|
||||
$output->writeln(str_pad(' ', $padding) . '[ <fg=green>OK</fg=green> ]');
|
||||
$this->status($padding, '[ <fg=green>OK</fg=green> ]');
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
protected function status($padding, $content)
|
||||
{
|
||||
$verbose = Daux::getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE;
|
||||
$padding = $verbose ? '' : str_pad(' ', $padding);
|
||||
Daux::writeln($padding . $content);
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class Serve extends DauxCommand
|
||||
$host = $input->getOption('host');
|
||||
$port = $input->getOption('port');
|
||||
|
||||
$daux = $this->prepareDaux($input);
|
||||
$daux = $this->prepareDaux($input, $output);
|
||||
|
||||
// Daux can only serve HTML
|
||||
$daux->getParams()->setFormat('html');
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren