diff --git a/src/Preflight/ArgsRemapper.php b/src/Preflight/ArgsRemapper.php index e2a1576ac1..873a2a21f7 100644 --- a/src/Preflight/ArgsRemapper.php +++ b/src/Preflight/ArgsRemapper.php @@ -6,13 +6,16 @@ */ class ArgsRemapper { + protected $remapOptions; + protected $remapCommandAliases; + /** * ArgsRemapper constructor */ - public function __construct($remap, $remove) + public function __construct($remapOptions, $remapCommandAliases) { - $this->remap = $remap; - $this->remove = $remove; + $this->remapOptions = $remapOptions; + $this->remapCommandAliases = $remapCommandAliases; } /** @@ -24,8 +27,9 @@ public function __construct($remap, $remove) public function remap($argv) { $result = []; + $sawCommmand = false; foreach ($argv as $arg) { - $arg = $this->remapArgument($arg); + $arg = $this->checkRemap($arg, $sawCommmand); if (isset($arg)) { $result[] = $arg; } @@ -34,47 +38,36 @@ public function remap($argv) } /** - * Apply any transformations to a single arg. + * Check to see if the provided single arg needs to be remapped. If + * it does, then the remapping is performed. * - * @param stinrg $arg One arguent to remap + * @param stinrg $arg One arguent to inspect * @return string The altered argument */ - protected function remapArgument($arg) + protected function checkRemap($arg, &$sawCommmand) { - if ($this->checkRemoval($arg)) { - return null; + if (!$sawCommmand && ctype_alpha($arg[0])) { + $sawCommand = true; + return $this->remapCommandAlias($arg); } - return $this->checkRemap($arg); + return $this->remapOptions($arg); } - /** - * Check to see if the provided argument should be removed / ignored. - * - * @param stinrg $arg One arguent to inspect - * @return bool - */ - protected function checkRemoval($arg) + protected function remapOptions($arg) { - foreach ($this->remove as $removalCandidate) { - if ($this->matches($arg, $removalCandidate)) { - return true; + foreach ($this->remapOptions as $from => $to) { + if ($this->matches($arg, $from)) { + return $to . substr($arg, strlen($from)); } } - return false; + return $arg; } - /** - * Check to see if the provided single arg needs to be remapped. If - * it does, then the remapping is performed. - * - * @param stinrg $arg One arguent to inspect - * @return string The altered argument - */ - protected function checkRemap($arg) + protected function remapCommandAlias($arg) { - foreach ($this->remap as $from => $to) { - if ($this->matches($arg, $from)) { - return $to . substr($arg, strlen($from)); + foreach ($this->remapCommandAliases as $from => $to) { + if ($arg == $from) { + return $to; } } return $arg; diff --git a/src/Preflight/Preflight.php b/src/Preflight/Preflight.php index bd2ae3e8b8..a162d18f9d 100644 --- a/src/Preflight/Preflight.php +++ b/src/Preflight/Preflight.php @@ -81,7 +81,7 @@ public function init(PreflightArgs $preflightArgs) * Eventually, we might want to expose this table to some form of * 'help' output, so folks can see the available conversions. */ - protected function remapArguments() + protected function remapOptions() { return [ '--ssh-options' => '-Dssh.options', @@ -94,21 +94,24 @@ protected function remapArguments() '--db-su' => '-Dsql.db-su', '--notify' => '-Dnotify.duration', '--xh-link' => '-Dxh.link', - // Map command aliases which Console complains about. - 'si' => 'site-install', - 'en' => 'pm-enable', ]; } /** - * Removal table for arguments. Anything found here will be silently - * removed. The option value is ignored; ergo, both --strict and - * --strict=0 will be removed; however, --stricter will not be removed. + * Symfony Console dislikes certain command aliases, because + * they are too similar to other Drush commands that contain + * the same characters. To avoid the "I don't know which + * command you mean"-type errors, we will replace problematic + * aliases with their longhand equivalents. + * + * This should be fixed in Symfony Console. */ - protected function removeArguments() + protected function remapCommandAliases() { - // Now we are going to support rather than remove --strict. - return []; + return [ + 'si' => 'site-install', + 'en' => 'pm-enable', + ]; } /** @@ -119,7 +122,7 @@ protected function removeArguments() public function preflightArgs($argv) { $argProcessor = new ArgsPreprocessor(); - $remapper = new ArgsRemapper($this->remapArguments(), $this->removeArguments()); + $remapper = new ArgsRemapper($this->remapOptions(), $this->remapCommandAliases()); $preflightArgs = new PreflightArgs([]); $argProcessor->setArgsRemapper($remapper);