Skip to content

Commit 637c05c

Browse files
author
alysson
committed
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.
1 parent f8f4838 commit 637c05c

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

src/Console/ShellDispatcher.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ protected function _dispatch($extra = [])
210210
$this->help();
211211
return true;
212212
}
213+
if (in_array($shell, ['version', '--version'])) {
214+
$this->version();
215+
return true;
216+
}
213217

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

@@ -367,4 +371,15 @@ public function help()
367371
$this->args = array_merge(['command_list'], $this->args);
368372
$this->dispatch();
369373
}
374+
375+
/**
376+
* Prints the current version of CakePHP. Performs an internal dispatch to the CommandList Shell
377+
*
378+
* @return void
379+
*/
380+
public function version()
381+
{
382+
$this->args = array_merge(['command_list', '--version'], $this->args);
383+
$this->dispatch();
384+
}
370385
}

src/Shell/CommandListShell.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
use Cake\Console\ConsoleOutput;
1818
use Cake\Console\Shell;
19+
use Cake\Core\Configure;
1920
use Cake\Core\Plugin;
2021
use Cake\Utility\Inflector;
2122
use SimpleXmlElement;
@@ -41,7 +42,7 @@ class CommandListShell extends Shell
4142
*/
4243
public function startup()
4344
{
44-
if (empty($this->params['xml'])) {
45+
if (empty($this->params['xml']) && empty($this->params['version'])) {
4546
parent::startup();
4647
}
4748
}
@@ -53,7 +54,7 @@ public function startup()
5354
*/
5455
public function main()
5556
{
56-
if (empty($this->params['xml'])) {
57+
if (empty($this->params['xml']) && empty($this->params['version'])) {
5758
$this->out("<info>Current Paths:</info>", 2);
5859
$this->out("* app: " . APP_DIR);
5960
$this->out("* root: " . rtrim(ROOT, DIRECTORY_SEPARATOR));
@@ -68,6 +69,11 @@ public function main()
6869
return;
6970
}
7071

72+
if (!empty($this->params['version'])) {
73+
$this->out(Configure::version());
74+
return;
75+
}
76+
7177
if (empty($this->params['xml'])) {
7278
$this->_asText($shellList);
7379
} else {
@@ -136,6 +142,9 @@ public function getOptionParser()
136142
)->addOption('xml', [
137143
'help' => 'Get the listing as XML.',
138144
'boolean' => true
145+
])->addOption('version', [
146+
'help' => 'Prints the current version of CakePHP.',
147+
'boolean' => true
139148
]);
140149

141150
return $parser;

tests/TestCase/Shell/CommandListShellTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
namespace Cake\Test\TestCase\Shell;
1616

1717
use Cake\Console\ConsoleIo;
18+
use Cake\Core\Configure;
1819
use Cake\Core\Plugin;
1920
use Cake\TestSuite\Stub\ConsoleOutput;
2021
use Cake\TestSuite\TestCase;
@@ -131,4 +132,20 @@ public function testMainXml()
131132
$find = '<shell name="welcome" call_as="TestPluginTwo.welcome" provider="TestPluginTwo" help="TestPluginTwo.welcome -h"';
132133
$this->assertContains($find, $output);
133134
}
135+
136+
/**
137+
* test that main prints the cakephp's version.
138+
*
139+
* @return void
140+
*/
141+
public function testMainVersion()
142+
{
143+
$this->Shell->params['version'] = true;
144+
$this->Shell->main();
145+
$output = $this->out->messages();
146+
$output = implode("\n", $output);
147+
148+
$expected = Configure::version();
149+
$this->assertEquals($expected, $output);
150+
}
134151
}

0 commit comments

Comments
 (0)