diff --git a/lib/Cake/Console/Shell.php b/lib/Cake/Console/Shell.php index b8b4919e2..dc5e187fb 100644 --- a/lib/Cake/Console/Shell.php +++ b/lib/Cake/Console/Shell.php @@ -79,6 +79,14 @@ class Shell extends Object { */ public $name = null; +/** + * The name of the plugin the shell belongs to. + * Is automatically set by ShellDispatcher when a shell is constructed. + * + * @var string + */ + public $plugin = null; + /** * Contains tasks to load and instantiate * @@ -409,7 +417,8 @@ class Shell extends Object { * @link http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::getOptionParser */ public function getOptionParser() { - $parser = new ConsoleOptionParser($this->name); + $name = ($this->plugin ? $this->plugin . '.' : '') . $this->name; + $parser = new ConsoleOptionParser($name); return $parser; } diff --git a/lib/Cake/Console/ShellDispatcher.php b/lib/Cake/Console/ShellDispatcher.php index 622cc9764..3d01c8256 100644 --- a/lib/Cake/Console/ShellDispatcher.php +++ b/lib/Cake/Console/ShellDispatcher.php @@ -219,6 +219,7 @@ class ShellDispatcher { )); } $Shell = new $class(); + $Shell->plugin = trim($plugin, '.'); return $Shell; } diff --git a/lib/Cake/Test/Case/Console/ShellDispatcherTest.php b/lib/Cake/Test/Case/Console/ShellDispatcherTest.php index 95c9da749..586166632 100644 --- a/lib/Cake/Test/Case/Console/ShellDispatcherTest.php +++ b/lib/Cake/Test/Case/Console/ShellDispatcherTest.php @@ -422,6 +422,8 @@ class ShellDispatcherTest extends CakeTestCase { $Dispatcher = new TestShellDispatcher(); $result = $Dispatcher->getShell('test_plugin.example'); $this->assertInstanceOf('ExampleShell', $result); + $this->assertEquals('TestPlugin', $result->plugin); + $this->assertEquals('Example', $result->name); $Dispatcher = new TestShellDispatcher(); $result = $Dispatcher->getShell('TestPlugin.example'); diff --git a/lib/Cake/Test/Case/Console/ShellTest.php b/lib/Cake/Test/Case/Console/ShellTest.php index fd14ec7b0..af27aed37 100644 --- a/lib/Cake/Test/Case/Console/ShellTest.php +++ b/lib/Cake/Test/Case/Console/ShellTest.php @@ -841,4 +841,17 @@ TEXT; $expected = 'TestApple'; $this->assertEquals($expected, $this->Shell->TestApple->name); } + +/** + * Test that option parsers are created with the correct name/command. + * + * @return void + */ + public function testGetOptionParser() { + $this->Shell->name = 'test'; + $this->Shell->plugin = 'plugin'; + $parser = $this->Shell->getOptionParser(); + + $this->assertEquals('plugin.test', $parser->command()); + } }