Skip to content

Commit

Permalink
Add --version parameter CommandList shell.
Browse files Browse the repository at this point in the history
It prints the current version of CakePHP.

Add `--version` and `version` parameter to ShellDispatcher.
It performs an internal dispatch to CommandList shell.

See #8891.
  • Loading branch information
alysson committed May 26, 2016
1 parent f8f4838 commit 637c05c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/Console/ShellDispatcher.php
Expand Up @@ -210,6 +210,10 @@ protected function _dispatch($extra = [])
$this->help();
return true;
}
if (in_array($shell, ['version', '--version'])) {
$this->version();
return true;
}

$Shell = $this->findShell($shell);

Expand Down Expand Up @@ -367,4 +371,15 @@ public function help()
$this->args = array_merge(['command_list'], $this->args);
$this->dispatch();
}

/**
* Prints the current version of CakePHP. Performs an internal dispatch to the CommandList Shell
*
* @return void
*/
public function version()
{
$this->args = array_merge(['command_list', '--version'], $this->args);
$this->dispatch();
}
}
13 changes: 11 additions & 2 deletions src/Shell/CommandListShell.php
Expand Up @@ -16,6 +16,7 @@

use Cake\Console\ConsoleOutput;
use Cake\Console\Shell;
use Cake\Core\Configure;
use Cake\Core\Plugin;
use Cake\Utility\Inflector;
use SimpleXmlElement;
Expand All @@ -41,7 +42,7 @@ class CommandListShell extends Shell
*/
public function startup()
{
if (empty($this->params['xml'])) {
if (empty($this->params['xml']) && empty($this->params['version'])) {
parent::startup();
}
}
Expand All @@ -53,7 +54,7 @@ public function startup()
*/
public function main()
{
if (empty($this->params['xml'])) {
if (empty($this->params['xml']) && empty($this->params['version'])) {
$this->out("<info>Current Paths:</info>", 2);
$this->out("* app: " . APP_DIR);
$this->out("* root: " . rtrim(ROOT, DIRECTORY_SEPARATOR));
Expand All @@ -68,6 +69,11 @@ public function main()
return;
}

if (!empty($this->params['version'])) {
$this->out(Configure::version());
return;
}

if (empty($this->params['xml'])) {
$this->_asText($shellList);
} else {
Expand Down Expand Up @@ -136,6 +142,9 @@ public function getOptionParser()
)->addOption('xml', [
'help' => 'Get the listing as XML.',
'boolean' => true
])->addOption('version', [
'help' => 'Prints the current version of CakePHP.',
'boolean' => true
]);

return $parser;
Expand Down
17 changes: 17 additions & 0 deletions tests/TestCase/Shell/CommandListShellTest.php
Expand Up @@ -15,6 +15,7 @@
namespace Cake\Test\TestCase\Shell;

use Cake\Console\ConsoleIo;
use Cake\Core\Configure;
use Cake\Core\Plugin;
use Cake\TestSuite\Stub\ConsoleOutput;
use Cake\TestSuite\TestCase;
Expand Down Expand Up @@ -131,4 +132,20 @@ public function testMainXml()
$find = '<shell name="welcome" call_as="TestPluginTwo.welcome" provider="TestPluginTwo" help="TestPluginTwo.welcome -h"';
$this->assertContains($find, $output);
}

/**
* test that main prints the cakephp's version.
*
* @return void
*/
public function testMainVersion()
{
$this->Shell->params['version'] = true;
$this->Shell->main();
$output = $this->out->messages();
$output = implode("\n", $output);

$expected = Configure::version();
$this->assertEquals($expected, $output);
}
}

0 comments on commit 637c05c

Please sign in to comment.