Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add docs and simplify getShell().
  • Loading branch information
markstory committed Jun 20, 2017
1 parent 416a702 commit c871aa3
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/Console/CommandRunner.php
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down

0 comments on commit c871aa3

Please sign in to comment.