Allow to set configuration values directly in the command line
Dieser Commit ist enthalten in:
Ursprung
55ee848e32
Commit
8e7340da3d
@ -2,10 +2,51 @@
|
||||
|
||||
use Symfony\Component\Console\Command\Command as SymfonyCommand;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Todaymade\Daux\Daux;
|
||||
|
||||
class DauxCommand extends SymfonyCommand
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->addOption('configuration', 'c', InputOption::VALUE_REQUIRED, 'Configuration file')
|
||||
->addOption('value', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Set different configuration values')
|
||||
->addOption('source', 's', InputOption::VALUE_REQUIRED, 'Where to take the documentation from')
|
||||
->addOption('processor', 'p', InputOption::VALUE_REQUIRED, 'Manipulations on the tree');
|
||||
}
|
||||
|
||||
private function setValue(&$array, $key, $value)
|
||||
{
|
||||
if (is_null($key)) {
|
||||
return $array = $value;
|
||||
}
|
||||
$keys = explode('.', $key);
|
||||
while (count($keys) > 1) {
|
||||
$key = array_shift($keys);
|
||||
if (! isset($array[$key]) || ! is_array($array[$key])) {
|
||||
$array[$key] = [];
|
||||
}
|
||||
$array = &$array[$key];
|
||||
}
|
||||
$array[array_shift($keys)] = $value;
|
||||
return $array;
|
||||
}
|
||||
|
||||
private function applyConfiguration(array $options, Daux $daux)
|
||||
{
|
||||
$values = array_map(
|
||||
function ($value) {
|
||||
return array_map("trim", explode('=', $value));
|
||||
},
|
||||
$options
|
||||
);
|
||||
|
||||
foreach ($values as $value) {
|
||||
$this->setValue($daux->options, $value[0], $value[1]);
|
||||
}
|
||||
}
|
||||
|
||||
protected function prepareDaux(InputInterface $input)
|
||||
{
|
||||
$daux = new Daux(Daux::STATIC_MODE);
|
||||
@ -30,6 +71,10 @@ class DauxCommand extends SymfonyCommand
|
||||
$daux->getParams()['confluence']['delete'] = true;
|
||||
}
|
||||
|
||||
if ($input->hasOption('value')) {
|
||||
$this->applyConfiguration($input->getOption('value'), $daux);
|
||||
}
|
||||
|
||||
return $daux;
|
||||
}
|
||||
}
|
||||
|
@ -11,22 +11,21 @@ class Generate extends DauxCommand
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$description = 'Destination folder, relative to the working directory';
|
||||
|
||||
$this
|
||||
->setName('generate')
|
||||
->setDescription('Generate documentation')
|
||||
|
||||
->addOption('configuration', 'c', InputOption::VALUE_REQUIRED, 'Configuration file')
|
||||
->addOption('source', 's', InputOption::VALUE_REQUIRED, 'Where to take the documentation from')
|
||||
->addOption('format', 'f', InputOption::VALUE_REQUIRED, 'Output format, html or confluence', 'html')
|
||||
->addOption('processor', 'p', InputOption::VALUE_REQUIRED, 'Manipulations on the tree')
|
||||
->addOption('themes', 't', InputOption::VALUE_REQUIRED, 'Set a different themes directory')
|
||||
|
||||
// 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')
|
||||
->addOption('search', null, InputOption::VALUE_NONE, 'Generate full text search');
|
||||
}
|
||||
|
@ -13,15 +13,12 @@ class Serve extends DauxCommand
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this
|
||||
->setName('serve')
|
||||
->setDescription('Serve documentation')
|
||||
|
||||
->addOption('configuration', 'c', InputOption::VALUE_REQUIRED, 'Configuration file')
|
||||
->addOption('source', 's', InputOption::VALUE_REQUIRED, 'Where to take the documentation from')
|
||||
->addOption('processor', 'p', InputOption::VALUE_REQUIRED, 'Manipulations on the tree')
|
||||
->addOption('themes', 't', InputOption::VALUE_REQUIRED, 'Set a different themes directory')
|
||||
|
||||
// Serve the current documentation
|
||||
->addOption('serve', null, InputOption::VALUE_NONE, 'Serve the current directory')
|
||||
->addOption('host', null, InputOption::VALUE_REQUIRED, 'The host to serve on', 'localhost')
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren