Add Shell::$plugin and update getOptionParser()

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

Fixes #2359
This commit is contained in:
mark_story 2011-12-10 21:31:21 -05:00
parent 47b2f3e70c
commit 205bfb506f
4 changed files with 26 additions and 1 deletions

View file

@ -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;
}

View file

@ -219,6 +219,7 @@ class ShellDispatcher {
));
}
$Shell = new $class();
$Shell->plugin = trim($plugin, '.');
return $Shell;
}

View file

@ -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');

View file

@ -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());
}
}