8
0
Fork 0

Add more details on verbose output #52

Dieser Commit ist enthalten in:
Stéphane Goetz 2018-06-05 20:31:51 +02:00
Ursprung 29a8a8d9cc
Commit 41c355edb1
11 geänderte Dateien mit 71 neuen und 20 gelöschten Zeilen

Datei anzeigen

@ -3,6 +3,7 @@
use Symfony\Component\Console\Command\Command as SymfonyCommand; use Symfony\Component\Console\Command\Command as SymfonyCommand;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Todaymade\Daux\Daux; use Todaymade\Daux\Daux;
class DauxCommand extends SymfonyCommand 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 // Set the format if requested
if ($input->hasOption('format') && $input->getOption('format')) { if ($input->hasOption('format') && $input->getOption('format')) {

Datei anzeigen

@ -42,7 +42,7 @@ class Generate extends DauxCommand
$input = new ArgvInput($argv, $this->getDefinition()); $input = new ArgvInput($argv, $this->getDefinition());
} }
$daux = $this->prepareDaux($input); $daux = $this->prepareDaux($input, $output);
$width = (new Terminal)->getWidth(); $width = (new Terminal)->getWidth();

Datei anzeigen

@ -1,6 +1,7 @@
<?php namespace Todaymade\Daux\Console; <?php namespace Todaymade\Daux\Console;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Todaymade\Daux\Daux;
trait RunAction trait RunAction
{ {
@ -8,23 +9,33 @@ trait RunAction
return function_exists('mb_strlen') ? mb_strlen($content) : strlen($content); 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 // 8 is the length of the label + 2 let it breathe
$padding = $width - $this->getLength($title) - 10; $padding = $width - $this->getLength($title) - 10;
try { try {
$response = $closure(function ($content) use ($output, &$padding) { $response = $closure(function ($content) use (&$padding) {
$padding -= $this->getLength($content); $padding -= $this->getLength($content);
$output->write($content); Daux::write($content, $verbose);
}); });
} catch (\Exception $e) { } catch (\Exception $e) {
$output->writeln(str_pad(' ', $padding) . '[ <fg=red>FAIL</fg=red> ]'); $this->status($padding, '[ <fg=red>FAIL</fg=red> ]');
throw $e; throw $e;
} }
$output->writeln(str_pad(' ', $padding) . '[ <fg=green>OK</fg=green> ]'); $this->status($padding, '[ <fg=green>OK</fg=green> ]');
return $response; return $response;
} }
protected function status($padding, $content)
{
$verbose = Daux::getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE;
$padding = $verbose ? '' : str_pad(' ', $padding);
Daux::writeln($padding . $content);
}
} }

Datei anzeigen

@ -30,7 +30,7 @@ class Serve extends DauxCommand
$host = $input->getOption('host'); $host = $input->getOption('host');
$port = $input->getOption('port'); $port = $input->getOption('port');
$daux = $this->prepareDaux($input); $daux = $this->prepareDaux($input, $output);
// Daux can only serve HTML // Daux can only serve HTML
$daux->getParams()->setFormat('html'); $daux->getParams()->setFormat('html');

Datei anzeigen

@ -1,6 +1,7 @@
<?php namespace Todaymade\Daux; <?php namespace Todaymade\Daux;
use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Todaymade\Daux\ContentTypes\ContentTypeHandler; use Todaymade\Daux\ContentTypes\ContentTypeHandler;
use Todaymade\Daux\Tree\Builder; use Todaymade\Daux\Tree\Builder;
use Todaymade\Daux\Tree\Content; use Todaymade\Daux\Tree\Content;
@ -12,6 +13,8 @@ class Daux
const STATIC_MODE = 'DAUX_STATIC'; const STATIC_MODE = 'DAUX_STATIC';
const LIVE_MODE = 'DAUX_LIVE'; const LIVE_MODE = 'DAUX_LIVE';
public static $output;
/** @var string */ /** @var string */
public $local_base; public $local_base;
@ -44,8 +47,9 @@ class Daux
/** /**
* @param string $mode * @param string $mode
*/ */
public function __construct($mode) public function __construct($mode, OutputInterface $output)
{ {
Daux::$output = $output;
$this->mode = $mode; $this->mode = $mode;
$this->local_base = dirname(__DIR__); $this->local_base = dirname(__DIR__);
@ -236,7 +240,7 @@ class Daux
public function getProcessor() public function getProcessor()
{ {
if (!$this->processor) { if (!$this->processor) {
$this->processor = new Processor($this, new NullOutput(), 0); $this->processor = new Processor($this, Daux::getOutput(), 0);
} }
return $this->processor; return $this->processor;
@ -347,4 +351,37 @@ class Daux
return $this->validExtensions = $this->getContentTypeHandler()->getContentExtensions(); return $this->validExtensions = $this->getContentTypeHandler()->getContentExtensions();
} }
public static function getOutput() {
if (!Daux::$output) {
Daux:$output = new NullOutput();
}
return Daux::$output;
}
/**
* Writes a message to the output.
*
* @param string|array $messages The message as an array of lines or a single string
* @param bool $newline Whether to add a newline
* @param int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL
*/
public static function write($messages, $newline = false, $options = 0) {
Daux::$output->write($messages, $newline, $options);
}
/**
* Writes a message to the output and adds a newline at the end.
*
* @param string|array $messages The message as an array of lines of a single string
* @param int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL
*/
public static function writeln($messages, $options = 0) {
Daux::write($messages, true, $options);
}
public static function getVerbosity() {
return Daux::getOutput()->getVerbosity();
}
} }

Datei anzeigen

@ -79,7 +79,6 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator
$tree = $this->runAction( $tree = $this->runAction(
'Generating Tree ...', 'Generating Tree ...',
$output,
$width, $width,
function() use ($params) { function() use ($params) {
$tree = $this->generateRecursive($this->daux->tree, $params); $tree = $this->generateRecursive($this->daux->tree, $params);

Datei anzeigen

@ -41,7 +41,7 @@ class Publisher
public function run($title, $closure) public function run($title, $closure)
{ {
try { try {
return $this->runAction($title, $this->output, $this->width, $closure); return $this->runAction($title, $this->width, $closure);
} catch (BadResponseException $e) { } catch (BadResponseException $e) {
$this->output->writeLn('<fg=red>' . $e->getMessage() . '</>'); $this->output->writeLn('<fg=red>' . $e->getMessage() . '</>');
} }

Datei anzeigen

@ -80,7 +80,6 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator
$this->runAction( $this->runAction(
'Copying Static assets ...', 'Copying Static assets ...',
$output,
$width, $width,
function() use ($destination, $params) { function() use ($destination, $params) {
$this->ensureEmptyDestination($destination); $this->ensureEmptyDestination($destination);
@ -194,7 +193,6 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator
} else { } else {
$this->runAction( $this->runAction(
'- ' . $node->getUrl(), '- ' . $node->getUrl(),
$output,
$width, $width,
function() use ($node, $output_dir, $key, $params, $index_pages) { function() use ($node, $output_dir, $key, $params, $index_pages) {
if ($node instanceof Raw) { if ($node instanceof Raw) {

Datei anzeigen

@ -1,6 +1,7 @@
<?php namespace Todaymade\Daux\Format\HTML; <?php namespace Todaymade\Daux\Format\HTML;
use League\Plates\Engine; use League\Plates\Engine;
use Symfony\Component\Console\Output\OutputInterface;
use Todaymade\Daux\Config; use Todaymade\Daux\Config;
use Todaymade\Daux\Daux; use Todaymade\Daux\Daux;
use Todaymade\Daux\Tree\Content; use Todaymade\Daux\Tree\Content;
@ -43,6 +44,8 @@ class Template
} }
$this->engine->addFolder('theme', $theme, true); $this->engine->addFolder('theme', $theme, true);
Daux::writeln("Starting Template engine with basedir '$base' and theme folder '$theme'.", OutputInterface::VERBOSITY_VERBOSE);
$this->registerFunctions($this->engine); $this->registerFunctions($this->engine);
return $this->engine; return $this->engine;
@ -65,6 +68,8 @@ class Template
'tree' => $data['params']['tree'], 'tree' => $data['params']['tree'],
]); ]);
Daux::writeln("Rendering template '$name'", OutputInterface::VERBOSITY_VERBOSE);
return $engine->render($name, $data); return $engine->render($name, $data);
} }

Datei anzeigen

@ -74,7 +74,6 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator
return $pdf; return $pdf;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -90,7 +89,6 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator
while ($current) { while ($current) {
$this->runAction( $this->runAction(
'Generating ' . $current->getTitle(), 'Generating ' . $current->getTitle(),
$output,
$width, $width,
function () use ($book, $current, $params) { function () use ($book, $current, $params) {
$contentType = $this->daux->getContentTypeHandler()->getType($current); $contentType = $this->daux->getContentTypeHandler()->getType($current);

Datei anzeigen

@ -31,12 +31,14 @@ class Server
*/ */
public static function serve() public static function serve()
{ {
$daux = new Daux(Daux::LIVE_MODE); $output = new NullOutput();
$daux = new Daux(Daux::LIVE_MODE, $output);
$daux->initializeConfiguration(); $daux->initializeConfiguration();
$class = $daux->getProcessorClass(); $class = $daux->getProcessorClass();
if (!empty($class)) { if (!empty($class)) {
$daux->setProcessor(new $class($daux, new NullOutput(), 0)); $daux->setProcessor(new $class($daux, $output, 0));
} }
// Set this critical configuration // Set this critical configuration