Page MenuHomePhabricator

D21799.diff
No OneTemporary

D21799.diff

diff --git a/src/parser/argument/PhutilArgumentParser.php b/src/parser/argument/PhutilArgumentParser.php
--- a/src/parser/argument/PhutilArgumentParser.php
+++ b/src/parser/argument/PhutilArgumentParser.php
@@ -625,6 +625,33 @@
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() {
return $this->argv;
}

File Metadata

Mime Type
text/plain
Expires
May 14 2024, 5:33 AM (5 w, 15 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6285174
Default Alt Text
D21799.diff (1 KB)

Event Timeline