daux.io/libs/Console/DauxCommand.php

68 regels
2.4 KiB
PHP

<?php namespace Todaymade\Daux\Console;
use Symfony\Component\Console\Command\Command as SymfonyCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
2018-06-05 20:31:51 +02:00
use Symfony\Component\Console\Output\OutputInterface;
use Todaymade\Daux\ConfigBuilder;
use Todaymade\Daux\Daux;
class DauxCommand extends SymfonyCommand
{
2020-04-22 21:55:53 +02: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')
->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');
}
protected function prepareConfig($mode, InputInterface $input, OutputInterface $output): ConfigBuilder
{
$builder = ConfigBuilder::withMode($mode);
if ($input->getOption('configuration')) {
$builder->withConfigurationOverride($input->getOption('configuration'));
}
if ($input->getOption('source')) {
$builder->withDocumentationDirectory($input->getOption('source'));
}
if ($input->getOption('processor')) {
$builder->withProcessor($input->getOption('processor'));
2016-09-21 23:30:01 +02:00
}
if ($input->getOption('no-cache')) {
$builder->withCache(false);
}
if ($input->getOption('themes')) {
$builder->withThemesDirectory($input->getOption('themes'));
}
if ($input->hasOption('value')) {
$values = array_map(
2020-04-22 21:55:53 +02:00
function ($value) {
return array_map("trim", explode('=', $value));
},
$input->getOption('value')
);
$builder->withValues($values);
}
return $builder;
}
2018-06-06 23:20:29 +02: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));
}
}
}