Add the daux --serve command to simplify writing documentation and reading.

This commit is contained in:
Stéphane Goetz
2016-07-28 22:47:47 +02:00
parent 97c4014926
commit 18e10cacc8
10 changed files with 148 additions and 36 deletions

View File

@ -1,10 +1,12 @@
<?php namespace Todaymade\Daux\Console;
use Symfony\Component\Console\Command\Command as SymfonyCommand;
use Symfony\Component\Console\Exception\InvalidOptionException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Todaymade\Daux\Daux;
use Todaymade\Daux\Server\Server;
class Generate extends SymfonyCommand
{
@ -15,19 +17,36 @@ class Generate extends SymfonyCommand
$this
->setName('generate')
->setDescription('Generate documentation')
->addOption('configuration', 'c', InputOption::VALUE_REQUIRED, 'Configuration file')
->addOption('source', 's', InputOption::VALUE_REQUIRED, 'Where to take the documentation from')
->addOption('format', 'f', InputOption::VALUE_REQUIRED, 'Output format, html or confluence', 'html')
->addOption('processor', 'p', InputOption::VALUE_REQUIRED, 'Manipulations on the tree')
->addOption('source', 's', InputOption::VALUE_REQUIRED, 'Where to take the documentation from')
// Serve the current documentation
->addOption('serve', null, InputOption::VALUE_NONE, 'Serve the current directory')
->addOption('host', null, InputOption::VALUE_REQUIRED, 'The host to serve on', 'localhost')
->addOption('port', null, InputOption::VALUE_REQUIRED, 'The port to serve on', 8085)
// Confluence format only
->addOption('delete', null, InputOption::VALUE_NONE, 'Delete pages not linked to a documentation page (confluence)')
// HTML Format only
->addOption('destination', 'd', InputOption::VALUE_REQUIRED, $description, 'static')
->addOption('search', null, InputOption::VALUE_NONE, 'Generate full text search');
->addOption('search', null, InputOption::VALUE_NONE, 'Generate full text search')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$daux = $this->prepareDaux($input);
if ($input->getOption('serve')) {
$this->serve($daux, $input);
return;
}
$width = $this->getApplication()->getTerminalDimensions()[0];
// Instiantiate the processor if one is defined
@ -40,13 +59,23 @@ class Generate extends SymfonyCommand
$daux->getGenerator()->generateAll($input, $output, $width);
}
protected function serve(Daux $daux, InputInterface $input)
{
// Daux can only serve HTML
$daux->getParams()->setFormat('html');
//TODO :: support configuration and processor
Server::runServer($daux->getParams(), $input->getOption('host'), $input->getOption('port'));
}
protected function prepareDaux(InputInterface $input)
{
$daux = new Daux(Daux::STATIC_MODE);
// Set the format if requested
if ($input->getOption('format')) {
$daux->getParams()['format'] = $input->getOption('format');
$daux->getParams()->setFormat($input->getOption('format'));
}
// Set the source directory