Permalink
Browse files

Add Shell::$plugin and update getOptionParser()

Adding a plugin property allows the correct
usage/help information to be generated.

Fixes #2359
  • Loading branch information...
1 parent 47b2f3e commit 205bfb506ffdab7c2a223d82da7fa9aaf81c1132 @markstory markstory committed Dec 11, 2011
View
@@ -80,6 +80,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
*
* @var array
@@ -409,7 +417,8 @@ protected function _displayHelp($command) {
* @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;
}
@@ -219,6 +219,7 @@ protected function _getShell($shell) {
));
}
$Shell = new $class();
+ $Shell->plugin = trim($plugin, '.');
return $Shell;
}
@@ -422,6 +422,8 @@ public function testGetShell() {
$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');
@@ -841,4 +841,17 @@ public function testShellNaming() {
$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());
+ }
}

0 comments on commit 205bfb5

Please sign in to comment.