Permalink
Browse files

Merge branch '1.3-router' into 1.3-misc

  • Loading branch information...
2 parents 4094f0a + 893e177 commit 58ec259714f46b7bc4aa57c4379e7e7abdfbdefe @markstory markstory committed Sep 30, 2009
@@ -229,7 +229,7 @@ function help() {
$this->out("\n\tbake model\n\t\tbakes a model. run 'bake model help' for more info");
$this->out("\n\tbake view\n\t\tbakes views. run 'bake view help' for more info");
$this->out("\n\tbake controller\n\t\tbakes a controller. run 'bake controller help' for more info");
- $this->out("");
+ $this->out();
}
}
@@ -238,7 +238,7 @@ function main($command = null) {
$this->out("\t$field2: $value2");
}
- $this->out("");
+ $this->out();
} else {
$this->out("\t$field: $value");
}
@@ -253,7 +253,7 @@ function main($command = null) {
$this->out("\t$field2: $value2");
}
- $this->out("");
+ $this->out();
} else {
$this->out("\t$field: $value");
}
@@ -128,7 +128,7 @@ function help() {
$this->out(__('usage:', true));
$this->out(' cake i18n help');
$this->out(' cake i18n initdb [-datasource custom]');
- $this->out('');
+ $this->out();
$this->hr();
$this->Extract->help();
@@ -372,7 +372,7 @@ function __update(&$Schema, $table = null) {
$this->out("\n" . __('The following statements will run.', true));
$this->out(array_map('trim', $contents));
if ('y' == $this->in(__('Are you sure you want to alter the tables?', true), array('y', 'n'), 'n')) {
- $this->out('');
+ $this->out();
$this->out(__('Updating Database...', true));
$this->__run($contents, 'update', $Schema);
}
@@ -448,7 +448,7 @@ function help() {
$this->out("\n\tschema dump <filename>\n\t\tDump database sql based on schema file to <filename>. \n\t\tIf <filename> is write, schema dump will be written to a file\n\t\tthat has the same name as the app directory.");
$this->out("\n\tschema run create <schema> <table>\n\t\tDrop and create tables based on schema file\n\t\toptional <schema> arg for selecting schema name\n\t\toptional <table> arg for creating only one table\n\t\tpass the -s param with a number to use a snapshot\n\t\tTo see the changes, perform a dry run with the -dry param");
$this->out("\n\tschema run update <schema> <table>\n\t\talter tables based on schema file\n\t\toptional <schema> arg for selecting schema name.\n\t\toptional <table> arg for altering only one table.\n\t\tTo use a snapshot, pass the -s param with the snapshot number\n\t\tTo see the changes, perform a dry run with the -dry param");
- $this->out("");
+ $this->out();
$this->_stop();
}
}
@@ -145,6 +145,7 @@ class Shell extends Object {
*/
function __construct(&$dispatch) {
$vars = array('params', 'args', 'shell', 'shellCommand' => 'command');
+
foreach ($vars as $key => $var) {
if (is_string($key)) {
$this->{$var} =& $dispatch->{$key};
@@ -205,8 +206,9 @@ function startup() {
*/
function _welcome() {
$this->Dispatch->clear();
- $this->out("\nWelcome to CakePHP v" . Configure::version() . " Console");
- $this->out("---------------------------------------------------------------");
+ $this->out();
+ $this->out('Welcome to CakePHP v' . Configure::version() . ' Console');
+ $this->hr();
$this->out('App : '. $this->params['app']);
$this->out('Path: '. $this->params['working']);
$this->hr();
@@ -224,8 +226,8 @@ function _loadDbConfig() {
$this->DbConfig =& new DATABASE_CONFIG();
return true;
}
- $this->err('Database config could not be loaded');
- $this->out('Run \'bake\' to create the database configuration');
+ $this->err('Database config could not be loaded.');
+ $this->out('Run `bake` to create the database configuration.');
return false;
}
@@ -296,7 +298,7 @@ function loadTasks() {
if (!class_exists($taskClass)) {
foreach ($this->Dispatch->shellPaths as $path) {
- $taskPath = $path . 'tasks' . DS . $task.'.php';
+ $taskPath = $path . 'tasks' . DS . $task . '.php';
if (file_exists($taskPath)) {
require_once $taskPath;
break;
@@ -320,7 +322,7 @@ function loadTasks() {
}
if (!isset($this->{$taskName})) {
- $this->err("Task '" . $taskName . "' could not be loaded");
+ $this->err("Task `{$taskName}` could not be loaded");
$this->_stop();
}
}
@@ -363,63 +365,58 @@ function in($prompt, $options = null, $default = null) {
}
/**
- * Outputs a single or multiple messages to stdout.
+ * Outputs a single or multiple messages to stdout. If no parameters
+ * are passed outputs just a newline.
*
* @param mixed $message A string or a an array of strings to output
- * @param mixed $after Appended to message, if true a newline is used
+ * @param integer $newlines Number of newlines to append
* @access public
*/
- function out($message, $after = true) {
+ function out($message = null, $newlines = 1) {
if (is_array($message)) {
$message = implode($this->nl(), $message);
}
- $this->Dispatch->stdout($message . $this->nl($after), false);
+ $this->Dispatch->stdout($message . $this->nl($newlines), false);
}
/**
- * Outputs a single or multiple error messages to stderr.
+ * Outputs a single or multiple error messages to stderr. If no parameters
+ * are passed outputs just a newline.
*
* @param mixed $message A string or a an array of strings to output
- * @param mixed $after Appended to message, if true a newline is used
+ * @param integer $newlines Number of newlines to append
* @access public
*/
- function err($message, $after = true) {
+ function err($message = null, $newlines = 1) {
if (is_array($message)) {
$message = implode($this->nl(), $message);
}
- $this->Dispatch->stderr($message . $this->nl($after));
+ $this->Dispatch->stderr($message . $this->nl($newlines));
}
/**
* Returns a single or multiple linefeeds sequences.
*
- * @param mixed $format If true returns a linefeed sequence, if false null,
- * if a string is given that is returned,
- * if an integer is given it is used as a multiplier to return multiple linefeed sequences
+ * @param integer $multiplier Number of times the linefeed sequence should be repeated
* @access public
* @return string
*/
- function nl($format = true) {
- if (is_string($format)) {
- return $format . "\n";
- }
- if (is_int($format)) {
- return str_repeat("\n", $format);
- }
- return $format ? "\n" : null;
+ function nl($multiplier = 1) {
+ return str_repeat("\n", $multiplier);
}
/**
* Outputs a series of minus characters to the standard output, acts as a visual separator.
*
- * @param mixed $surround If true, the outputs gets surrounded by newlines.
+ * @param integer $newlines Number of newlines to pre- and append
* @access public
*/
- function hr($surround = false) {
- $this->out(null, $surround);
+ function hr($newlines = 0) {
+ $this->out(null, $newlines);
$this->out('---------------------------------------------------------------');
- $this->out(null, $surround);
+ $this->out(null, $newlines);
}
+
/**
* Displays a formatted error message
* and exits the application with status code 1
@@ -449,7 +446,11 @@ function _checkArgs($expectedNum, $command = null) {
$command = $this->command;
}
if (count($this->args) < $expectedNum) {
- $this->error("Wrong number of parameters: ".count($this->args), "Expected: {$expectedNum}\nPlease type 'cake {$this->shell} help' for help on usage of the {$this->name} {$command}");
+ $message[] = "Got: " . count($this->args);
+ $message[] = "Expected: {$expectedNum}";
+ $message[] = "Please type `cake {$this->shell} help` for help";
+ $message[] = "on usage of the {$this->name} {$command}.";
+ $this->error('Wrong number of parameters', $message);
}
}
@@ -461,16 +462,21 @@ function _checkArgs($expectedNum, $command = null) {
* @return boolean Success
* @access public
*/
- function createFile ($path, $contents) {
+ function createFile($path, $contents) {
$path = str_replace(DS . DS, DS, $path);
- $this->out("\n" . sprintf(__("Creating file %s", true), $path));
+
+ $this->out();
+ $this->out(sprintf(__("Creating file %s", true), $path));
+
if (is_file($path) && $this->interactive === true) {
- $key = $this->in(__("File exists, overwrite?", true). " {$path}", array('y', 'n', 'q'), 'n');
+ $prompt = sprintf(__('File `%s` exists, overwrite?', true), $path);
+ $key = $this->in($prompt, array('y', 'n', 'q'), 'n');
+
if (strtolower($key) == 'q') {
- $this->out(__("Quitting.", true) ."\n");
- exit;
+ $this->out(__('Quitting.', true), 2);
+ $this->_stop();
} elseif (strtolower($key) != 'y') {
- $this->out(__("Skip", true) ." {$path}\n");
+ $this->out(sprintf(__('Skip `%s`', true), $path), 2);
return false;
}
}
@@ -481,10 +487,10 @@ function createFile ($path, $contents) {
if ($File = new File($path, true)) {
$data = $File->prepare($contents);
$File->write($data);
- $this->out(__("Wrote", true) ." {$path}");
+ $this->out(sprintf(__('Wrote `%s`', true), $path));
return true;
} else {
- $this->err(__("Error! Could not write to", true)." {$path}.\n");
+ $this->err(sprintf(__('Could not write to `%s`.', true), $path), 2);
return false;
}
}
@@ -496,7 +502,8 @@ function createFile ($path, $contents) {
*/
function help() {
if ($this->command != null) {
- $this->err("Unknown {$this->name} command '$this->command'.\nFor usage, try 'cake {$this->shell} help'.\n\n");
+ $this->err("Unknown {$this->name} command `{$this->command}`.");
+ $this->err("For usage, try `cake {$this->shell} help`.", 2);
} else {
$this->Dispatch->help();
}
@@ -512,11 +519,13 @@ function _checkUnitTest() {
if (App::import('vendor', 'simpletest' . DS . 'simpletest')) {
return true;
}
- $unitTest = $this->in('SimpleTest is not installed. Do you want to bake unit test files anyway?', array('y','n'), 'y');
+ $prompt = 'SimpleTest is not installed. Do you want to bake unit test files anyway?';
+ $unitTest = $this->in($prompt, array('y','n'), 'y');
$result = strtolower($unitTest) == 'y' || strtolower($unitTest) == 'yes';
if ($result) {
- $this->out("\nYou can download SimpleTest from http://simpletest.org", true);
+ $this->out();
+ $this->out('You can download SimpleTest from http://simpletest.org');
}
return $result;
}
@@ -575,7 +584,7 @@ function _modelName($name) {
* @access protected
*/
function _modelKey($name) {
- return Inflector::underscore(Inflector::singularize($name)).'_id';
+ return Inflector::underscore(Inflector::singularize($name)) . '_id';
}
/**
@@ -586,8 +595,7 @@ function _modelKey($name) {
* @access protected
*/
function _modelNameFromKey($key) {
- $name = str_replace('_id', '',$key);
- return Inflector::camelize($name);
+ return Inflector::camelize(str_replace('_id', '', $key));
}
/**
@@ -643,6 +651,7 @@ function _pluralHumanName($name) {
function _pluginPath($pluginName) {
$pluginPaths = App::path('plugins');
$pluginDirName = Inflector::underscore($pluginName);
+
foreach ($pluginPaths as $path) {
if (is_dir($path . $pluginDirName)) {
return $path . $pluginDirName . DS ;
@@ -222,7 +222,7 @@ function __interactive() {
* @return void
**/
function confirmController($controllerName, $useDynamicScaffold, $helpers, $components) {
- $this->out('');
+ $this->out();
$this->hr();
$this->out(__('The following controller will be created:', true));
$this->hr();
@@ -457,27 +457,27 @@ function help() {
$this->out("Usage: cake bake controller <arg1> <arg2>...");
$this->hr();
$this->out('Commands:');
- $this->out('');
+ $this->out();
$this->out("controller <name>");
$this->out("\tbakes controller with var \$scaffold");
- $this->out('');
+ $this->out();
$this->out("controller <name> public");
$this->out("\tbakes controller with basic crud actions");
$this->out("\t(index, view, add, edit, delete)");
- $this->out('');
+ $this->out();
$this->out("controller <name> admin");
$this->out("\tbakes a controller with basic crud actions for");
$this->out("\tConfigure::read('Routing.admin') methods.");
- $this->out('');
+ $this->out();
$this->out("controller <name> public admin");
$this->out("\tbakes a controller with basic crud actions for");
$this->out("\tConfigure::read('Routing.admin') and non admin methods.");
$this->out("\t(index, view, add, edit, delete,");
$this->out("\tadmin_index, admin_view, admin_edit, admin_add, admin_delete)");
- $this->out('');
+ $this->out();
$this->out("controller all");
$this->out("\tbakes all controllers with CRUD methods.");
- $this->out("");
+ $this->out();
$this->_stop();
}
}
@@ -204,7 +204,7 @@ function __interactive() {
function __verify($config) {
$config = array_merge($this->__defaultConfig, $config);
extract($config);
- $this->out('');
+ $this->out();
$this->hr();
$this->out('The following database configuration will be created:');
$this->hr();
Oops, something went wrong.

0 comments on commit 58ec259

Please sign in to comment.