Skip to content

Commit

Permalink
Updating ApiShell to use ConsoleOptionParser correctly.
Browse files Browse the repository at this point in the history
Removing old help method.
  • Loading branch information
markstory committed Oct 14, 2010
1 parent c0d15a4 commit 2a2428a
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions cake/console/libs/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function initialize() {
*/
public function main() {
if (empty($this->args)) {
return $this->help();
return $this->out($this->OptionParser->help());
}

$type = strtolower($this->args[0]);
Expand All @@ -78,7 +78,6 @@ public function main() {
$file = Inflector::underscore($this->args[1]);
$class = Inflector::camelize($file);
}

$objects = App::objects('class', $path);
if (in_array($class, $objects)) {
if (in_array($type, array('behavior', 'component', 'helper')) && $type !== $file) {
Expand All @@ -88,19 +87,18 @@ public function main() {
}

} else {
$this->err(sprintf(__('%s not found'), $class));
$this->_stop();
$this->error(sprintf(__('%s not found'), $class));
}

$parsed = $this->__parseClass($path . $file .'.php', $class);

if (!empty($parsed)) {
if (isset($this->params['m'])) {
if (!isset($parsed[$this->params['m']])) {
$this->err(sprintf(__('%s::%s() could not be found'), $class, $this->params['m']));
if (isset($this->params['method'])) {
if (!isset($parsed[$this->params['method']])) {
$this->err(sprintf(__('%s::%s() could not be found'), $class, $this->params['method']));
$this->_stop();
}
$method = $parsed[$this->params['m']];
$method = $parsed[$this->params['method']];
$this->out($class .'::'.$method['method'] . $method['parameters']);
$this->hr();
$this->out($method['comment'], true);
Expand Down Expand Up @@ -136,6 +134,23 @@ public function main() {
}
}

/**
* Get and configure the optionparser.
*
* @return ConsoleOptionParser
*/
protected 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(
'help' => 'A CakePHP core class name (e.g: Component, HtmlHelper).'
))->addOption('method', array(
'short' => 'm',
'help' => __('The specific method you want help on.')
))->description(__('Lookup doc block comments for classes in CakePHP.'));
return $parser;
}
/**
* Show help for this shell.
*
Expand Down

0 comments on commit 2a2428a

Please sign in to comment.