Skip to content

Commit 72e1a96

Browse files
committed
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.
1 parent ab794b3 commit 72e1a96

File tree

5 files changed

+31
-13
lines changed

5 files changed

+31
-13
lines changed

cake/console/libs/api.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ public function main() {
139139
*
140140
* @return ConsoleOptionParser
141141
*/
142-
protected function _getOptionParser() {
143-
$parser = parent::_getOptionParser();
142+
public function getOptionParser() {
143+
$parser = parent::getOptionParser();
144144
$parser->addArgument('type', array(
145145
'help' => 'Either a full path or type of class (model, behavior, controller, component, view, helper)'
146146
))->addArgument('className', array(

cake/console/libs/i18n.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,14 @@ public function initdb() {
107107
*
108108
* @return ConsoleOptionParser
109109
*/
110-
protected function _getOptionParser() {
111-
$parser = parent::_getOptionParser();
110+
public function getOptionParser() {
111+
$parser = parent::getOptionParser();
112112
return $parser->description(__('I18n Shell initializes i18n database table for your application and generates .pot files(s) with translations.'))
113113
->addSubcommand('initdb', array('help' => __('Initialize the i18n table.')))
114-
->addSubcommand('extract', array('help' => __('Extract the po translations from your application')));
114+
->addSubcommand('extract', array(
115+
'help' => __('Extract the po translations from your application'),
116+
'parser' => $this->Extract->getOptionParser()
117+
));
115118
}
116119

117120
/**

cake/console/libs/shell.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ function __construct(&$dispatch, $stdout = null, $stderr = null, $stdin = null)
174174
}
175175

176176
if ($this->name == null) {
177-
$this->name = Inflector::underscore(str_replace('Shell', '', get_class($this)));
177+
$this->name = Inflector::underscore(str_replace(array('Shell', 'Task'), '', get_class($this)));
178178
}
179179

180180
$this->Dispatch =& $dispatch;
@@ -324,19 +324,19 @@ public function runCommand($command, $argv) {
324324
array_shift($argv);
325325
}
326326

327-
$this->OptionParser = $this->_getOptionParser();
327+
$this->OptionParser = $this->getOptionParser();
328328
list($this->params, $this->args) = $this->OptionParser->parse($argv);
329329

330330
if (($isTask || $isMethod || $isMain) && $command !== 'execute' ) {
331331
$this->startup();
332332
}
333+
if (isset($this->params['help'])) {
334+
return $this->out($this->OptionParser->help($command));
335+
}
333336
if ($isTask) {
334337
$command = Inflector::camelize($command);
335338
return $this->{$command}->runCommand('execute', $argv);
336339
}
337-
if (isset($this->params['help'])) {
338-
return $this->out($this->OptionParser->help());
339-
}
340340
if ($isMethod) {
341341
return $this->{$command}();
342342
}
@@ -352,7 +352,7 @@ public function runCommand($command, $argv) {
352352
*
353353
* @return ConsoleOptionParser
354354
*/
355-
protected function _getOptionParser() {
355+
public function getOptionParser() {
356356
$parser = new ConsoleOptionParser($this->name);
357357
return $parser;
358358
}

cake/console/libs/tasks/extract.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,21 @@ function __extract() {
182182
$this->out(__('Done.'));
183183
}
184184

185+
/**
186+
* Get & configure the option parser
187+
*
188+
* @return void
189+
*/
190+
public function getOptionParser() {
191+
$parser = parent::getOptionParser();
192+
return $parser->description(__('CakePHP Language String Extraction:'))
193+
->addOption('app', array('help' => __('directory where your application is located.')))
194+
->addOption('paths', array('help' => __('comma separted list of paths, full paths are needed.')))
195+
->addOption('merge', array('help' => __('[yes|no] Merge all domain strings into the default.po file.')))
196+
->addOption('output', array('help' => __('Full path to output directory.')))
197+
->addOption('files', array('help' => __('comma separated list of files, full paths are needed.')));
198+
}
199+
185200
/**
186201
* Show help options
187202
*

cake/tests/cases/console/libs/shell.test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,8 +657,8 @@ function testRunCommandTriggeringHelp() {
657657
->will($this->returnValue(array(array('help' => true), array())));
658658
$Parser->expects($this->once())->method('help');
659659

660-
$Shell = $this->getMock('Shell', array('_getOptionParser', 'out', 'startup'), array(), '', false);
661-
$Shell->expects($this->once())->method('_getOptionParser')
660+
$Shell = $this->getMock('Shell', array('getOptionParser', 'out', 'startup'), array(), '', false);
661+
$Shell->expects($this->once())->method('getOptionParser')
662662
->will($this->returnValue($Parser));
663663
$Shell->expects($this->once())->method('out');
664664

0 commit comments

Comments
 (0)