Add more details on verbose output #52
This commit is contained in:
bovenliggende
29a8a8d9cc
commit
41c355edb1
@ -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');
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php namespace Todaymade\Daux;
|
||||
|
||||
use Symfony\Component\Console\Output\NullOutput;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Todaymade\Daux\ContentTypes\ContentTypeHandler;
|
||||
use Todaymade\Daux\Tree\Builder;
|
||||
use Todaymade\Daux\Tree\Content;
|
||||
@ -12,6 +13,8 @@ class Daux
|
||||
const STATIC_MODE = 'DAUX_STATIC';
|
||||
const LIVE_MODE = 'DAUX_LIVE';
|
||||
|
||||
public static $output;
|
||||
|
||||
/** @var string */
|
||||
public $local_base;
|
||||
|
||||
@ -44,8 +47,9 @@ class Daux
|
||||
/**
|
||||
* @param string $mode
|
||||
*/
|
||||
public function __construct($mode)
|
||||
public function __construct($mode, OutputInterface $output)
|
||||
{
|
||||
Daux::$output = $output;
|
||||
$this->mode = $mode;
|
||||
|
||||
$this->local_base = dirname(__DIR__);
|
||||
@ -236,7 +240,7 @@ class Daux
|
||||
public function getProcessor()
|
||||
{
|
||||
if (!$this->processor) {
|
||||
$this->processor = new Processor($this, new NullOutput(), 0);
|
||||
$this->processor = new Processor($this, Daux::getOutput(), 0);
|
||||
}
|
||||
|
||||
return $this->processor;
|
||||
@ -347,4 +351,37 @@ class Daux
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -79,7 +79,6 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator
|
||||
|
||||
$tree = $this->runAction(
|
||||
'Generating Tree ...',
|
||||
$output,
|
||||
$width,
|
||||
function() use ($params) {
|
||||
$tree = $this->generateRecursive($this->daux->tree, $params);
|
||||
|
@ -41,7 +41,7 @@ class Publisher
|
||||
public function run($title, $closure)
|
||||
{
|
||||
try {
|
||||
return $this->runAction($title, $this->output, $this->width, $closure);
|
||||
return $this->runAction($title, $this->width, $closure);
|
||||
} catch (BadResponseException $e) {
|
||||
$this->output->writeLn('<fg=red>' . $e->getMessage() . '</>');
|
||||
}
|
||||
|
@ -80,7 +80,6 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator
|
||||
|
||||
$this->runAction(
|
||||
'Copying Static assets ...',
|
||||
$output,
|
||||
$width,
|
||||
function() use ($destination, $params) {
|
||||
$this->ensureEmptyDestination($destination);
|
||||
@ -194,7 +193,6 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator
|
||||
} else {
|
||||
$this->runAction(
|
||||
'- ' . $node->getUrl(),
|
||||
$output,
|
||||
$width,
|
||||
function() use ($node, $output_dir, $key, $params, $index_pages) {
|
||||
if ($node instanceof Raw) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php namespace Todaymade\Daux\Format\HTML;
|
||||
|
||||
use League\Plates\Engine;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Todaymade\Daux\Config;
|
||||
use Todaymade\Daux\Daux;
|
||||
use Todaymade\Daux\Tree\Content;
|
||||
@ -43,6 +44,8 @@ class Template
|
||||
}
|
||||
$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);
|
||||
|
||||
return $this->engine;
|
||||
@ -65,6 +68,8 @@ class Template
|
||||
'tree' => $data['params']['tree'],
|
||||
]);
|
||||
|
||||
Daux::writeln("Rendering template '$name'", OutputInterface::VERBOSITY_VERBOSE);
|
||||
|
||||
return $engine->render($name, $data);
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,6 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator
|
||||
return $pdf;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -90,7 +89,6 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator
|
||||
while ($current) {
|
||||
$this->runAction(
|
||||
'Generating ' . $current->getTitle(),
|
||||
$output,
|
||||
$width,
|
||||
function () use ($book, $current, $params) {
|
||||
$contentType = $this->daux->getContentTypeHandler()->getType($current);
|
||||
|
@ -31,12 +31,14 @@ class Server
|
||||
*/
|
||||
public static function serve()
|
||||
{
|
||||
$daux = new Daux(Daux::LIVE_MODE);
|
||||
$output = new NullOutput();
|
||||
|
||||
$daux = new Daux(Daux::LIVE_MODE, $output);
|
||||
$daux->initializeConfiguration();
|
||||
|
||||
$class = $daux->getProcessorClass();
|
||||
if (!empty($class)) {
|
||||
$daux->setProcessor(new $class($daux, new NullOutput(), 0));
|
||||
$daux->setProcessor(new $class($daux, $output, 0));
|
||||
}
|
||||
|
||||
// Set this critical configuration
|
||||
|
Laden…
Verwijs in nieuw issue
Block a user