From 3f08be54fb23941c2bafcaadda6e623eb3905e35 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Thu, 27 Jul 2017 23:56:59 -0400 Subject: [PATCH] Output the command list when no command is given. Make `bin/cake` in CommandRunner work similar to how it works with ShellDispatcher. Output the help list when no command is given. --- src/Console/CommandRunner.php | 4 ++++ tests/TestCase/Console/CommandRunnerTest.php | 23 ++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/Console/CommandRunner.php b/src/Console/CommandRunner.php index 1b390520639..b39a5ddddaa 100644 --- a/src/Console/CommandRunner.php +++ b/src/Console/CommandRunner.php @@ -162,6 +162,10 @@ public function run(array $argv, ConsoleIo $io = null) */ protected function getShell(ConsoleIo $io, CommandCollection $commands, $name) { + if (!$name) { + $io->err('No command provided. Choose one of the available commands.', 2); + $name = 'help'; + } if (isset($this->aliases[$name])) { $name = $this->aliases[$name]; } diff --git a/tests/TestCase/Console/CommandRunnerTest.php b/tests/TestCase/Console/CommandRunnerTest.php index 98f8cf84fd4..e9e4342146c 100644 --- a/tests/TestCase/Console/CommandRunnerTest.php +++ b/tests/TestCase/Console/CommandRunnerTest.php @@ -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 *