Skip to content

Commit

Permalink
mend
Browse files Browse the repository at this point in the history
  • Loading branch information
AD7six authored and markstory committed Aug 12, 2009
1 parent 31d136c commit b53c733
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 43 deletions.
Empty file removed app/tmp/cache/persistent/empty
Empty file.
68 changes: 50 additions & 18 deletions cake/console/cake.php
Expand Up @@ -27,6 +27,7 @@
if (!defined('E_DEPRECATED')) {
define('E_DEPRECATED', 8192);
}

/**
* Shell dispatcher
*
Expand Down Expand Up @@ -402,6 +403,7 @@ function dispatch() {
$this->stderr($title . "\n" . $message . "\n");
return false;
}

/**
* Get shell to use, either plugin shell or application shell
*
Expand Down Expand Up @@ -606,28 +608,58 @@ function help() {
$this->stdout("Example: -app relative/path/to/myapp or -app /absolute/path/to/myapp");

$this->stdout("\nAvailable Shells:");
$_shells = array();
$shellList = array();
foreach ($this->shellPaths as $path) {
if (is_dir($path)) {
$shells = App::objects('file', $path);
$path = str_replace(CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS, 'CORE' . DS, $path);
$path = str_replace(APP, 'APP' . DS, $path);
$path = str_replace(ROOT, 'ROOT', $path);
$path = rtrim($path, DS);
$this->stdout("\n " . $path . ":");
if (empty($shells)) {
$this->stdout("\t - none");
} else {
sort($shells);
foreach ($shells as $shell) {

if ($shell !== 'shell.php') {
$this->stdout("\t " . str_replace('.php', '', $shell));
}
}
if (!is_dir($path)) {
continue;
}
$shells = App::objects('file', $path);
if (empty($shells)) {
continue;
}
if (preg_match('@plugins[\\\/]([^\\\/]*)@', $path, $matches)) {
$type = Inflector::camelize($matches[1]);
} elseif (preg_match('@([^\\\/]*)[\\\/]vendors[\\\/]@', $path, $matches)) {
$type = $matches[1];
} elseif (strpos($path, CAKE_CORE_INCLUDE_PATH . DS . 'cake') === 0) {
$type = 'CORE';
} else {
$type = 'app';
}
foreach ($shells as $shell) {
if ($shell !== 'shell.php') {
$shell = str_replace('.php', '', $shell);
$shellList[$shell][$type] = $type;
}
}
}
if ($shellList) {
ksort($shellList);
if (DS === '/') {
$width = exec('tput cols') - 2;
}
if (empty($width)) {
$width = 80;
}
$columns = max(1, floor($width / 30));
$rows = ceil(count($shellList) / $columns);

foreach($shellList as $shell => $types) {
sort($types);
$shellList[$shell] = str_pad($shell . ' [' . implode ($types, ', ') . ']', $width / $columns);
}
$out = array_chunk($shellList, $rows);
for($i = 0; $i < $rows; $i++) {
$row = '';
for($j = 0; $j < $columns; $j++) {
if (!isset($out[$j][$i])) {
continue;
}
$row .= $out[$j][$i];
}
$this->stdout(" " . $row);
}
}
$this->stdout("\nTo run a command, type 'cake shell_name [args]'");
$this->stdout("To get help on a specific command, type 'cake shell_name help'");
}
Expand Down
53 changes: 28 additions & 25 deletions cake/tests/cases/console/cake.test.php
Expand Up @@ -36,8 +36,8 @@
ob_end_clean();
}


require_once CONSOLE_LIBS . 'shell.php';

/**
* TestShellDispatcher class
*
Expand Down Expand Up @@ -85,6 +85,7 @@ class TestShellDispatcher extends ShellDispatcher {
* @access public
*/
var $TestShell;

/**
* _initEnvironment method
*
Expand Down Expand Up @@ -138,6 +139,7 @@ function _stop($status = 0) {
$this->stopped = 'Stopped with status: ' . $status;
return $status;
}

/**
* getShell
*
Expand All @@ -148,6 +150,7 @@ function _stop($status = 0) {
function getShell($plugin = null) {
return $this->_getShell($plugin);
}

/**
* _getShell
*
Expand Down Expand Up @@ -439,7 +442,6 @@ function testParseParams() {
$Dispatcher->parseParams($params);
$this->assertEqual($expected, $Dispatcher->params);


$params = array(
'cake.php',
'-working',
Expand Down Expand Up @@ -510,6 +512,7 @@ function testGetShell() {
$result = $Dispatcher->getShell('test_plugin');
$this->assertIsA($result, 'ExampleShell');
}

/**
* Verify correct dispatch of Shell subclasses with a main method
*
Expand Down Expand Up @@ -600,6 +603,7 @@ function testDispatchShellWithMain() {
$result = $Dispatcher->dispatch();
$this->assertFalse($result);
}

/**
* Verify correct dispatch of Shell subclasses without a main method
*
Expand Down Expand Up @@ -671,6 +675,7 @@ function testDispatchShellWithoutMain() {
$result = $Dispatcher->dispatch();
$this->assertFalse($result);
}

/**
* Verify correct dispatch of custom classes with a main method
*
Expand Down Expand Up @@ -750,6 +755,7 @@ function testDispatchNotAShellWithMain() {
$result = $Dispatcher->dispatch();
$this->assertFalse($result);
}

/**
* Verify correct dispatch of custom classes without a main method
*
Expand Down Expand Up @@ -819,6 +825,7 @@ function testDispatchNotAShellWithoutMain() {
$result = $Dispatcher->dispatch();
$this->assertFalse($result);
}

/**
* Verify that a task is called instead of the shell if the first arg equals
* the name of the task
Expand Down Expand Up @@ -867,6 +874,7 @@ function testDispatchTask() {
$result = $Dispatcher->dispatch();
$this->assertTrue($result);
}

/**
* Verify shifting of arguments
*
Expand Down Expand Up @@ -906,39 +914,34 @@ function testShiftArgs() {
function testHelpCommand() {
$Dispatcher =& new TestShellDispatcher();

$expected = "/ CORE(\\\|\/)tests(\\\|\/)test_app(\\\|\/)plugins(\\\|\/)test_plugin(\\\|\/)vendors(\\\|\/)shells:";
$expected .= "\n\t example";
$expected .= "\n/";
$expected = "/example \[.*TestPlugin, TestPluginTwo.*\]/";
$this->assertPattern($expected, $Dispatcher->stdout);

$expected = "/welcome \[.*TestPluginTwo.*\]/";
$this->assertPattern($expected, $Dispatcher->stdout);

$expected = "/acl \[.*CORE.*\]/";
$this->assertPattern($expected, $Dispatcher->stdout);

$expected = "/api \[.*CORE.*\]/";
$this->assertPattern($expected, $Dispatcher->stdout);

$expected = "/bake \[.*CORE.*\]/";
$this->assertPattern($expected, $Dispatcher->stdout);

$expected = "/ CORE(\\\|\/)tests(\\\|\/)test_app(\\\|\/)plugins(\\\|\/)test_plugin_two(\\\|\/)vendors(\\\|\/)shells:";
$expected .= "\n\t example";
$expected .= "\n\t welcome";
$expected .= "\n/";
$expected = "/console \[.*CORE.*\]/";
$this->assertPattern($expected, $Dispatcher->stdout);

$expected = "/ APP(\\\|\/)vendors(\\\|\/)shells:";
$expected .= "\n/";
$expected = "/i18n \[.*CORE.*\]/";
$this->assertPattern($expected, $Dispatcher->stdout);

$expected = "/ ROOT(\\\|\/)vendors(\\\|\/)shells:";
$expected .= "\n/";
$expected = "/schema \[.*CORE.*\]/";
$this->assertPattern($expected, $Dispatcher->stdout);

$expected = "/ CORE(\\\|\/)console(\\\|\/)libs:";
$expected .= "\n\t acl";
$expected .= "\n\t api";
$expected .= "\n\t bake";
$expected .= "\n\t console";
$expected .= "\n\t i18n";
$expected .= "\n\t schema";
$expected .= "\n\t testsuite";
$expected .= "\n/";
$expected = "/testsuite \[.*CORE.*\]/";
$this->assertPattern($expected, $Dispatcher->stdout);

$expected = "/ CORE(\\\|\/)tests(\\\|\/)test_app(\\\|\/)vendors(\\\|\/)shells:";
$expected .= "\n\t sample";
$expected .= "\n/";
$expected = "/sample \[.*test_app.*\]/";
$this->assertPattern($expected, $Dispatcher->stdout);
}
}
Expand Down
Empty file removed vendors/css/empty
Empty file.
Empty file removed vendors/js/empty
Empty file.

0 comments on commit b53c733

Please sign in to comment.