8
0
daux.io/libs/Console/Generate.php

72 Zeilen
2.5 KiB
PHP

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\Input\ArgvInput;
use Symfony\Component\Console\Input\ArrayInput;
2015-07-14 22:06:01 +02:00
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
2015-07-14 22:06:01 +02:00
use Symfony\Component\Console\Output\OutputInterface;
use Todaymade\Daux\Daux;
class Generate extends DauxCommand
2015-07-14 22:06:01 +02:00
{
protected function configure()
{
parent::configure();
2015-07-14 22:06:01 +02:00
$description = 'Destination folder, relative to the working directory';
$this
->setName('generate')
->setDescription('Generate documentation')
->addOption('format', 'f', InputOption::VALUE_REQUIRED, 'Output format, html or confluence', 'html')
// Confluence format only
->addOption('delete', null, InputOption::VALUE_NONE, 'Delete pages not linked to a documentation page (confluence)')
// HTML Format only
->addOption('themes', 't', InputOption::VALUE_REQUIRED, 'Set a different themes directory')
->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
}
protected function execute(InputInterface $input, OutputInterface $output)
{
// 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());
}
$daux = $this->prepareDaux($input);
2015-07-14 22:06:01 +02:00
$width = $this->getApplication()->getTerminalDimensions()[0];
// 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
// Generate the documentation
$daux->getGenerator()->generateAll($input, $output, $width);
}
protected function prepareProcessor(Daux $daux, InputInterface $input, OutputInterface $output, $width)
{
if ($input->getOption('processor')) {
$daux->getParams()['processor'] = $input->getOption('processor');
2015-07-14 22:06:01 +02:00
}
$class = $daux->getProcessorClass();
2015-07-20 15:59:52 +02:00
if (!empty($class)) {
$daux->setProcessor(new $class($daux, $output, $width));
}
2015-07-14 22:06:01 +02:00
}
}