Changeset View
Changeset View
Standalone View
Standalone View
src/parser/argument/PhutilArgumentParser.php
Show First 20 Lines • Show All 619 Lines • ▼ Show 20 Lines | public function getArg($name) { | ||||
if (idx($this->results, $name) !== null) { | if (idx($this->results, $name) !== null) { | ||||
return $this->results[$name]; | return $this->results[$name]; | ||||
} | } | ||||
return $this->specs[$name]->getDefault(); | return $this->specs[$name]->getDefault(); | ||||
} | } | ||||
public function getArgAsInteger($name) { | |||||
$value = $this->getArg($name); | |||||
if ($value === null) { | |||||
return $value; | |||||
} | |||||
if (!preg_match('/^-?\d+\z/', $value)) { | |||||
throw new PhutilArgumentUsageException( | |||||
pht( | |||||
'Parameter provided to argument "--%s" must be an integer.', | |||||
$name)); | |||||
} | |||||
$intvalue = (int)$value; | |||||
if (phutil_string_cast($intvalue) !== phutil_string_cast($value)) { | |||||
throw new PhutilArgumentUsageException( | |||||
pht( | |||||
'Parameter provided to argument "--%s" is too large to '. | |||||
'parse as an integer.', | |||||
$name)); | |||||
} | |||||
return $intvalue; | |||||
} | |||||
public function getUnconsumedArgumentVector() { | public function getUnconsumedArgumentVector() { | ||||
return $this->argv; | return $this->argv; | ||||
} | } | ||||
public function setUnconsumedArgumentVector(array $argv) { | public function setUnconsumedArgumentVector(array $argv) { | ||||
$this->argv = $argv; | $this->argv = $argv; | ||||
return $this; | return $this; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | public function renderWorkflowHelp( | ||||
$workflow = idx($workflows, strtolower($workflow_name)); | $workflow = idx($workflows, strtolower($workflow_name)); | ||||
if (!$workflow) { | if (!$workflow) { | ||||
$out[] = $this->indent( | $out[] = $this->indent( | ||||
$indent, | $indent, | ||||
pht('There is no **%s** workflow.', $workflow_name)); | pht('There is no **%s** workflow.', $workflow_name)); | ||||
} else { | } else { | ||||
$out[] = $this->indent($indent, $workflow->getExamples()); | $out[] = $this->indent($indent, $workflow->getExamples()); | ||||
$synopsis = $workflow->getSynopsis(); | |||||
if ($synopsis !== null) { | |||||
$out[] = $this->indent($indent, $workflow->getSynopsis()); | $out[] = $this->indent($indent, $workflow->getSynopsis()); | ||||
} | |||||
if ($show_details) { | if ($show_details) { | ||||
$full_help = $workflow->getHelp(); | $full_help = $workflow->getHelp(); | ||||
if ($full_help) { | if ($full_help) { | ||||
$out[] = null; | $out[] = null; | ||||
$out[] = $this->indent($indent, $full_help); | $out[] = $this->indent($indent, $full_help); | ||||
} | } | ||||
$specs = $this->renderArgumentSpecs($workflow->getArguments()); | $specs = $this->renderArgumentSpecs($workflow->getArguments()); | ||||
if ($specs) { | if ($specs) { | ||||
Show All 14 Lines | $message = tsprintf( | ||||
pht('Usage Exception:'), | pht('Usage Exception:'), | ||||
$ex->getMessage()); | $ex->getMessage()); | ||||
$this->logMessage($message); | $this->logMessage($message); | ||||
} | } | ||||
private function logMessage($message) { | private function logMessage($message) { | ||||
fwrite(STDERR, $message); | PhutilSystem::writeStderr($message); | ||||
} | } | ||||
/* -( Internals )---------------------------------------------------------- */ | /* -( Internals )---------------------------------------------------------- */ | ||||
private function filterWildcardArgv(array $argv) { | private function filterWildcardArgv(array $argv) { | ||||
foreach ($argv as $key => $value) { | foreach ($argv as $key => $value) { | ||||
▲ Show 20 Lines • Show All 201 Lines • Show Last 20 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0