2016-07-29 07:58:48 +02:00
|
|
|
<?php namespace Todaymade\Daux\Console;
|
|
|
|
|
|
|
|
use Symfony\Component\Console\Command\Command as SymfonyCommand;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
2017-11-05 23:56:46 +01:00
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
2018-06-05 20:31:51 +02:00
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
2019-12-05 21:25:58 +01:00
|
|
|
use Todaymade\Daux\ConfigBuilder;
|
2016-07-29 07:58:48 +02:00
|
|
|
use Todaymade\Daux\Daux;
|
|
|
|
|
|
|
|
class DauxCommand extends SymfonyCommand
|
|
|
|
{
|
2017-11-05 23:56:46 +01:00
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
$this
|
|
|
|
->addOption('configuration', 'c', InputOption::VALUE_REQUIRED, 'Configuration file')
|
|
|
|
->addOption('source', 's', InputOption::VALUE_REQUIRED, 'Where to take the documentation from')
|
2018-06-06 23:20:29 +02:00
|
|
|
->addOption('processor', 'p', InputOption::VALUE_REQUIRED, 'Manipulations on the tree')
|
2019-12-05 21:25:58 +01:00
|
|
|
->addOption('no-cache', null, InputOption::VALUE_NONE, 'Disable Cache')
|
|
|
|
->addOption('themes', 't', InputOption::VALUE_REQUIRED, 'Set a different themes directory (Used by HTML format only)')
|
|
|
|
->addOption('value', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Set different configuration values');
|
2017-11-05 23:56:46 +01:00
|
|
|
}
|
|
|
|
|
2019-12-05 21:25:58 +01:00
|
|
|
protected function prepareConfig($mode, InputInterface $input, OutputInterface $output): ConfigBuilder
|
2016-07-29 07:58:48 +02:00
|
|
|
{
|
2019-12-05 21:25:58 +01:00
|
|
|
$builder = ConfigBuilder::withMode($mode);
|
2016-07-29 07:58:48 +02:00
|
|
|
|
2019-12-05 21:25:58 +01:00
|
|
|
if ($input->getOption('configuration')) {
|
|
|
|
$builder->withConfigurationOverride($input->getOption('configuration'));
|
2016-07-29 07:58:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($input->getOption('source')) {
|
2019-12-05 21:25:58 +01:00
|
|
|
$builder->withDocumentationDirectory($input->getOption('source'));
|
2016-07-29 07:58:48 +02:00
|
|
|
}
|
|
|
|
|
2019-12-05 21:25:58 +01:00
|
|
|
if ($input->getOption('processor')) {
|
|
|
|
$builder->withProcessor($input->getOption('processor'));
|
2016-09-21 23:30:01 +02:00
|
|
|
}
|
|
|
|
|
2019-12-05 21:25:58 +01:00
|
|
|
if ($input->getOption('no-cache')) {
|
|
|
|
$builder->withCache(false);
|
|
|
|
}
|
2016-07-29 07:58:48 +02:00
|
|
|
|
2019-12-05 21:25:58 +01:00
|
|
|
if ($input->getOption('themes')) {
|
|
|
|
$builder->withThemesDirectory($input->getOption('themes'));
|
2016-07-29 07:58:48 +02:00
|
|
|
}
|
|
|
|
|
2017-11-05 23:56:46 +01:00
|
|
|
if ($input->hasOption('value')) {
|
2019-12-05 21:25:58 +01:00
|
|
|
$values = array_map(
|
|
|
|
function($value) {
|
|
|
|
return array_map("trim", explode('=', $value));
|
|
|
|
},
|
|
|
|
$input->getOption('value')
|
|
|
|
);
|
|
|
|
$builder->withValues($values);
|
2017-11-05 23:56:46 +01:00
|
|
|
}
|
|
|
|
|
2019-12-05 21:25:58 +01:00
|
|
|
return $builder;
|
|
|
|
}
|
2018-06-06 23:20:29 +02:00
|
|
|
|
2019-12-05 21:25:58 +01:00
|
|
|
protected function prepareProcessor(Daux $daux, $width)
|
|
|
|
{
|
|
|
|
$class = $daux->getProcessorClass();
|
|
|
|
if (!empty($class)) {
|
2019-12-07 11:22:40 +01:00
|
|
|
$daux->setProcessor(new $class($daux, $daux->getOutput(), $width));
|
2019-12-05 21:25:58 +01:00
|
|
|
}
|
2016-07-29 07:58:48 +02:00
|
|
|
}
|
|
|
|
}
|