2015-07-23 17:44:24 +02:00
|
|
|
<?php namespace Todaymade\Daux\Console;
|
2015-07-14 22:06:01 +02:00
|
|
|
|
2016-09-30 23:10:17 +02:00
|
|
|
use Symfony\Component\Console\Input\ArgvInput;
|
|
|
|
use Symfony\Component\Console\Input\ArrayInput;
|
2015-07-14 22:06:01 +02:00
|
|
|
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;
|
2018-05-05 16:58:49 +02:00
|
|
|
use Symfony\Component\Console\Terminal;
|
2015-07-14 22:06:01 +02:00
|
|
|
use Todaymade\Daux\Daux;
|
2019-12-05 21:25:58 +01:00
|
|
|
use Todaymade\Daux\ConfigBuilder;
|
2015-07-14 22:06:01 +02:00
|
|
|
|
2016-07-29 07:58:48 +02:00
|
|
|
class Generate extends DauxCommand
|
2015-07-14 22:06:01 +02:00
|
|
|
{
|
|
|
|
protected function configure()
|
|
|
|
{
|
2017-11-05 23:56:46 +01:00
|
|
|
parent::configure();
|
|
|
|
|
2015-07-14 22:06:01 +02:00
|
|
|
$description = 'Destination folder, relative to the working directory';
|
|
|
|
|
|
|
|
$this
|
|
|
|
->setName('generate')
|
|
|
|
->setDescription('Generate documentation')
|
2016-07-28 22:47:47 +02:00
|
|
|
|
2016-01-25 14:48:37 +01:00
|
|
|
->addOption('format', 'f', InputOption::VALUE_REQUIRED, 'Output format, html or confluence', 'html')
|
2016-07-28 22:47:47 +02:00
|
|
|
|
|
|
|
// Confluence format only
|
2016-01-25 14:48:37 +01:00
|
|
|
->addOption('delete', null, InputOption::VALUE_NONE, 'Delete pages not linked to a documentation page (confluence)')
|
2016-07-28 22:47:47 +02:00
|
|
|
|
2016-02-15 21:14:48 +01:00
|
|
|
->addOption('destination', 'd', InputOption::VALUE_REQUIRED, $description, 'static')
|
2016-07-28 22:48:50 +02:00
|
|
|
->addOption('search', null, InputOption::VALUE_NONE, 'Generate full text search');
|
2015-07-14 22:06:01 +02:00
|
|
|
}
|
|
|
|
|
2019-12-05 21:25:58 +01:00
|
|
|
protected function prepareConfig($mode, InputInterface $input, OutputInterface $output): ConfigBuilder
|
|
|
|
{
|
|
|
|
$builder = parent::prepareConfig($mode, $input, $output);
|
|
|
|
|
|
|
|
// Set the format if requested
|
|
|
|
if ($input->hasOption('format') && $input->getOption('format')) {
|
|
|
|
$builder->withFormat($input->getOption('format'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($input->hasOption('delete') && $input->getOption('delete')) {
|
|
|
|
$builder->withConfluenceDelete(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($input->hasOption('search')) {
|
|
|
|
$builder->withSearch($input->getOption('search'));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $builder;
|
|
|
|
}
|
|
|
|
|
2015-07-14 22:06:01 +02:00
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
{
|
2016-09-30 23:10:17 +02:00
|
|
|
// When used as a default command,
|
|
|
|
// Symfony doesn't read the default parameters.
|
|
|
|
// This will parse the parameters
|
|
|
|
if ($input instanceof ArrayInput) {
|
|
|
|
$argv = $_SERVER['argv'];
|
|
|
|
$argv[0] = $this->getName();
|
|
|
|
array_unshift($argv, 'binary_name');
|
|
|
|
|
|
|
|
$input = new ArgvInput($argv, $this->getDefinition());
|
|
|
|
}
|
|
|
|
|
2019-12-05 21:25:58 +01:00
|
|
|
$builder = $this->prepareConfig(Daux::STATIC_MODE, $input, $output);
|
|
|
|
$daux = new Daux($builder->build(), $output);
|
2015-07-28 17:25:03 +02:00
|
|
|
|
2018-05-05 16:58:49 +02:00
|
|
|
$width = (new Terminal)->getWidth();
|
2015-07-14 22:06:01 +02:00
|
|
|
|
2015-07-19 22:38:37 +02:00
|
|
|
// Instiantiate the processor if one is defined
|
2019-12-05 21:25:58 +01:00
|
|
|
$this->prepareProcessor($daux, $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);
|
2019-11-28 22:41:53 +01:00
|
|
|
|
|
|
|
return 0;
|
2015-07-19 00:55:57 +02:00
|
|
|
}
|
2015-07-14 22:06:01 +02:00
|
|
|
}
|