Skip to content
Permalink
Browse files

Adding a --sort param to view the command_list sorted in a different …

…way.

Test cases added.
Fixes #574
  • Loading branch information...
markstory committed Oct 27, 2010
1 parent 02ade65 commit 558bd7e3c29b8258b0e91e007dbe78a955522e0a
Showing with 70 additions and 2 deletions.
  1. +46 −1 cake/console/shells/command_list.php
  2. +24 −1 cake/tests/cases/console/shells/command_list.test.php
@@ -62,7 +62,11 @@ public function main() {
if ($shellList) {
ksort($shellList);
if (empty($this->params['xml'])) {
$this->_asText($shellList);
if (!empty($this->params['sort'])) {
$this->_asSorted($shellList);
} else {
$this->_asText($shellList);
}
} else {
$this->_asXml($shellList);
}
@@ -151,6 +155,44 @@ protected function _asText($shellList) {
$this->out("To get help on a specific command, type <info>cake shell_name --help</info>", 2);
}
/**
* Generates the shell list sorted by where the shells are found.
*
* @return void
*/
protected function _asSorted($shellList) {
$grouped = array();
foreach ($shellList as $shell => $types) {
foreach ($types as $type) {
$type = Inflector::camelize($type);
if (empty($grouped[$type])) {
$grouped[$type] = array();
}
$grouped[$type][] = $shell;
}
}
if (!empty($grouped['App'])) {
sort($grouped['App'], SORT_STRING);
$this->out('[ App ]');
$this->out(' ' . implode(', ', $grouped['App']), 2);
unset($grouped['App']);
}
foreach ($grouped as $section => $shells) {
if ($section == 'CORE') {
continue;
}
sort($shells, SORT_STRING);
$this->out('[ ' . $section . ' ]');
$this->out(' ' . implode(', ', $shells), 2);
}
if (!empty($grouped['CORE'])) {
sort($grouped['CORE'], SORT_STRING);
$this->out('[ Core ]');
$this->out(' ' . implode(', ', $grouped['CORE']), 2);
}
$this->out();
}
/**
* Output as XML
*
@@ -185,6 +227,9 @@ public function getOptionParser() {
->addOption('xml', array(
'help' => __('Get the listing as XML.'),
'boolean' => true
))->addOption('sort', array(
'help' => __('Sorts the commands by where they are located.'),
'boolean' => true
));
}
}
@@ -19,7 +19,6 @@
*/
App::import('Shell', 'CommandList', false);
require_once CAKE . 'console' . DS . 'shell_dispatcher.php';
class TestStringOutput extends ConsoleOutput {
public $output = '';
@@ -110,6 +109,30 @@ function testMain() {
$this->assertPattern($expected, $output);
}
/**
* Test the sort param
*
* @return void
*/
function testSortPlugin() {
$this->Shell->params['sort'] = true;
$this->Shell->main();
$output = $this->Shell->stdout->output;
$expected = "/\[.*App.*\]\n[ ]+sample/";
$this->assertPattern($expected, $output);
$expected = "/\[.*TestPluginTwo.*\]\n[ ]+example, welcome/";
$this->assertPattern($expected, $output);
$expected = "/\[.*TestPlugin.*\]\n[ ]+example/";
$this->assertPattern($expected, $output);
$expected = "/\[.*Core.*\]\n[ ]+acl, api, bake, command_list, console, i18n, schema, testsuite/";
$this->assertPattern($expected, $output);
}
/**
* test xml output.
*

0 comments on commit 558bd7e

Please sign in to comment.
You can’t perform that action at this time.