From e8c3cc32897e30d5b4aee92f8ce3ea6ed9d0377e Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 8 Jun 2020 14:50:35 -0700 Subject: [PATCH] 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 --- .../argument/PhutilArgumentSpellingCorrector.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/parser/argument/PhutilArgumentSpellingCorrector.php b/src/parser/argument/PhutilArgumentSpellingCorrector.php index dd999123..47218a5c 100644 --- a/src/parser/argument/PhutilArgumentSpellingCorrector.php +++ b/src/parser/argument/PhutilArgumentSpellingCorrector.php @@ -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) {