Skip to content

Commit

Permalink
Output the command list when no command is given.
Browse files Browse the repository at this point in the history
Make `bin/cake` in CommandRunner work similar to how it works with
ShellDispatcher. Output the help list when no command is given.
  • Loading branch information
markstory committed Jul 28, 2017
1 parent 0a5bf84 commit 3f08be5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Console/CommandRunner.php
Expand Up @@ -162,6 +162,10 @@ public function run(array $argv, ConsoleIo $io = null)
*/
protected function getShell(ConsoleIo $io, CommandCollection $commands, $name)
{
if (!$name) {
$io->err('<error>No command provided. Choose one of the available commands.</error>', 2);
$name = 'help';
}
if (isset($this->aliases[$name])) {
$name = $this->aliases[$name];
}
Expand Down
23 changes: 23 additions & 0 deletions tests/TestCase/Console/CommandRunnerTest.php
Expand Up @@ -145,6 +145,29 @@ public function testRunHelpShortOption()
$this->assertContains('Available Commands', $messages);
}

/**
* Test that no command outputs the command list
*
* @return void
*/
public function testRunNoCommand()
{
$app = $this->getMockBuilder(BaseApplication::class)
->setMethods(['middleware', 'bootstrap'])
->setConstructorArgs([$this->config])
->getMock();

$output = new ConsoleOutput();
$runner = new CommandRunner($app);
$result = $runner->run(['cake'], $this->getMockIo($output));

$this->assertSame(0, $result, 'help output is success.');
$messages = implode("\n", $output->messages());
$this->assertContains('No command provided. Choose one of the available commands', $messages);
$this->assertContains('- i18n', $messages);
$this->assertContains('Available Commands', $messages);
}

/**
* Test using `cake --verson` invokes the version command
*
Expand Down

0 comments on commit 3f08be5

Please sign in to comment.