From c871aa3cc2fd8ef68630ce7bd3ec933d3ed17333 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Mon, 19 Jun 2017 23:42:37 -0400 Subject: [PATCH] Add docs and simplify getShell(). --- src/Console/CommandRunner.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Console/CommandRunner.php b/src/Console/CommandRunner.php index 628fefe29f9..53197377fdb 100644 --- a/src/Console/CommandRunner.php +++ b/src/Console/CommandRunner.php @@ -66,15 +66,12 @@ public function run(array $argv, ConsoleIo $io = null) "Unknown root command{$command}. Was expecting `{$this->root}`." ); } - $io = $io ?: new ConsoleIo(); - // Remove the root executable segment array_shift($argv); - $shell = $this->getShell($io, $commands, $argv); + $io = $io ?: new ConsoleIo(); + $shell = $this->getShell($io, $commands, array_shift($argv)); - // Remove the command name segment - array_shift($argv); try { $shell->initialize(); $result = $shell->runCommand($argv, true); @@ -93,20 +90,22 @@ public function run(array $argv, ConsoleIo $io = null) } /** - * Get the shell instance for the argv list. + * Get the shell instance for a given command name * + * @param \Cake\Console\ConsoleIo $io The io wrapper for the created shell class. + * @param \Cake\Console\CommandCollection $commands The command collection to find the shell in. + * @param string $name The command name to find * @return \Cake\Console\Shell */ - protected function getShell(ConsoleIo $io, CommandCollection $commands, array $argv) + protected function getShell(ConsoleIo $io, CommandCollection $commands, $name) { - $command = array_shift($argv); - if (!$commands->has($command)) { + if (!$commands->has($name)) { throw new RuntimeException( - "Unknown command `{$this->root} {$command}`." . + "Unknown command `{$this->root} {$name}`." . " Run `{$this->root} --help` to get the list of valid commands." ); } - $classOrInstance = $commands->get($command); + $classOrInstance = $commands->get($name); if (is_string($classOrInstance)) { return new $classOrInstance($io); }