diff --git a/libs/Console/Application.php b/libs/Console/Application.php index 7a66c68..f083483 100644 --- a/libs/Console/Application.php +++ b/libs/Console/Application.php @@ -5,45 +5,11 @@ use Symfony\Component\Console\Input\InputInterface; class Application extends SymfonyApplication { - /** - * Gets the name of the command based on input. - * - * @param InputInterface $input The input interface - * - * @return string The command name - */ - protected function getCommandName(InputInterface $input) - { - // This should return the name of your command. - return 'generate'; - } + public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN') { + parent::__construct($name, $version); - /** - * Gets the default commands that should always be available. - * - * @return array An array of default Command instances - */ - protected function getDefaultCommands() - { - // Keep the core default commands to have the HelpCommand - // which is used when using the --help option - $defaultCommands = parent::getDefaultCommands(); - - $defaultCommands[] = new Generate(); - - return $defaultCommands; - } - - /** - * Overridden so that the application doesn't expect the command - * name to be the first argument. - */ - public function getDefinition() - { - $inputDefinition = parent::getDefinition(); - // clear out the normal first argument, which is the command name - $inputDefinition->setArguments(); - - return $inputDefinition; + $this->add(new Generate()); + $this->add(new Serve()); + $this->setDefaultCommand('generate'); } } diff --git a/libs/Console/DauxCommand.php b/libs/Console/DauxCommand.php new file mode 100644 index 0000000..7e370a0 --- /dev/null +++ b/libs/Console/DauxCommand.php @@ -0,0 +1,31 @@ +hasOption('format') && $input->getOption('format')) { + $daux->getParams()->setFormat($input->getOption('format')); + } + + // Set the source directory + if ($input->getOption('source')) { + $daux->getParams()->setDocumentationDirectory($input->getOption('source')); + } + + $daux->initializeConfiguration($input->getOption('configuration')); + + if ($input->hasOption('delete') && $input->getOption('delete')) { + $daux->getParams()['confluence']['delete'] = true; + } + + return $daux; + } +} diff --git a/libs/Console/Generate.php b/libs/Console/Generate.php index 6e91bad..51d6646 100755 --- a/libs/Console/Generate.php +++ b/libs/Console/Generate.php @@ -1,13 +1,11 @@ addOption('format', 'f', InputOption::VALUE_REQUIRED, 'Output format, html or confluence', 'html') ->addOption('processor', 'p', InputOption::VALUE_REQUIRED, 'Manipulations on the tree') - // 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') - ->addOption('port', null, InputOption::VALUE_REQUIRED, 'The port to serve on', 8085) - - // Confluence format only ->addOption('delete', null, InputOption::VALUE_NONE, 'Delete pages not linked to a documentation page (confluence)') @@ -40,12 +32,6 @@ class Generate extends SymfonyCommand { $daux = $this->prepareDaux($input); - if ($input->getOption('serve')) { - $this->serve($daux, $input); - - return; - } - $width = $this->getApplication()->getTerminalDimensions()[0]; // Instiantiate the processor if one is defined @@ -58,39 +44,6 @@ class Generate extends SymfonyCommand $daux->getGenerator()->generateAll($input, $output, $width); } - protected function serve(Daux $daux, InputInterface $input) - { - // Daux can only serve HTML - $daux->getParams()->setFormat('html'); - - //TODO :: support configuration and processor - - Server::runServer($daux->getParams(), $input->getOption('host'), $input->getOption('port')); - } - - protected function prepareDaux(InputInterface $input) - { - $daux = new Daux(Daux::STATIC_MODE); - - // Set the format if requested - if ($input->getOption('format')) { - $daux->getParams()->setFormat($input->getOption('format')); - } - - // Set the source directory - if ($input->getOption('source')) { - $daux->getParams()->setDocumentationDirectory($input->getOption('source')); - } - - $daux->initializeConfiguration($input->getOption('configuration')); - - if ($input->getOption('delete')) { - $daux->getParams()['confluence']['delete'] = true; - } - - return $daux; - } - protected function prepareProcessor(Daux $daux, InputInterface $input, OutputInterface $output, $width) { if ($input->getOption('processor')) { diff --git a/libs/Console/Serve.php b/libs/Console/Serve.php new file mode 100755 index 0000000..cd09cc9 --- /dev/null +++ b/libs/Console/Serve.php @@ -0,0 +1,76 @@ +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') + + // 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') + ->addOption('port', null, InputOption::VALUE_REQUIRED, 'The port to serve on', 8085); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $host = $input->getOption('host'); + $port = $input->getOption('port'); + + $daux = $this->prepareDaux($input); + + // Daux can only serve HTML + $daux->getParams()->setFormat('html'); + + chdir(__DIR__ . '/../../'); + + putenv('DAUX_SOURCE=' . $daux->getParams()->getDocumentationDirectory()); + + //TODO :: support configuration and processor + //putenv('DAUX_CONFIGURATION=' . $daux->getParams()->getConfigurationFile()); + //putenv('DAUX_PROCESSOR=' . $daux->getParams()->getProcessorFile()); + + $base = ProcessUtils::escapeArgument(__DIR__ . '/../../'); + $binary = ProcessUtils::escapeArgument((new PhpExecutableFinder)->find(false)); + + echo "Daux development server started on http://{$host}:{$port}/\n"; + + if (defined('HHVM_VERSION')) { + if (version_compare(HHVM_VERSION, '3.8.0') >= 0) { + passthru("{$binary} -m server -v Server.Type=proxygen -v Server.SourceRoot={$base}/ -v Server.IP={$host} -v Server.Port={$port} -v Server.DefaultDocument=server.php -v Server.ErrorDocument404=server.php"); + } else { + throw new Exception("HHVM's built-in server requires HHVM >= 3.8.0."); + } + } else { + passthru("{$binary} -S {$host}:{$port} {$base}/index.php"); + } + } + + protected function prepareProcessor(Daux $daux, InputInterface $input, OutputInterface $output, $width) + { + if ($input->getOption('processor')) { + $daux->getParams()['processor'] = $input->getOption('processor'); + } + + $class = $daux->getProcessorClass(); + if (!empty($class)) { + $daux->setProcessor(new $class($daux, $output, $width)); + } + } +} diff --git a/libs/Server/Server.php b/libs/Server/Server.php index 664ee2b..c0d715b 100755 --- a/libs/Server/Server.php +++ b/libs/Server/Server.php @@ -66,28 +66,6 @@ class Server echo $page->getContent(); } - public static function runServer(Config $config, $host, $port) - { - chdir(__DIR__ . '/../../'); - - putenv('DAUX_SOURCE=' . $config->getDocumentationDirectory()); - - $base = ProcessUtils::escapeArgument(__DIR__ . '/../../'); - $binary = ProcessUtils::escapeArgument((new PhpExecutableFinder)->find(false)); - - echo "Daux development server started on http://{$host}:{$port}/\n"; - - if (defined('HHVM_VERSION')) { - if (version_compare(HHVM_VERSION, '3.8.0') >= 0) { - passthru("{$binary} -m server -v Server.Type=proxygen -v Server.SourceRoot={$base}/ -v Server.IP={$host} -v Server.Port={$port} -v Server.DefaultDocument=server.php -v Server.ErrorDocument404=server.php"); - } else { - throw new Exception("HHVM's built-in server requires HHVM >= 3.8.0."); - } - } else { - passthru("{$binary} -S {$host}:{$port} {$base}/index.php"); - } - } - public function __construct(Daux $daux) { $this->daux = $daux;