Skip to content

Commit 2a2428a

Browse files
committed
Updating ApiShell to use ConsoleOptionParser correctly.
Removing old help method.
1 parent c0d15a4 commit 2a2428a

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

cake/console/libs/api.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function initialize() {
6060
*/
6161
public function main() {
6262
if (empty($this->args)) {
63-
return $this->help();
63+
return $this->out($this->OptionParser->help());
6464
}
6565

6666
$type = strtolower($this->args[0]);
@@ -78,7 +78,6 @@ public function main() {
7878
$file = Inflector::underscore($this->args[1]);
7979
$class = Inflector::camelize($file);
8080
}
81-
8281
$objects = App::objects('class', $path);
8382
if (in_array($class, $objects)) {
8483
if (in_array($type, array('behavior', 'component', 'helper')) && $type !== $file) {
@@ -88,19 +87,18 @@ public function main() {
8887
}
8988

9089
} else {
91-
$this->err(sprintf(__('%s not found'), $class));
92-
$this->_stop();
90+
$this->error(sprintf(__('%s not found'), $class));
9391
}
9492

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

9795
if (!empty($parsed)) {
98-
if (isset($this->params['m'])) {
99-
if (!isset($parsed[$this->params['m']])) {
100-
$this->err(sprintf(__('%s::%s() could not be found'), $class, $this->params['m']));
96+
if (isset($this->params['method'])) {
97+
if (!isset($parsed[$this->params['method']])) {
98+
$this->err(sprintf(__('%s::%s() could not be found'), $class, $this->params['method']));
10199
$this->_stop();
102100
}
103-
$method = $parsed[$this->params['m']];
101+
$method = $parsed[$this->params['method']];
104102
$this->out($class .'::'.$method['method'] . $method['parameters']);
105103
$this->hr();
106104
$this->out($method['comment'], true);
@@ -136,6 +134,23 @@ public function main() {
136134
}
137135
}
138136

137+
/**
138+
* Get and configure the optionparser.
139+
*
140+
* @return ConsoleOptionParser
141+
*/
142+
protected function _getOptionParser() {
143+
$parser = parent::_getOptionParser();
144+
$parser->addArgument('type', array(
145+
'help' => 'Either a full path or type of class (model, behavior, controller, component, view, helper)'
146+
))->addArgument('className', array(
147+
'help' => 'A CakePHP core class name (e.g: Component, HtmlHelper).'
148+
))->addOption('method', array(
149+
'short' => 'm',
150+
'help' => __('The specific method you want help on.')
151+
))->description(__('Lookup doc block comments for classes in CakePHP.'));
152+
return $parser;
153+
}
139154
/**
140155
* Show help for this shell.
141156
*

0 commit comments

Comments
 (0)