2015-07-23 17:44:24 +02:00
|
|
|
<?php namespace Todaymade\Daux\Console;
|
2015-07-14 22:06:01 +02:00
|
|
|
|
|
|
|
use Symfony\Component\Console\Command\Command as SymfonyCommand;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
2016-01-25 14:48:37 +01:00
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
2015-07-14 22:06:01 +02:00
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
use Todaymade\Daux\Daux;
|
|
|
|
|
2015-07-23 17:44:24 +02:00
|
|
|
class Generate extends SymfonyCommand
|
2015-07-14 22:06:01 +02:00
|
|
|
{
|
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
$description = 'Destination folder, relative to the working directory';
|
|
|
|
|
|
|
|
$this
|
|
|
|
->setName('generate')
|
|
|
|
->setDescription('Generate documentation')
|
2016-01-25 14:48:37 +01:00
|
|
|
->addOption('configuration', 'c', InputOption::VALUE_REQUIRED, 'Configuration file')
|
|
|
|
->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')
|
|
|
|
->addOption('delete', null, InputOption::VALUE_NONE, 'Delete pages not linked to a documentation page (confluence)')
|
|
|
|
->addOption('destination', 'd', InputOption::VALUE_REQUIRED, $description, 'static');
|
2015-07-14 22:06:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
{
|
2015-07-28 17:26:35 +02:00
|
|
|
$daux = $this->prepareDaux($input);
|
2015-07-28 17:25:03 +02:00
|
|
|
|
2015-07-14 22:06:01 +02:00
|
|
|
$width = $this->getApplication()->getTerminalDimensions()[0];
|
|
|
|
|
2015-07-19 22:38:37 +02:00
|
|
|
// Instiantiate the processor if one is defined
|
|
|
|
$this->prepareProcessor($daux, $input, $output, $width);
|
2015-07-14 22:06:01 +02:00
|
|
|
|
2015-07-19 23:17:57 +02:00
|
|
|
// Generate the tree
|
|
|
|
$daux->generateTree();
|
2015-07-17 18:34:00 +02:00
|
|
|
|
2015-07-19 22:38:37 +02:00
|
|
|
// Generate the documentation
|
|
|
|
$daux->getGenerator()->generateAll($input, $output, $width);
|
2015-07-19 00:55:57 +02:00
|
|
|
}
|
|
|
|
|
2015-08-02 15:42:23 +02:00
|
|
|
protected function prepareDaux(InputInterface $input)
|
|
|
|
{
|
2015-07-28 17:26:35 +02:00
|
|
|
$daux = new Daux(Daux::STATIC_MODE);
|
|
|
|
|
|
|
|
// Set the format if requested
|
|
|
|
if ($input->getOption('format')) {
|
|
|
|
$daux->getParams()['format'] = $input->getOption('format');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the source directory
|
|
|
|
if ($input->getOption('source')) {
|
|
|
|
$daux->getParams()['docs_directory'] = $input->getOption('source');
|
|
|
|
}
|
|
|
|
|
|
|
|
$daux->setDocumentationPath($daux->getParams()['docs_directory']);
|
|
|
|
|
2015-08-09 22:18:23 +02:00
|
|
|
$daux->setThemesPath($daux->getParams()['themes_directory']);
|
|
|
|
|
2015-07-28 17:26:35 +02:00
|
|
|
$daux->initializeConfiguration($input->getOption('configuration'));
|
|
|
|
|
2016-01-25 14:48:37 +01:00
|
|
|
if ($input->getOption('delete')) {
|
|
|
|
$daux->getParams()['confluence']['delete'] = true;
|
|
|
|
}
|
|
|
|
|
2015-07-28 17:26:35 +02:00
|
|
|
return $daux;
|
|
|
|
}
|
|
|
|
|
2015-07-19 22:38:37 +02:00
|
|
|
protected function prepareProcessor(Daux $daux, InputInterface $input, OutputInterface $output, $width)
|
2015-07-19 00:55:57 +02:00
|
|
|
{
|
2015-07-19 22:38:37 +02:00
|
|
|
if ($input->getOption('processor')) {
|
|
|
|
$daux->getParams()['processor'] = $input->getOption('processor');
|
2015-07-14 22:06:01 +02:00
|
|
|
}
|
2015-07-19 00:55:57 +02:00
|
|
|
|
2015-07-19 22:38:37 +02:00
|
|
|
$class = $daux->getProcessorClass();
|
2015-07-20 15:59:52 +02:00
|
|
|
if (!empty($class)) {
|
2015-07-19 22:38:37 +02:00
|
|
|
$daux->setProcessor(new $class($daux, $output, $width));
|
2015-07-19 00:55:57 +02:00
|
|
|
}
|
2015-07-14 22:06:01 +02:00
|
|
|
}
|
|
|
|
}
|