本文整理汇总了PHP中PhutilArgumentParser::printHelpAndExit方法的典型用法代码示例。如果您正苦于以下问题:PHP PhutilArgumentParser::printHelpAndExit方法的具体用法?PHP PhutilArgumentParser::printHelpAndExit怎么用?PHP PhutilArgumentParser::printHelpAndExit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhutilArgumentParser
的用法示例。
在下文中一共展示了PhutilArgumentParser::printHelpAndExit方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute(PhutilArgumentParser $args)
{
$with = $args->getArg('help-with-what');
if (!$with) {
$args->printHelpAndExit();
} else {
foreach ($with as $thing) {
echo phutil_console_format("**%s**\n\n", pht('%s WORKFLOW', strtoupper($thing)));
echo $args->renderWorkflowHelp($thing, $show_flags = true);
echo "\n";
}
exit(PhutilArgumentParser::PARSE_ERROR_CODE);
}
}
示例2: dirname
<?php
$root = dirname(dirname(dirname(__FILE__)));
require_once $root . '/scripts/__init_script__.php';
$args = new PhutilArgumentParser($argv);
$args->setTagline('test InteractiveEditor class');
$args->setSynopsis(<<<EOHELP
**interactive_editor.php** [__options__]
Edit some content via the InteractiveEditor class. This script
makes it easier to test changes to InteractiveEditor, which is
difficult to unit test.
EOHELP
);
$args->parseStandardArguments();
$args->parse(array(array('name' => 'fallback', 'param' => 'editor', 'help' => 'Set the fallback editor.'), array('name' => 'line', 'short' => 'l', 'param' => 'number', 'help' => 'Open at line number __number__.'), array('name' => 'name', 'param' => 'filename', 'help' => 'Set edited file name.')));
if ($args->getArg('help')) {
$args->printHelpAndExit();
}
$editor = new PhutilInteractiveEditor("The wizard quickly\n" . "jinxed the gnomes\n" . "before they vaporized.");
$name = $args->getArg('name');
if ($name) {
$editor->setName($name);
}
$line = $args->getArg('line');
if ($line) {
$editor->setLineOffset($line);
}
$fallback = $args->getArg('fallback');
if ($fallback) {
$editor->setFallbackEditor($fallback);
}
$result = $editor->editInteractively();
示例3: __construct
public function __construct(array $argv)
{
PhutilServiceProfiler::getInstance()->enableDiscardMode();
$original_argv = $argv;
$args = new PhutilArgumentParser($argv);
$args->setTagline('daemon overseer');
$args->setSynopsis(<<<EOHELP
**launch_daemon.php** [__options__] __daemon__
Launch and oversee an instance of __daemon__.
EOHELP
);
$args->parseStandardArguments();
$args->parsePartial(array(array('name' => 'trace-memory', 'help' => 'Enable debug memory tracing.'), array('name' => 'log', 'param' => 'file', 'help' => 'Send output to __file__.'), array('name' => 'daemonize', 'help' => 'Run in the background.'), array('name' => 'phd', 'param' => 'dir', 'help' => 'Write PID information to __dir__.'), array('name' => 'verbose', 'help' => 'Enable verbose activity logging.'), array('name' => 'load-phutil-library', 'param' => 'library', 'repeat' => true, 'help' => 'Load __library__.')));
$argv = array();
$more = $args->getUnconsumedArgumentVector();
$this->daemon = array_shift($more);
if (!$this->daemon) {
$args->printHelpAndExit();
}
if ($args->getArg('trace')) {
$this->traceMode = true;
$argv[] = '--trace';
}
if ($args->getArg('trace-memory')) {
$this->traceMode = true;
$this->traceMemory = true;
$argv[] = '--trace-memory';
}
if ($args->getArg('load-phutil-library')) {
foreach ($args->getArg('load-phutil-library') as $library) {
$argv[] = '--load-phutil-library=' . $library;
}
}
$log = $args->getArg('log');
if ($log) {
ini_set('error_log', $log);
$argv[] = '--log=' . $log;
}
$verbose = $args->getArg('verbose');
if ($verbose) {
$this->verbose = true;
$argv[] = '--verbose';
}
$this->daemonize = $args->getArg('daemonize');
$this->phddir = $args->getArg('phd');
$this->argv = $argv;
$this->moreArgs = coalesce($more, array());
error_log("Bringing daemon '{$this->daemon}' online...");
if (self::$instance) {
throw new Exception('You may not instantiate more than one Overseer per process.');
}
self::$instance = $this;
if ($this->daemonize) {
// We need to get rid of these or the daemon will hang when we TERM it
// waiting for something to read the buffers. TODO: Learn how unix works.
fclose(STDOUT);
fclose(STDERR);
ob_start();
$pid = pcntl_fork();
if ($pid === -1) {
throw new Exception('Unable to fork!');
} else {
if ($pid) {
exit(0);
}
}
}
if ($this->phddir) {
$desc = array('name' => $this->daemon, 'argv' => $this->moreArgs, 'pid' => getmypid(), 'start' => time());
Filesystem::writeFile($this->phddir . '/daemon.' . getmypid(), json_encode($desc));
}
$this->daemonID = $this->generateDaemonID();
$this->dispatchEvent(self::EVENT_DID_LAUNCH, array('argv' => array_slice($original_argv, 1), 'explicitArgv' => $this->moreArgs));
declare (ticks=1);
pcntl_signal(SIGUSR1, array($this, 'didReceiveKeepaliveSignal'));
pcntl_signal(SIGUSR2, array($this, 'didReceiveNotifySignal'));
pcntl_signal(SIGINT, array($this, 'didReceiveGracefulSignal'));
pcntl_signal(SIGTERM, array($this, 'didReceiveTerminalSignal'));
}
示例4: __construct
public function __construct(array $argv)
{
PhutilServiceProfiler::getInstance()->enableDiscardMode();
$original_argv = $argv;
$args = new PhutilArgumentParser($argv);
$args->setTagline('daemon overseer');
$args->setSynopsis(<<<EOHELP
**launch_daemon.php** [__options__] __daemon__
Launch and oversee an instance of __daemon__.
EOHELP
);
$args->parsePartial(array(array('name' => 'trace', 'help' => 'Enable debug tracing.'), array('name' => 'trace-memory', 'help' => 'Enable debug memory tracing.'), array('name' => 'log', 'param' => 'file', 'help' => 'Send output to __file__.'), array('name' => 'daemonize', 'help' => 'Run in the background.'), array('name' => 'phd', 'param' => 'dir', 'help' => 'Write PID information to __dir__.'), array('name' => 'conduit-uri', 'param' => 'uri', 'help' => 'Send logs to Conduit on __uri__.'), array('name' => 'verbose', 'help' => 'Enable verbose activity logging.')));
$argv = $args->getUnconsumedArgumentVector();
$this->daemon = array_shift($argv);
if (!$this->daemon) {
$args->printHelpAndExit();
}
if ($args->getArg('trace')) {
$this->traceMode = true;
array_unshift($argv, '--trace');
}
if ($args->getArg('trace-memory')) {
$this->traceMode = true;
$this->traceMemory = true;
array_unshift($argv, '--trace-memory');
}
$log = $args->getArg('log');
if ($log) {
ini_set('error_log', $log);
array_unshift($argv, '--log=' . $log);
}
$verbose = $args->getArg('verbose');
if ($verbose) {
$this->verbose = true;
array_unshift($argv, '--verbose');
}
$this->daemonize = $args->getArg('daemonize');
$this->phddir = $args->getArg('phd');
$this->conduitURI = $args->getArg('conduit-uri');
$this->argv = $argv;
error_log("Bringing daemon '{$this->daemon}' online...");
if (self::$instance) {
throw new Exception("You may not instantiate more than one Overseer per process.");
}
self::$instance = $this;
if ($this->daemonize) {
// We need to get rid of these or the daemon will hang when we TERM it
// waiting for something to read the buffers. TODO: Learn how unix works.
fclose(STDOUT);
fclose(STDERR);
ob_start();
$pid = pcntl_fork();
if ($pid === -1) {
throw new Exception("Unable to fork!");
} else {
if ($pid) {
exit(0);
}
}
}
if ($this->phddir) {
$desc = array('name' => $this->daemon, 'pid' => getmypid(), 'start' => time());
Filesystem::writeFile($this->phddir . '/daemon.' . getmypid(), json_encode($desc));
}
if ($this->conduitURI) {
$this->conduit = new ConduitClient($this->conduitURI);
$this->daemonLogID = $this->conduit->callMethodSynchronous('daemon.launched', array('daemon' => $this->daemon, 'host' => php_uname('n'), 'pid' => getmypid(), 'argv' => json_encode(array_slice($original_argv, 1))));
}
declare (ticks=1);
pcntl_signal(SIGUSR1, array($this, 'didReceiveKeepaliveSignal'));
pcntl_signal(SIGINT, array($this, 'didReceiveTerminalSignal'));
pcntl_signal(SIGTERM, array($this, 'didReceiveTerminalSignal'));
}