Be able to set the source directory on command line

This commit is contained in:
Stéphane Goetz 2015-07-28 17:26:35 +02:00
parent b5ce4f1d79
commit 114a0f29b7
4 changed files with 43 additions and 40 deletions

BIN
daux.phar

Binary file not shown.

View File

@ -18,19 +18,13 @@ class Generate extends SymfonyCommand
->addOption('configuration', 'c', InputArgument::OPTIONAL, 'Configuration file')
->addOption('format', 'f', InputArgument::OPTIONAL, 'Output format, html or confluence', 'html')
->addOption('processor', 'p', InputArgument::OPTIONAL, 'Manipulations on the tree')
->addOption('source', 's', InputArgument::OPTIONAL, 'Where to take the documentation from')
->addOption('destination', 'd', InputArgument::OPTIONAL, $description, 'static');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
// Initialize the system
$daux = new Daux(Daux::STATIC_MODE);
$daux->initialize($input->getOption('configuration'));
// Set the format if requested
if ($input->getOption('format')) {
$daux->getParams()['format'] = $input->getOption('format');
}
$daux = $this->prepareDaux($input);
$width = $this->getApplication()->getTerminalDimensions()[0];
@ -45,6 +39,26 @@ class Generate extends SymfonyCommand
$daux->getGenerator()->generateAll($input, $output, $width);
}
protected function prepareDaux(InputInterface $input) {
$daux = new Daux(Daux::STATIC_MODE);
// Set the format if requested
if ($input->getOption('format')) {
$daux->getParams()['format'] = $input->getOption('format');
}
// Set the source directory
if ($input->getOption('source')) {
$daux->getParams()['docs_directory'] = $input->getOption('source');
}
$daux->setDocumentationPath($daux->getParams()['docs_directory']);
$daux->initializeConfiguration($input->getOption('configuration'));
return $daux;
}
protected function prepareProcessor(Daux $daux, InputInterface $input, OutputInterface $output, $width)
{
if ($input->getOption('processor')) {

View File

@ -63,28 +63,25 @@ class Daux
if (defined('PHAR_DIR')) {
$this->local_base = PHAR_DIR;
}
// global.json
$this->loadBaseConfiguration();
}
/**
* @param string $override_file
* @throws Exception
*/
public function initialize($override_file = 'config.json')
public function initializeConfiguration($override_file = 'config.json')
{
// global.json
$this->loadBaseConfiguration();
// Read documentation overrides
$this->loadConfiguration($this->docs_path . DIRECTORY_SEPARATOR . 'config.json');
// Check the documentation path
$this->docs_path = $this->options['docs_directory'];
if (!is_dir($this->docs_path) &&
!is_dir($this->docs_path = $this->local_base . DIRECTORY_SEPARATOR . $this->docs_path)
) {
throw new Exception('The Docs directory does not exist. Check the path again : ' . $this->docs_path);
// Read command line overrides
if (!is_null($override_file)) {
$this->loadConfiguration($this->local_base . DIRECTORY_SEPARATOR . $override_file);
}
// <docs>/config.json, <overrides.json>
$this->loadConfigurationOverrides($override_file);
// Set a valid default timezone
if (isset($this->options['timezone'])) {
date_default_timezone_set($this->options['timezone']);
@ -93,6 +90,16 @@ class Daux
}
}
public function setDocumentationPath($path)
{
$this->docs_path = $path;
if (!is_dir($this->docs_path) &&
!is_dir($this->docs_path = $this->local_base . DIRECTORY_SEPARATOR . $this->docs_path)
) {
throw new Exception('The Docs directory does not exist. Check the path again : ' . $this->docs_path);
}
}
/**
* Load and validate the global configuration
*
@ -112,25 +119,6 @@ class Daux
$this->loadConfiguration($this->local_base . DIRECTORY_SEPARATOR . 'global.json', false);
}
/**
* Load the configuration files, first, "config.json"
* in the documentation and then the file specified
* when running the configuration
*
* @param string $override_file
* @throws Exception
*/
protected function loadConfigurationOverrides($override_file)
{
// Read documentation overrides
$this->loadConfiguration($this->docs_path . DIRECTORY_SEPARATOR . 'config.json');
// Read command line overrides
if (!is_null($override_file)) {
$this->loadConfiguration($this->local_base . DIRECTORY_SEPARATOR . $override_file);
}
}
/**
* @param string $config_file
* @param bool $optional

View File

@ -22,7 +22,8 @@ class Server
public static function serve()
{
$daux = new Daux(Daux::LIVE_MODE);
$daux->initialize();
$daux->setDocumentationPath($daux->getParams()['docs_directory']);
$daux->initializeConfiguration();
$class = $daux->getProcessorClass();
if (!empty($class)) {