1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-25 00:02:40 +01:00

Allow "arc" to accept any prefix of a command as that command

Summary:
Ref T13546. Practically, this allows "arc branch" to run "arc branches".

(This risks overcorrection to some degree, but command correction only occurs if stdout is a TTY so the risk seems limited.)

Test Plan: Ran "arc branch", got "arc branches" as a correction.

Maniphest Tasks: T13546

Differential Revision: https://secure.phabricator.com/D21338
This commit is contained in:
epriestley 2020-06-08 14:50:35 -07:00
parent 31d08f9a8f
commit e8c3cc3289

View file

@ -115,6 +115,21 @@ final class PhutilArgumentSpellingCorrector extends Phobject {
$options[$key] = $this->normalizeString($option);
}
// In command mode, accept any unique prefix of a command as a shorthand
// for that command.
if ($this->getMode() === self::MODE_COMMANDS) {
$prefixes = array();
foreach ($options as $option) {
if (!strncmp($input, $option, strlen($input))) {
$prefixes[] = $option;
}
}
if (count($prefixes) === 1) {
return $prefixes;
}
}
$distances = array();
$inputv = phutil_utf8v($input);
foreach ($options as $option) {