Be able to set the source directory on command line
This commit is contained in:
parent
b5ce4f1d79
commit
114a0f29b7
@ -18,19 +18,13 @@ class Generate extends SymfonyCommand
|
|||||||
->addOption('configuration', 'c', InputArgument::OPTIONAL, 'Configuration file')
|
->addOption('configuration', 'c', InputArgument::OPTIONAL, 'Configuration file')
|
||||||
->addOption('format', 'f', InputArgument::OPTIONAL, 'Output format, html or confluence', 'html')
|
->addOption('format', 'f', InputArgument::OPTIONAL, 'Output format, html or confluence', 'html')
|
||||||
->addOption('processor', 'p', InputArgument::OPTIONAL, 'Manipulations on the tree')
|
->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');
|
->addOption('destination', 'd', InputArgument::OPTIONAL, $description, 'static');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
// Initialize the system
|
$daux = $this->prepareDaux($input);
|
||||||
$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');
|
|
||||||
}
|
|
||||||
|
|
||||||
$width = $this->getApplication()->getTerminalDimensions()[0];
|
$width = $this->getApplication()->getTerminalDimensions()[0];
|
||||||
|
|
||||||
@ -45,6 +39,26 @@ class Generate extends SymfonyCommand
|
|||||||
$daux->getGenerator()->generateAll($input, $output, $width);
|
$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)
|
protected function prepareProcessor(Daux $daux, InputInterface $input, OutputInterface $output, $width)
|
||||||
{
|
{
|
||||||
if ($input->getOption('processor')) {
|
if ($input->getOption('processor')) {
|
||||||
|
@ -63,28 +63,25 @@ class Daux
|
|||||||
if (defined('PHAR_DIR')) {
|
if (defined('PHAR_DIR')) {
|
||||||
$this->local_base = PHAR_DIR;
|
$this->local_base = PHAR_DIR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// global.json
|
||||||
|
$this->loadBaseConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $override_file
|
* @param string $override_file
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function initialize($override_file = 'config.json')
|
public function initializeConfiguration($override_file = 'config.json')
|
||||||
{
|
{
|
||||||
// global.json
|
// Read documentation overrides
|
||||||
$this->loadBaseConfiguration();
|
$this->loadConfiguration($this->docs_path . DIRECTORY_SEPARATOR . 'config.json');
|
||||||
|
|
||||||
// Check the documentation path
|
// Read command line overrides
|
||||||
$this->docs_path = $this->options['docs_directory'];
|
if (!is_null($override_file)) {
|
||||||
if (!is_dir($this->docs_path) &&
|
$this->loadConfiguration($this->local_base . DIRECTORY_SEPARATOR . $override_file);
|
||||||
!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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// <docs>/config.json, <overrides.json>
|
|
||||||
$this->loadConfigurationOverrides($override_file);
|
|
||||||
|
|
||||||
// Set a valid default timezone
|
// Set a valid default timezone
|
||||||
if (isset($this->options['timezone'])) {
|
if (isset($this->options['timezone'])) {
|
||||||
date_default_timezone_set($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
|
* Load and validate the global configuration
|
||||||
*
|
*
|
||||||
@ -112,25 +119,6 @@ class Daux
|
|||||||
$this->loadConfiguration($this->local_base . DIRECTORY_SEPARATOR . 'global.json', false);
|
$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 string $config_file
|
||||||
* @param bool $optional
|
* @param bool $optional
|
||||||
|
@ -22,7 +22,8 @@ class Server
|
|||||||
public static function serve()
|
public static function serve()
|
||||||
{
|
{
|
||||||
$daux = new Daux(Daux::LIVE_MODE);
|
$daux = new Daux(Daux::LIVE_MODE);
|
||||||
$daux->initialize();
|
$daux->setDocumentationPath($daux->getParams()['docs_directory']);
|
||||||
|
$daux->initializeConfiguration();
|
||||||
|
|
||||||
$class = $daux->getProcessorClass();
|
$class = $daux->getProcessorClass();
|
||||||
if (!empty($class)) {
|
if (!empty($class)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user