diff --git a/daux.phar b/daux.phar index 5d9df58..a62cc9f 100755 Binary files a/daux.phar and b/daux.phar differ diff --git a/libs/Console/Generate.php b/libs/Console/Generate.php index 3da20e0..c25038c 100644 --- a/libs/Console/Generate.php +++ b/libs/Console/Generate.php @@ -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')) { diff --git a/libs/Daux.php b/libs/Daux.php index 146eddc..c55c37c 100644 --- a/libs/Daux.php +++ b/libs/Daux.php @@ -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); } - // /config.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 diff --git a/libs/Server/Server.php b/libs/Server/Server.php index f1ee380..42746e1 100644 --- a/libs/Server/Server.php +++ b/libs/Server/Server.php @@ -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)) {