Page MenuHomePhabricator

D19984.id47691.diff
No OneTemporary

D19984.id47691.diff

diff --git a/src/parser/argument/PhutilArgumentSpellingCorrector.php b/src/parser/argument/PhutilArgumentSpellingCorrector.php
--- a/src/parser/argument/PhutilArgumentSpellingCorrector.php
+++ b/src/parser/argument/PhutilArgumentSpellingCorrector.php
@@ -4,6 +4,10 @@
private $editDistanceMatrix;
private $maximumDistance;
+ private $mode;
+
+ const MODE_COMMANDS = 'commands';
+ const MODE_FLAGS = 'flags';
/**
* Build a new corrector with parameters for correcting commands, like
@@ -31,6 +35,7 @@
return id(new self())
->setEditDistanceMatrix($matrix)
+ ->setMode(self::MODE_COMMANDS)
->setMaximumDistance($max_distance);
}
@@ -55,9 +60,19 @@
return id(new self())
->setEditDistanceMatrix($matrix)
+ ->setMode(self::MODE_FLAGS)
->setMaximumDistance($max_distance);
}
+ public function setMode($mode) {
+ $this->mode = $mode;
+ return $this;
+ }
+
+ public function getMode() {
+ return $this->mode;
+ }
+
public function setEditDistanceMatrix(PhutilEditDistanceMatrix $matrix) {
$this->editDistanceMatrix = $matrix;
return $this;
@@ -87,6 +102,14 @@
throw new PhutilInvalidStateException('setMaximumDistance');
}
+ // If we're correcting commands, never correct an input which begins
+ // with "-", since this is almost certainly intended to be a flag.
+ if ($this->getMode() === self::MODE_COMMANDS) {
+ if (preg_match('/^-/', $input)) {
+ return array();
+ }
+ }
+
$input = $this->normalizeString($input);
foreach ($options as $key => $option) {
$options[$key] = $this->normalizeString($option);

File Metadata

Mime Type
text/plain
Expires
Mon, Mar 10, 10:21 PM (3 w, 6 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7475746
Default Alt Text
D19984.id47691.diff (1 KB)

Event Timeline