/** * Print the usage message * * @param \Zend\Console\Getopt $options options to get the usage message from */ function printUsageMessage(\Zend\Console\Getopt $options) { $usage = $options->getUsageMessage(); list($firstLine, $usage) = explode(PHP_EOL, $usage, 2); echo $firstLine . ' -o outputfile.pdf character-images [..]' . PHP_EOL; echo $usage; }
/** * Render help message. * * @return void */ public function getHelp() { $msg = $this->opts->getUsageMessage(); // Amend the auto-generated help message: $options = "[ options ] [ target ]\n" . "Where [ target ] is the name of a section of the configuration\n" . "specified by the ini option, or a directory to harvest into if\n" . "no .ini file is used. If [ target ] is omitted, all .ini sections\n" . "will be processed. [ options ] may be selected from those below,\n" . "and will override .ini settings where applicable."; $this->write(str_replace('[ options ]', $options, $msg)); }
exit(2); } } // Setup autoloading $loader = new StandardAutoloader(array('autoregister_zf' => true)); $loader->register(); $rules = array('help|h' => 'Get usage message', 'library|l-s' => 'Library to parse; if none provided, assumes current directory', 'output|o-s' => 'Where to write plugin map file; if not provided, assumes "plugin_classmap.php" in library directory', 'append|a' => 'Append to plugin map file if it exists', 'overwrite|w' => 'Whether or not to overwrite existing autoload file'); try { $opts = new Console\Getopt($rules); $opts->parse(); } catch (Console\Exception\RuntimeException $e) { echo $e->getUsageMessage(); exit(2); } if ($opts->getOption('h')) { echo $opts->getUsageMessage(); exit; } $path = $libPath; if (array_key_exists('PWD', $_SERVER)) { $path = $_SERVER['PWD']; } if (isset($opts->l)) { $libraryPath = $opts->l; $libraryPath = rtrim($libraryPath, '/\\') . DIRECTORY_SEPARATOR; if (!is_dir($libraryPath)) { echo "Invalid library directory provided" . PHP_EOL . PHP_EOL; echo $opts->getUsageMessage(); exit(2); } $path = realpath($libraryPath);
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'; }
} } $libraryPath = getcwd(); // Setup autoloading $loader = new StandardAutoloader(array('autoregister_zf' => true)); $loader->register(); $rules = array('help|h' => 'Get usage message', 'library|l-s' => 'Library to parse; if none provided, assumes current directory', 'output|o-s' => 'Where to write autoload file; if not provided, assumes "autoload_classmap.php" in library directory', 'append|a' => 'Append to autoload file if it exists', 'overwrite|w' => 'Whether or not to overwrite existing autoload file', 'ignore|i-s' => 'Comma-separated namespaces to ignore', 'sort|s' => 'Alphabetically sort classes'); try { $opts = new Console\Getopt($rules); $opts->parse(); } catch (Console\Exception\RuntimeException $e) { echo $e->getUsageMessage(); exit(2); } if ($opts->getOption('h')) { echo $opts->getUsageMessage(); exit(0); } $ignoreNamespaces = array(); if (isset($opts->i)) { $ignoreNamespaces = explode(',', $opts->i); } $relativePathForClassmap = ''; if (isset($opts->l)) { if (!is_dir($opts->l)) { echo 'Invalid library directory provided' . PHP_EOL . PHP_EOL; echo $opts->getUsageMessage(); exit(2); } $libraryPath = $opts->l; }
public function testGetoptSetHelpInvalid() { $opts = new Getopt('abp:', array('-a')); $opts->setHelp(array( 'a' => 'apple', 'b' => 'banana', 'p' => 'pear', 'c' => 'cumquat')); $message = preg_replace('/Usage: .* \[ options \]/', 'Usage: <progname> [ options ]', $opts->getUsageMessage()); $message = preg_replace('/ /', '_', $message); $this->assertEquals($message, "Usage:_<progname>_[_options_]\n-a___________________apple\n-b___________________banana\n-p_<string>__________pear\n"); }
/** * @see \wcf\system\cli\command\ICLICommand::getUsage() */ public function getUsage() { return str_replace($_SERVER['argv'][0] . ' [ options ]', 'package [ options ] <install|uninstall> <package>', $this->argv->getUsageMessage()); }
public function testGetoptWithFreeformFlagOptionShowHelpAfterParseDoesNotShowFreeformFlags() { $opts = new Getopt(array('colors' => 'Colors-option'), array('color', '--freeform', 'test', 'zend'), array(Getopt::CONFIG_FREEFORM_FLAGS => true)); $opts->parse(); $message = preg_replace('/Usage: .* \\[ options \\]/', 'Usage: <progname> [ options ]', $opts->getUsageMessage()); $message = preg_replace('/ /', '_', $message); $this->assertEquals($message, "Usage:_<progname>_[_options_]\n--colors_____________Colors-option\n"); }
/** * @param array $argv * @throws \Zend\Console\Exception\RuntimeException */ public function parseGetOpt(array $argv) { $rules = array('h|help' => 'show this help', 'l|lines=i' => 'output the last N lines of a stacktrace. Default: 100', 'line-length=i' => 'maximum length of a line. Default 512', 'process-name=s' => 'name of running php processes. Default: autodetect', 'live' => 'search while running for new upcoming pid\'s', 'o|output=s' => 'output log to file'); $opts = new Console\Getopt($rules, $argv); $opts->parse(); if ($opts->help) { throw new Console\Exception\RuntimeException('', $opts->getUsageMessage()); } if ($opts->getOption('lines')) { $this->getStrace()->setLines(min(1000, max(1, $opts->getOption('lines')))); } if ($opts->getOption('line-length')) { $this->getStrace()->setLineLength(min(1 * 1024 * 1024, max(10, $opts->getOption('line-length')))); } if ($opts->getOption('process-name')) { $this->getProcessStatus()->setProcessName($opts->getOption('process-name')); } if ($opts->getOption('output')) { $fileOutput = new FileOutput($opts->getOption('output')); $this->getCommandLine()->attachObserver($fileOutput, 'stdout'); $this->getCommandLine()->attachObserver($fileOutput, 'stderr'); } if ($opts->getOption('live')) { $this->setLive(true); } }
/** * @see \wcf\system\cli\command\ICLICommand::getUsage() */ public function getUsage() { return str_replace($_SERVER['argv'][0] . ' [ options ]', 'worker [ options ] <worker>', $this->argv->getUsageMessage()); }
function exitWithMessage($msg, $help, $code) { title(); echo $msg . PHP_EOL; echo $help; exit($code); } $rules = array('help|h' => 'Get usage message', 'title|t-s' => 'Document title: default = "Foo"'); try { $opts = new Getopt($rules); $opts->parse(); } catch (Console\Exception\RuntimeException $e) { exitWithMessage($e->getMessage(), $e->getUsageMessage(), 1); } if ($opts->getOption('h')) { exitWithMessage('tdconv <testdox.html.file.name> <output.file.name>', $opts->getUsageMessage(), 0); } $title = false; $args = $opts->getArguments(); if ($opts->getOption('t')) { $title = $opts->getOption('t'); unset($args['title']); } if (count($args) !== 2) { exitWithMessage('Expected exactly two arguments, got ' . count($args), $opts->getUsageMessage(), 1000); } $testdoxFile = $args[0]; $outputFile = $args[1]; //get the xml translation $xsldoc = new \DOMDocument(); $xsldoc->load(dirname(__FILE__) . '/xsl/tdconv.xsl');
/** * @see \wcf\system\cli\command\ICLICommand::getUsage() */ public function getUsage() { return str_replace($_SERVER['argv'][0] . ' [ options ]', 'cronjob [ options ] execute', $this->argv->getUsageMessage()); }
/** * @see \wcf\system\cli\command\ICLICommand::getUsage() */ public function getUsage() { return str_replace($_SERVER['argv'][0] . ' [ options ]', 'help [ options ] <command>', $this->argv->getUsageMessage()); }