Skip to content

Commit

Permalink
Renaming a Shell::_getOptionParser -> getOptionParser
Browse files Browse the repository at this point in the history
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 14, 2010
1 parent ab794b3 commit 72e1a96
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
4 changes: 2 additions & 2 deletions cake/console/libs/api.php
Expand Up @@ -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(
Expand Down
9 changes: 6 additions & 3 deletions cake/console/libs/i18n.php
Expand Up @@ -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()
));
}

/**
Expand Down
12 changes: 6 additions & 6 deletions cake/console/libs/shell.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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}();
}
Expand All @@ -352,7 +352,7 @@ public function runCommand($command, $argv) {
*
* @return ConsoleOptionParser
*/
protected function _getOptionParser() {
public function getOptionParser() {
$parser = new ConsoleOptionParser($this->name);
return $parser;
}
Expand Down
15 changes: 15 additions & 0 deletions cake/console/libs/tasks/extract.php
Expand Up @@ -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
*
Expand Down
4 changes: 2 additions & 2 deletions cake/tests/cases/console/libs/shell.test.php
Expand Up @@ -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');

Expand Down

0 comments on commit 72e1a96

Please sign in to comment.