本文整理汇总了PHP中PhutilArgumentParser::getArg方法的典型用法代码示例。如果您正苦于以下问题:PHP PhutilArgumentParser::getArg方法的具体用法?PHP PhutilArgumentParser::getArg怎么用?PHP PhutilArgumentParser::getArg使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhutilArgumentParser
的用法示例。
在下文中一共展示了PhutilArgumentParser::getArg方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute(PhutilArgumentParser $args)
{
$console = PhutilConsole::getConsole();
$ids = $args->getArg('id');
if (!$ids) {
throw new PhutilArgumentUsageException(pht("Use the '%s' flag to specify one or more SMS messages to show.", '--id'));
}
$messages = id(new PhabricatorSMS())->loadAllWhere('id IN (%Ld)', $ids);
if ($ids) {
$ids = array_fuse($ids);
$missing = array_diff_key($ids, $messages);
if ($missing) {
throw new PhutilArgumentUsageException(pht('Some specified SMS messages do not exist: %s', implode(', ', array_keys($missing))));
}
}
$last_key = last_key($messages);
foreach ($messages as $message_key => $message) {
$info = array();
$info[] = pht('PROPERTIES');
$info[] = pht('ID: %d', $message->getID());
$info[] = pht('Status: %s', $message->getSendStatus());
$info[] = pht('To: %s', $message->getToNumber());
$info[] = pht('From: %s', $message->getFromNumber());
$info[] = null;
$info[] = pht('BODY');
$info[] = $message->getBody();
$info[] = null;
$console->writeOut('%s', implode("\n", $info));
if ($message_key != $last_key) {
$console->writeOut("\n%s\n\n", str_repeat('-', 80));
}
}
}
示例2: execute
public function execute(PhutilArgumentParser $args)
{
$console = PhutilConsole::getConsole();
$argv = $args->getArg('args');
if (count($argv) == 0) {
throw new PhutilArgumentUsageException(pht('Specify a configuration key to delete.'));
}
$key = $argv[0];
if (count($argv) > 1) {
throw new PhutilArgumentUsageException(pht('Too many arguments: expected one key.'));
}
$use_database = $args->getArg('database');
if ($use_database) {
$config = new PhabricatorConfigDatabaseSource('default');
$config_type = 'database';
} else {
$config = new PhabricatorConfigLocalSource();
$config_type = 'local';
}
$values = $config->getKeys(array($key));
if (!$values) {
throw new PhutilArgumentUsageException(pht("Configuration key '%s' is not set in %s configuration!", $key, $config_type));
}
if ($use_database) {
$config_entry = PhabricatorConfigEntry::loadConfigEntry($key);
$config_entry->setIsDeleted(1);
$config_entry->save();
} else {
$config->deleteKeys(array($key));
}
$console->writeOut("%s\n", pht("Deleted '%s' from %s configuration.", $key, $config_type));
}
示例3: execute
public function execute(PhutilArgumentParser $args)
{
$console = PhutilConsole::getConsole();
$resource_type = $args->getArg('type');
if (!$resource_type) {
throw new PhutilArgumentUsageException(pht('Specify a resource type with `%s`.', '--type'));
}
$until = $args->getArg('until');
if (strlen($until)) {
$until = strtotime($until);
if ($until <= 0) {
throw new PhutilArgumentUsageException(pht('Unable to parse argument to "%s".', '--until'));
}
}
$attributes = $args->getArg('attributes');
if ($attributes) {
$options = new PhutilSimpleOptions();
$options->setCaseSensitive(true);
$attributes = $options->parse($attributes);
}
$lease = id(new DrydockLease())->setResourceType($resource_type);
if ($attributes) {
$lease->setAttributes($attributes);
}
if ($until) {
$lease->setUntil($until);
}
$lease->queueForActivation();
echo tsprintf("%s\n", pht('Waiting for daemons to activate lease...'));
$lease->waitUntilActive();
echo tsprintf("%s\n", pht('Activated lease "%s".', $lease->getID()));
return 0;
}
示例4: execute
public function execute(PhutilArgumentParser $args)
{
$pids = $args->getArg('pids');
$graceful = $args->getArg('graceful');
$force = $args->getArg('force');
return $this->executeStopCommand($pids, $graceful, $force);
}
示例5: didExecute
public function didExecute(PhutilArgumentParser $args)
{
$console = PhutilConsole::getConsole();
$patches = $this->getPatches();
if (!$this->isDryRun() && !$this->isForce()) {
$console->writeOut(phutil_console_wrap(pht('Before running storage upgrades, you should take down the ' . 'Phabricator web interface and stop any running Phabricator ' . 'daemons (you can disable this warning with %s).', '--force')));
if (!phutil_console_confirm(pht('Are you ready to continue?'))) {
$console->writeOut("%s\n", pht('Cancelled.'));
return 1;
}
}
$apply_only = $args->getArg('apply');
if ($apply_only) {
if (empty($patches[$apply_only])) {
throw new PhutilArgumentUsageException(pht("%s argument '%s' is not a valid patch. " . "Use '%s' to show patch status.", '--apply', $apply_only, './bin/storage status'));
}
}
$no_quickstart = $args->getArg('no-quickstart');
$init_only = $args->getArg('init-only');
$no_adjust = $args->getArg('no-adjust');
$this->upgradeSchemata($apply_only, $no_quickstart, $init_only);
if ($no_adjust || $init_only || $apply_only) {
$console->writeOut("%s\n", pht('Declining to apply storage adjustments.'));
return 0;
} else {
return $this->adjustSchemata(false);
}
}
示例6: execute
public function execute(PhutilArgumentParser $args)
{
$console = PhutilConsole::getConsole();
$in = $args->getArg('in');
if (!strlen($in)) {
throw new PhutilArgumentUsageException(pht('Specify the dumpfile to read with --in.'));
}
$from = $args->getArg('from');
if (!strlen($from)) {
throw new PhutilArgumentUsageException(pht('Specify namespace to rename from with --from.'));
}
$to = $args->getArg('to');
if (!strlen($to)) {
throw new PhutilArgumentUsageException(pht('Specify namespace to rename to with --to.'));
}
$patterns = array('use' => '@^(USE `)([^_]+)(_.*)$@', 'create' => '@^(CREATE DATABASE /\\*.*?\\*/ `)([^_]+)(_.*)$@');
$found = array_fill_keys(array_keys($patterns), 0);
$matches = null;
foreach (new LinesOfALargeFile($in) as $line) {
foreach ($patterns as $key => $pattern) {
if (preg_match($pattern, $line, $matches)) {
$namespace = $matches[2];
if ($namespace != $from) {
throw new Exception(pht('Expected namespace "%s", found "%s": %s.', $from, $namespace, $line));
}
$line = $matches[1] . $to . $matches[3];
$found[$key]++;
}
}
echo $line . "\n";
}
// Give the user a chance to catch things if the results are crazy.
$console->writeErr(pht('Adjusted **%s** create statements and **%s** use statements.', new PhutilNumber($found['create']), new PhutilNumber($found['use'])) . "\n");
return 0;
}
开发者ID:fengshao0907,项目名称:phabricator,代码行数:35,代码来源:PhabricatorStorageManagementRenamespaceWorkflow.php
示例7: execute
public function execute(PhutilArgumentParser $args)
{
$viewer = $this->getViewer();
$names = $args->getArg('buildable');
if (count($names) != 1) {
throw new PhutilArgumentUsageException(pht('Specify exactly one buildable object, by object name.'));
}
$name = head($names);
$buildable = id(new PhabricatorObjectQuery())->setViewer($viewer)->withNames($names)->executeOne();
if (!$buildable) {
throw new PhutilArgumentUsageException(pht('No such buildable "%s"!', $name));
}
if (!$buildable instanceof HarbormasterBuildableInterface) {
throw new PhutilArgumentUsageException(pht('Object "%s" is not a buildable!', $name));
}
$plan_id = $args->getArg('plan');
if (!$plan_id) {
throw new PhutilArgumentUsageException(pht('Use --plan to specify a build plan to run.'));
}
$plan = id(new HarbormasterBuildPlanQuery())->setViewer($viewer)->withIDs(array($plan_id))->executeOne();
if (!$plan) {
throw new PhutilArgumentUsageException(pht('Build plan "%s" does not exist.', $plan_id));
}
$console = PhutilConsole::getConsole();
$buildable = HarbormasterBuildable::initializeNewBuildable($viewer)->setIsManualBuildable(true)->setBuildablePHID($buildable->getHarbormasterBuildablePHID())->setContainerPHID($buildable->getHarbormasterContainerPHID())->save();
$console->writeOut("%s\n", pht('Applying plan %s to new buildable %s...', $plan->getID(), 'B' . $buildable->getID()));
$console->writeOut("\n %s\n\n", PhabricatorEnv::getProductionURI('/B' . $buildable->getID()));
PhabricatorWorker::setRunAllTasksInProcess(true);
$buildable->applyPlan($plan);
$console->writeOut("%s\n", pht('Done.'));
return 0;
}
示例8: execute
public function execute(PhutilArgumentParser $args)
{
$console = PhutilConsole::getConsole();
$public_keyfile = $args->getArg('public');
if (!strlen($public_keyfile)) {
throw new PhutilArgumentUsageException(pht('You must specify the path to a public keyfile with %s.', '--public'));
}
if (!Filesystem::pathExists($public_keyfile)) {
throw new PhutilArgumentUsageException(pht('Specified public keyfile "%s" does not exist!', $public_keyfile));
}
$public_key = Filesystem::readFile($public_keyfile);
$pkcs8_keyfile = $args->getArg('pkcs8');
if (!strlen($pkcs8_keyfile)) {
throw new PhutilArgumentUsageException(pht('You must specify the path to a pkcs8 keyfile with %s.', '--pkc8s'));
}
if (!Filesystem::pathExists($pkcs8_keyfile)) {
throw new PhutilArgumentUsageException(pht('Specified pkcs8 keyfile "%s" does not exist!', $pkcs8_keyfile));
}
$pkcs8_key = Filesystem::readFile($pkcs8_keyfile);
$warning = pht('Adding a PKCS8 keyfile to the cache can be very dangerous. If the ' . 'PKCS8 file really encodes a different public key than the one ' . 'specified, an attacker could use it to gain unauthorized access.' . "\n\n" . 'Generally, you should use this option only in a development ' . 'environment where ssh-keygen is broken and it is inconvenient to ' . 'fix it, and only if you are certain you understand the risks. You ' . 'should never cache a PKCS8 file you did not generate yourself.');
$console->writeOut("%s\n", phutil_console_wrap($warning));
$prompt = pht('Really trust this PKCS8 keyfile?');
if (!phutil_console_confirm($prompt)) {
throw new PhutilArgumentUsageException(pht('Aborted workflow.'));
}
$key = PhabricatorAuthSSHPublicKey::newFromRawKey($public_key);
$key->forcePopulatePKCS8Cache($pkcs8_key);
$console->writeOut("%s\n", pht('Cached PKCS8 key for public key.'));
return 0;
}
示例9: execute
public function execute(PhutilArgumentParser $args)
{
$is_dry = $args->getArg('dryrun');
$is_force = $args->getArg('force');
if (!$is_dry && !$is_force) {
echo phutil_console_wrap("Are you completely sure you really want to permanently destroy all " . "storage for Phabricator data? This operation can not be undone and " . "your data will not be recoverable if you proceed.");
if (!phutil_console_confirm('Permanently destroy all data?')) {
echo "Cancelled.\n";
exit(1);
}
if (!phutil_console_confirm('Really destroy all data forever?')) {
echo "Cancelled.\n";
exit(1);
}
}
$api = $this->getAPI();
$patches = $this->getPatches();
$databases = $api->getDatabaseList($patches);
$databases[] = $api->getDatabaseName('meta_data');
foreach ($databases as $database) {
if ($is_dry) {
echo "DRYRUN: Would drop database '{$database}'.\n";
} else {
echo "Dropping database '{$database}'...\n";
queryfx($api->getConn('meta_data', $select_database = false), 'DROP DATABASE IF EXISTS %T', $database);
}
}
if (!$is_dry) {
echo "Storage was destroyed.\n";
}
return 0;
}
示例10: execute
public function execute(PhutilArgumentParser $args)
{
$console = PhutilConsole::getConsole();
$daemon = new PhabricatorFactDaemon(array());
$daemon->setVerbose(true);
$daemon->setEngines(PhabricatorFactEngine::loadAllEngines());
$iterators = PhabricatorFactDaemon::getAllApplicationIterators();
$selected = $args->getArg('iterator');
if ($selected) {
$use = array();
foreach ($selected as $iterator_name) {
if (isset($iterators[$iterator_name])) {
$use[$iterator_name] = $iterators[$iterator_name];
} else {
$console->writeErr("%s\n", pht("Iterator '%s' does not exist.", $iterator_name));
}
}
$iterators = $use;
}
foreach ($iterators as $iterator_name => $iterator) {
if ($args->getArg('all')) {
$daemon->processIterator($iterator);
} else {
$daemon->processIteratorWithCursor($iterator_name, $iterator);
}
}
if (!$args->getArg('skip-aggregates')) {
$daemon->processAggregates();
}
return 0;
}
示例11: loadTasks
protected function loadTasks(PhutilArgumentParser $args)
{
$ids = $args->getArg('id');
$class = $args->getArg('class');
$min_failures = $args->getArg('min-failure-count');
if (!$ids && !$class && !$min_failures) {
throw new PhutilArgumentUsageException(pht('Use --id, --class, or --min-failure-count to select tasks.'));
}
$active_query = new PhabricatorWorkerActiveTaskQuery();
$archive_query = new PhabricatorWorkerArchiveTaskQuery();
if ($ids) {
$active_query = $active_query->withIDs($ids);
$archive_query = $archive_query->withIDs($ids);
}
if ($class) {
$class_array = array($class);
$active_query = $active_query->withClassNames($class_array);
$archive_query = $archive_query->withClassNames($class_array);
}
if ($min_failures) {
$active_query = $active_query->withFailureCountBetween($min_failures, null);
$archive_query = $archive_query->withFailureCountBetween($min_failures, null);
}
$active_tasks = $active_query->execute();
$archive_tasks = $archive_query->execute();
$tasks = mpull($active_tasks, null, 'getID') + mpull($archive_tasks, null, 'getID');
if ($ids) {
foreach ($ids as $id) {
if (empty($tasks[$id])) {
throw new PhutilArgumentUsageException(pht('No task exists with id "%s"!', $id));
}
}
}
if ($class && $min_failures) {
if (!$tasks) {
throw new PhutilArgumentUsageException(pht('No task exists with class "%s" and at least %d failures!', $class, $min_failures));
}
} else {
if ($class) {
if (!$tasks) {
throw new PhutilArgumentUsageException(pht('No task exists with class "%s"!', $class));
}
} else {
if ($min_failures) {
if (!$tasks) {
throw new PhutilArgumentUsageException(pht('No tasks exist with at least %d failures!', $min_failures));
}
}
}
}
// When we lock tasks properly, this gets populated as a side effect. Just
// fake it when doing manual CLI stuff. This makes sure CLI yields have
// their expires times set properly.
foreach ($tasks as $task) {
if ($task instanceof PhabricatorWorkerActiveTask) {
$task->setServerTime(PhabricatorTime::getNow());
}
}
return $tasks;
}
示例12: execute
public function execute(PhutilArgumentParser $args)
{
$console = PhutilConsole::getConsole();
$purge_all = $args->getArg('purge-all');
$purge = array('remarkup' => $purge_all || $args->getArg('purge-remarkup'), 'changeset' => $purge_all || $args->getArg('purge-changeset'), 'general' => $purge_all || $args->getArg('purge-general'));
if (!array_filter($purge)) {
$list = array();
foreach ($purge as $key => $ignored) {
$list[] = "'--purge-" . $key . "'";
}
throw new PhutilArgumentUsageException("Specify which cache or caches to purge, or use '--purge-all'. " . "Available caches are: " . implode(', ', $list) . ". Use '--help' " . "for more information.");
}
if ($purge['remarkup']) {
$console->writeOut('Purging remarkup cache...');
$this->purgeRemarkupCache();
$console->writeOut("done.\n");
}
if ($purge['changeset']) {
$console->writeOut('Purging changeset cache...');
$this->purgeChangesetCache();
$console->writeOut("done.\n");
}
if ($purge['general']) {
$console->writeOut('Purging general cache...');
$this->purgeGeneralCache();
$console->writeOut("done.\n");
}
}
示例13: execute
public function execute(PhutilArgumentParser $args)
{
$console = PhutilConsole::getConsole();
$resource_name = $args->getArg('name');
if (!$resource_name) {
throw new PhutilArgumentUsageException('Specify a resource name with `--name`.');
}
$blueprint_id = $args->getArg('blueprint');
if (!$blueprint_id) {
throw new PhutilArgumentUsageException('Specify a blueprint ID with `--blueprint`.');
}
$attributes = $args->getArg('attributes');
if ($attributes) {
$options = new PhutilSimpleOptions();
$options->setCaseSensitive(true);
$attributes = $options->parse($attributes);
}
$viewer = $this->getViewer();
$blueprint = id(new DrydockBlueprintQuery())->setViewer($viewer)->withIDs(array($blueprint_id))->executeOne();
if (!$blueprint) {
throw new PhutilArgumentUsageException('Specified blueprint does not exist.');
}
$resource = id(new DrydockResource())->setBlueprintPHID($blueprint->getPHID())->setType($blueprint->getImplementation()->getType())->setName($resource_name)->setStatus(DrydockResourceStatus::STATUS_OPEN);
if ($attributes) {
$resource->setAttributes($attributes);
}
$resource->save();
$console->writeOut("Created Resource %s\n", $resource->getID());
return 0;
}
示例14: execute
public function execute(PhutilArgumentParser $args)
{
$force = $args->getArg('force');
$unsafe = $args->getArg('unsafe');
$dry_run = $args->getArg('dryrun');
$this->requireAllPatchesApplied();
return $this->adjustSchemata($force, $unsafe, $dry_run);
}
示例15: execute
public function execute(PhutilArgumentParser $args)
{
$err = $this->executeStopCommand(array(), array('graceful' => $args->getArg('graceful'), 'force' => $args->getArg('force'), 'gently' => $args->getArg('gently')));
if ($err) {
return $err;
}
return $this->executeStartCommand(array('reserve' => (double) $args->getArg('autoscale-reserve', 0.0)));
}