Skip to content
Permalink
Browse files

Renaming a Shell::_getOptionParser -> getOptionParser

Made the method public so subparser help would be easy to wire up. Moving help generation above task invocation so it always displays.
  • Loading branch information...
markstory committed Oct 10, 2010
1 parent ab794b3 commit 72e1a96a9a7a55a2b6873bf0a40279e0750d9699
@@ -139,8 +139,8 @@ public function main() {
*
* @return ConsoleOptionParser
*/
protected function _getOptionParser() {
$parser = parent::_getOptionParser();
public function getOptionParser() {
$parser = parent::getOptionParser();
$parser->addArgument('type', array(
'help' => 'Either a full path or type of class (model, behavior, controller, component, view, helper)'
))->addArgument('className', array(
@@ -107,11 +107,14 @@ public function initdb() {
*
* @return ConsoleOptionParser
*/
protected function _getOptionParser() {
$parser = parent::_getOptionParser();
public function getOptionParser() {
$parser = parent::getOptionParser();
return $parser->description(__('I18n Shell initializes i18n database table for your application and generates .pot files(s) with translations.'))
->addSubcommand('initdb', array('help' => __('Initialize the i18n table.')))
->addSubcommand('extract', array('help' => __('Extract the po translations from your application')));
->addSubcommand('extract', array(
'help' => __('Extract the po translations from your application'),
'parser' => $this->Extract->getOptionParser()
));
}
/**
@@ -174,7 +174,7 @@ function __construct(&$dispatch, $stdout = null, $stderr = null, $stdin = null)
}
if ($this->name == null) {
$this->name = Inflector::underscore(str_replace('Shell', '', get_class($this)));
$this->name = Inflector::underscore(str_replace(array('Shell', 'Task'), '', get_class($this)));
}
$this->Dispatch =& $dispatch;
@@ -324,19 +324,19 @@ public function runCommand($command, $argv) {
array_shift($argv);
}
$this->OptionParser = $this->_getOptionParser();
$this->OptionParser = $this->getOptionParser();
list($this->params, $this->args) = $this->OptionParser->parse($argv);
if (($isTask || $isMethod || $isMain) && $command !== 'execute' ) {
$this->startup();
}
if (isset($this->params['help'])) {
return $this->out($this->OptionParser->help($command));
}
if ($isTask) {
$command = Inflector::camelize($command);
return $this->{$command}->runCommand('execute', $argv);
}
if (isset($this->params['help'])) {
return $this->out($this->OptionParser->help());
}
if ($isMethod) {
return $this->{$command}();
}
@@ -352,7 +352,7 @@ public function runCommand($command, $argv) {
*
* @return ConsoleOptionParser
*/
protected function _getOptionParser() {
public function getOptionParser() {
$parser = new ConsoleOptionParser($this->name);
return $parser;
}
@@ -182,6 +182,21 @@ function __extract() {
$this->out(__('Done.'));
}
/**
* Get & configure the option parser
*
* @return void
*/
public function getOptionParser() {
$parser = parent::getOptionParser();
return $parser->description(__('CakePHP Language String Extraction:'))
->addOption('app', array('help' => __('directory where your application is located.')))
->addOption('paths', array('help' => __('comma separted list of paths, full paths are needed.')))
->addOption('merge', array('help' => __('[yes|no] Merge all domain strings into the default.po file.')))
->addOption('output', array('help' => __('Full path to output directory.')))
->addOption('files', array('help' => __('comma separated list of files, full paths are needed.')));
}
/**
* Show help options
*
@@ -657,8 +657,8 @@ function testRunCommandTriggeringHelp() {
->will($this->returnValue(array(array('help' => true), array())));
$Parser->expects($this->once())->method('help');
$Shell = $this->getMock('Shell', array('_getOptionParser', 'out', 'startup'), array(), '', false);
$Shell->expects($this->once())->method('_getOptionParser')
$Shell = $this->getMock('Shell', array('getOptionParser', 'out', 'startup'), array(), '', false);
$Shell->expects($this->once())->method('getOptionParser')
->will($this->returnValue($Parser));
$Shell->expects($this->once())->method('out');

0 comments on commit 72e1a96

Please sign in to comment.
You can’t perform that action at this time.