Browse Source

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.

alysson 9 years ago
parent
commit
637c05c821

+ 15 - 0
src/Console/ShellDispatcher.php

@@ -210,6 +210,10 @@ class ShellDispatcher
             $this->help();
             return true;
         }
+        if (in_array($shell, ['version', '--version'])) {
+            $this->version();
+            return true;
+        }
 
         $Shell = $this->findShell($shell);
 
@@ -367,4 +371,15 @@ class ShellDispatcher
         $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();
+    }
 }

+ 11 - 2
src/Shell/CommandListShell.php

@@ -16,6 +16,7 @@ namespace Cake\Shell;
 
 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 @@ class CommandListShell extends Shell
      */
     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 @@ class CommandListShell extends Shell
             return;
         }
 
+        if (!empty($this->params['version'])) {
+            $this->out(Configure::version());
+            return;
+        }
+
         if (empty($this->params['xml'])) {
             $this->_asText($shellList);
         } else {
@@ -136,6 +142,9 @@ class CommandListShell extends Shell
         )->addOption('xml', [
             'help' => 'Get the listing as XML.',
             'boolean' => true
+        ])->addOption('version', [
+            'help' => 'Prints the current version of CakePHP.',
+            'boolean' => true
         ]);
 
         return $parser;

+ 17 - 0
tests/TestCase/Shell/CommandListShellTest.php

@@ -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 @@ class CommandListShellTest extends TestCase
         $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);
+    }
 }