This commit is contained in:
AD7six 2009-08-06 23:40:57 +02:00 committed by mark_story
parent 31d136ca67
commit b53c7339c4
5 changed files with 78 additions and 43 deletions

View file

View file

@ -27,6 +27,7 @@
if (!defined('E_DEPRECATED')) { if (!defined('E_DEPRECATED')) {
define('E_DEPRECATED', 8192); define('E_DEPRECATED', 8192);
} }
/** /**
* Shell dispatcher * Shell dispatcher
* *
@ -402,6 +403,7 @@ class ShellDispatcher {
$this->stderr($title . "\n" . $message . "\n"); $this->stderr($title . "\n" . $message . "\n");
return false; return false;
} }
/** /**
* Get shell to use, either plugin shell or application shell * Get shell to use, either plugin shell or application shell
* *
@ -606,28 +608,58 @@ class ShellDispatcher {
$this->stdout("Example: -app relative/path/to/myapp or -app /absolute/path/to/myapp"); $this->stdout("Example: -app relative/path/to/myapp or -app /absolute/path/to/myapp");
$this->stdout("\nAvailable Shells:"); $this->stdout("\nAvailable Shells:");
$_shells = array(); $shellList = array();
foreach ($this->shellPaths as $path) { foreach ($this->shellPaths as $path) {
if (is_dir($path)) { if (!is_dir($path)) {
$shells = App::objects('file', $path); continue;
$path = str_replace(CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS, 'CORE' . DS, $path); }
$path = str_replace(APP, 'APP' . DS, $path); $shells = App::objects('file', $path);
$path = str_replace(ROOT, 'ROOT', $path); if (empty($shells)) {
$path = rtrim($path, DS); continue;
$this->stdout("\n " . $path . ":"); }
if (empty($shells)) { if (preg_match('@plugins[\\\/]([^\\\/]*)@', $path, $matches)) {
$this->stdout("\t - none"); $type = Inflector::camelize($matches[1]);
} else { } elseif (preg_match('@([^\\\/]*)[\\\/]vendors[\\\/]@', $path, $matches)) {
sort($shells); $type = $matches[1];
foreach ($shells as $shell) { } elseif (strpos($path, CAKE_CORE_INCLUDE_PATH . DS . 'cake') === 0) {
$type = 'CORE';
if ($shell !== 'shell.php') { } else {
$this->stdout("\t " . str_replace('.php', '', $shell)); $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("\nTo run a command, type 'cake shell_name [args]'");
$this->stdout("To get help on a specific command, type 'cake shell_name help'"); $this->stdout("To get help on a specific command, type 'cake shell_name help'");
} }

View file

@ -36,8 +36,8 @@ if (!class_exists('ShellDispatcher')) {
ob_end_clean(); ob_end_clean();
} }
require_once CONSOLE_LIBS . 'shell.php'; require_once CONSOLE_LIBS . 'shell.php';
/** /**
* TestShellDispatcher class * TestShellDispatcher class
* *
@ -85,6 +85,7 @@ class TestShellDispatcher extends ShellDispatcher {
* @access public * @access public
*/ */
var $TestShell; var $TestShell;
/** /**
* _initEnvironment method * _initEnvironment method
* *
@ -138,6 +139,7 @@ class TestShellDispatcher extends ShellDispatcher {
$this->stopped = 'Stopped with status: ' . $status; $this->stopped = 'Stopped with status: ' . $status;
return $status; return $status;
} }
/** /**
* getShell * getShell
* *
@ -148,6 +150,7 @@ class TestShellDispatcher extends ShellDispatcher {
function getShell($plugin = null) { function getShell($plugin = null) {
return $this->_getShell($plugin); return $this->_getShell($plugin);
} }
/** /**
* _getShell * _getShell
* *
@ -439,7 +442,6 @@ class ShellDispatcherTest extends CakeTestCase {
$Dispatcher->parseParams($params); $Dispatcher->parseParams($params);
$this->assertEqual($expected, $Dispatcher->params); $this->assertEqual($expected, $Dispatcher->params);
$params = array( $params = array(
'cake.php', 'cake.php',
'-working', '-working',
@ -510,6 +512,7 @@ class ShellDispatcherTest extends CakeTestCase {
$result = $Dispatcher->getShell('test_plugin'); $result = $Dispatcher->getShell('test_plugin');
$this->assertIsA($result, 'ExampleShell'); $this->assertIsA($result, 'ExampleShell');
} }
/** /**
* Verify correct dispatch of Shell subclasses with a main method * Verify correct dispatch of Shell subclasses with a main method
* *
@ -600,6 +603,7 @@ class ShellDispatcherTest extends CakeTestCase {
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
$this->assertFalse($result); $this->assertFalse($result);
} }
/** /**
* Verify correct dispatch of Shell subclasses without a main method * Verify correct dispatch of Shell subclasses without a main method
* *
@ -671,6 +675,7 @@ class ShellDispatcherTest extends CakeTestCase {
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
$this->assertFalse($result); $this->assertFalse($result);
} }
/** /**
* Verify correct dispatch of custom classes with a main method * Verify correct dispatch of custom classes with a main method
* *
@ -750,6 +755,7 @@ class ShellDispatcherTest extends CakeTestCase {
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
$this->assertFalse($result); $this->assertFalse($result);
} }
/** /**
* Verify correct dispatch of custom classes without a main method * Verify correct dispatch of custom classes without a main method
* *
@ -819,6 +825,7 @@ class ShellDispatcherTest extends CakeTestCase {
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
$this->assertFalse($result); $this->assertFalse($result);
} }
/** /**
* Verify that a task is called instead of the shell if the first arg equals * Verify that a task is called instead of the shell if the first arg equals
* the name of the task * the name of the task
@ -867,6 +874,7 @@ class ShellDispatcherTest extends CakeTestCase {
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
$this->assertTrue($result); $this->assertTrue($result);
} }
/** /**
* Verify shifting of arguments * Verify shifting of arguments
* *
@ -906,39 +914,34 @@ class ShellDispatcherTest extends CakeTestCase {
function testHelpCommand() { function testHelpCommand() {
$Dispatcher =& new TestShellDispatcher(); $Dispatcher =& new TestShellDispatcher();
$expected = "/ CORE(\\\|\/)tests(\\\|\/)test_app(\\\|\/)plugins(\\\|\/)test_plugin(\\\|\/)vendors(\\\|\/)shells:"; $expected = "/example \[.*TestPlugin, TestPluginTwo.*\]/";
$expected .= "\n\t example";
$expected .= "\n/";
$this->assertPattern($expected, $Dispatcher->stdout); $this->assertPattern($expected, $Dispatcher->stdout);
$expected = "/ CORE(\\\|\/)tests(\\\|\/)test_app(\\\|\/)plugins(\\\|\/)test_plugin_two(\\\|\/)vendors(\\\|\/)shells:"; $expected = "/welcome \[.*TestPluginTwo.*\]/";
$expected .= "\n\t example";
$expected .= "\n\t welcome";
$expected .= "\n/";
$this->assertPattern($expected, $Dispatcher->stdout); $this->assertPattern($expected, $Dispatcher->stdout);
$expected = "/ APP(\\\|\/)vendors(\\\|\/)shells:"; $expected = "/acl \[.*CORE.*\]/";
$expected .= "\n/";
$this->assertPattern($expected, $Dispatcher->stdout); $this->assertPattern($expected, $Dispatcher->stdout);
$expected = "/ ROOT(\\\|\/)vendors(\\\|\/)shells:"; $expected = "/api \[.*CORE.*\]/";
$expected .= "\n/";
$this->assertPattern($expected, $Dispatcher->stdout); $this->assertPattern($expected, $Dispatcher->stdout);
$expected = "/ CORE(\\\|\/)console(\\\|\/)libs:"; $expected = "/bake \[.*CORE.*\]/";
$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/";
$this->assertPattern($expected, $Dispatcher->stdout); $this->assertPattern($expected, $Dispatcher->stdout);
$expected = "/ CORE(\\\|\/)tests(\\\|\/)test_app(\\\|\/)vendors(\\\|\/)shells:"; $expected = "/console \[.*CORE.*\]/";
$expected .= "\n\t sample"; $this->assertPattern($expected, $Dispatcher->stdout);
$expected .= "\n/";
$expected = "/i18n \[.*CORE.*\]/";
$this->assertPattern($expected, $Dispatcher->stdout);
$expected = "/schema \[.*CORE.*\]/";
$this->assertPattern($expected, $Dispatcher->stdout);
$expected = "/testsuite \[.*CORE.*\]/";
$this->assertPattern($expected, $Dispatcher->stdout);
$expected = "/sample \[.*test_app.*\]/";
$this->assertPattern($expected, $Dispatcher->stdout); $this->assertPattern($expected, $Dispatcher->stdout);
} }
} }

0
vendors/css/empty vendored
View file

0
vendors/js/empty vendored
View file