Skip to content
Permalink
Browse files

Add `--version` parameter CommandList shell.

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
alysson committed May 26, 2016
1 parent f8f4838 commit 637c05c821b3c18fc6209fdd5f22ab17326053cc
Showing with 43 additions and 2 deletions.
  1. +15 −0 src/Console/ShellDispatcher.php
  2. +11 −2 src/Shell/CommandListShell.php
  3. +17 −0 tests/TestCase/Shell/CommandListShellTest.php
@@ -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);
@@ -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();
}
}
@@ -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;
@@ -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();
}
}
@@ -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));
@@ -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 {
@@ -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;
@@ -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;
@@ -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.
You can’t perform that action at this time.