} elseif (false === (include $libPath . '/Zend/Loader/StandardAutoloader.php')) { echo "Unable to locate autoloader via library; aborting" . PHP_EOL; exit(2); } // Setup autoloading $loader = new StandardAutoloader(array('autoregister_zf' => true)); $loader->register(); $rules = array('help|h' => 'Get usage message', 'docbook|d-s' => 'Docbook file to convert', 'output|o-s' => 'Output file in reStructuredText format; By default assumes <docbook>.rst"'); try { $opts = new Console\Getopt($rules); $opts->parse(); } catch (Console\Exception\RuntimeException $e) { echo $e->getUsageMessage(); exit(2); } if (!$opts->getOptions() || $opts->getOption('h')) { echo $opts->getUsageMessage(); exit(0); } $docbook = $opts->getOption('d'); if (!file_exists($docbook)) { echo "Error: the docbook file {$docbook} doesn't exist." . PHP_EOL; exit(2); } $rstFile = $opts->getOption('o'); if (empty($rstFile)) { $rstFile = $docbook; if ('.xml' === substr($rstFile, -4)) { $rstFile = substr($rstFile, 0, strlen($docbook) - 4); } $rstFile .= '.rst';
public function testGetoptGetOptions() { $opts = new Getopt('abp:', array('-a', '-p', 'p_arg')); $this->assertEquals(implode(',', $opts->getOptions()), 'a,p'); }
define('DS', DIRECTORY_SEPARATOR); define('PHPOOLE_DIRNAME', '_phpoole'); $websitePath = ''; //getcwd(); // Defines rules $rules = array('help|h' => 'Get PHPoole usage message', 'init|i-s' => 'Build a new PHPoole website (<force>)', 'generate|g' => 'Generate static files', 'serve|s' => 'Start built-in web server', 'deploy|d' => 'Deploy static files', 'list|l' => 'Lists content'); // Get and parse console options try { $opts = new Getopt($rules); $opts->parse(); } catch (ConsoleException $e) { echo $e->getUsageMessage(); exit(2); } // help option if ($opts->getOption('help') || count($opts->getOptions()) == 0) { echo $opts->getUsageMessage(); exit(0); } // Get provided directory if exist if (!isset($opts->getRemainingArgs()[0])) { $path = '.'; } else { $path = $opts->getRemainingArgs()[0]; } if (!is_dir($path)) { $phpooleConsole->wlError('Invalid directory provided!'); exit(2); } $websitePath = str_replace(DS, '/', realpath($path)); // Instanciate the PHPoole API
/** * @see \wcf\system\cli\command\ICLICommand::execute() */ public function execute(array $parameters) { $this->argv->setArguments($parameters); $this->argv->parse(); if ($this->argv->list) { CLIWCF::getReader()->println(CLIUtil::generateTable($this->generateList())); return; } $args = $this->argv->getRemainingArgs(); // validate parameters if (count($args) != 1) { throw new ArgvException('', $this->getUsage()); } $class = $args[0]; // assume wcf\system\worker when no FQN is given if (strpos($class, '\\') === false) { $class = 'wcf\\system\\worker\\' . $class; } $invalid = false; if (!class_exists($class)) { $invalid = true; } else { $reflection = new \ReflectionClass($class); if (!$reflection->isInstantiable()) { $invalid = true; } else { if (!ClassUtil::isInstanceOf($class, 'wcf\\system\\worker\\IWorker')) { $invalid = true; } } } if ($invalid) { throw new ArgvException("Invalid worker '" . $class . "' given", $this->getUsage()); } // parse parameters $options = $this->argv->getOptions(); $parameters = array(); foreach ($options as $option) { $value = $this->argv->getOption($option); if ($option === 'setParameter') { if (!is_array($value)) { $value = array($value); } foreach ($value as $parameter) { list($parameterKey, $parameterValue) = explode('=', $parameter); $parameters[$parameterKey] = $parameterValue; } } else { $parameters[$option] = $value; } } $worker = new $class($parameters); $worker->validate(); $worker->getProgress(); // make sure objects are counted // initialize progressbar $progressbar = new ProgressBar(new ConsoleProgressBar(array('width' => CLIWCF::getTerminal()->getWidth()))); $progress = 0; for ($i = 0; $progress < 100; $i++) { $worker->setLoopCount($i); $worker->validate(); // execute worker $worker->execute(); // update progress $progress = $worker->getProgress(); $progressbar->update($progress); } $progressbar->update($progress); $progressbar->getAdapter()->finish(); }