From 72e1a96a9a7a55a2b6873bf0a40279e0750d9699 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 10 Oct 2010 01:56:23 -0400 Subject: [PATCH] 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. --- cake/console/libs/api.php | 4 ++-- cake/console/libs/i18n.php | 9 ++++++--- cake/console/libs/shell.php | 12 ++++++------ cake/console/libs/tasks/extract.php | 15 +++++++++++++++ cake/tests/cases/console/libs/shell.test.php | 4 ++-- 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/cake/console/libs/api.php b/cake/console/libs/api.php index acd20456b45..d0c19da7ef4 100644 --- a/cake/console/libs/api.php +++ b/cake/console/libs/api.php @@ -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( diff --git a/cake/console/libs/i18n.php b/cake/console/libs/i18n.php index 4c920367e37..24cc1d8cdb6 100644 --- a/cake/console/libs/i18n.php +++ b/cake/console/libs/i18n.php @@ -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() + )); } /** diff --git a/cake/console/libs/shell.php b/cake/console/libs/shell.php index 44b891593eb..bca1e5a3bfe 100644 --- a/cake/console/libs/shell.php +++ b/cake/console/libs/shell.php @@ -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; } diff --git a/cake/console/libs/tasks/extract.php b/cake/console/libs/tasks/extract.php index 8cbf27a9673..713ae299b28 100644 --- a/cake/console/libs/tasks/extract.php +++ b/cake/console/libs/tasks/extract.php @@ -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 * diff --git a/cake/tests/cases/console/libs/shell.test.php b/cake/tests/cases/console/libs/shell.test.php index e21b47f29bb..5fd0b119c00 100644 --- a/cake/tests/cases/console/libs/shell.test.php +++ b/cake/tests/cases/console/libs/shell.test.php @@ -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');