Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15504434
D21799.id51958.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D21799.id51958.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Tue, Apr 15, 5:51 PM (21 h, 17 m ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7412680
Default Alt Text
D21799.id51958.diff (1 KB)
Attached To
Mode
D21799: Add an ArgumentParser helper for integers
Attached
Detach File
Event Timeline
Log In to Comment