Merge branch 'fitorec-console' into 2.2

Closes #GH-682
This commit is contained in:
mark_story 2012-06-10 21:57:38 -04:00
commit fddcdd622d
4 changed files with 23 additions and 14 deletions

View file

@ -397,11 +397,12 @@ class ControllerTask extends BakeTask {
if ($this->interactive == true) { if ($this->interactive == true) {
$this->out(__d('cake_console', 'Possible Controllers based on your current database:')); $this->out(__d('cake_console', 'Possible Controllers based on your current database:'));
$this->hr();
$this->_controllerNames = array(); $this->_controllerNames = array();
$count = count($this->__tables); $count = count($this->__tables);
for ($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
$this->_controllerNames[] = $this->_controllerName($this->_modelName($this->__tables[$i])); $this->_controllerNames[] = $this->_controllerName($this->_modelName($this->__tables[$i]));
$this->out($i + 1 . ". " . $this->_controllerNames[$i]); $this->out(sprintf("%2d. %s", $i + 1, $this->_controllerNames[$i]));
} }
return $this->_controllerNames; return $this->_controllerNames;
} }

View file

@ -169,8 +169,9 @@ class ModelTask extends BakeTask {
$valid = false; $valid = false;
$max = count($options); $max = count($options);
while (!$valid) { while (!$valid) {
$len = strlen(count($options) + 1);
foreach ($options as $i => $option) { foreach ($options as $i => $option) {
$this->out($i + 1 . '. ' . $option); $this->out(sprintf("%${len}d. %s", $i + 1, $option));
} }
if (empty($prompt)) { if (empty($prompt)) {
$prompt = __d('cake_console', 'Make a selection from the choices above'); $prompt = __d('cake_console', 'Make a selection from the choices above');
@ -403,20 +404,24 @@ class ModelTask extends BakeTask {
while ($anotherValidator == 'y') { while ($anotherValidator == 'y') {
if ($this->interactive) { if ($this->interactive) {
$this->out(); $this->out();
$this->out(__d('cake_console', 'Field: %s', $fieldName)); $this->out(__d('cake_console', 'Field: <info>%s</info>', $fieldName));
$this->out(__d('cake_console', 'Type: %s', $metaData['type'])); $this->out(__d('cake_console', 'Type: <info>%s</info>', $metaData['type']));
$this->hr(); $this->hr();
$this->out(__d('cake_console', 'Please select one of the following validation options:')); $this->out(__d('cake_console', 'Please select one of the following validation options:'));
$this->hr(); $this->hr();
$optionText = '';
for ($i = 1, $m = $defaultChoice / 2; $i < $m; $i++) {
$line = sprintf("%2d. %s", $i, $this->_validations[$i]);
$optionText .= $line . str_repeat(" ", 31 - strlen($line));
$optionText .= sprintf("%2d. %s", $m + $i, $this->_validations[$m + $i]);
}
$this->out($optionText);
$this->out(__d('cake_console', "%s - Do not do any validation on this field.", $defaultChoice));
$this->hr();
} }
$prompt = ''; $prompt = __d('cake_console', "... or enter in a valid regex validation string.\n");
for ($i = 1; $i < $defaultChoice; $i++) {
$prompt .= $i . ' - ' . $this->_validations[$i] . "\n";
}
$prompt .= __d('cake_console', "%s - Do not do any validation on this field.\n", $defaultChoice);
$prompt .= __d('cake_console', "... or enter in a valid regex validation string.\n");
$methods = array_flip($this->_validations); $methods = array_flip($this->_validations);
$guess = $defaultChoice; $guess = $defaultChoice;
if ($metaData['null'] != 1 && !in_array($fieldName, array($primaryKey, 'created', 'modified', 'updated'))) { if ($metaData['null'] != 1 && !in_array($fieldName, array($primaryKey, 'created', 'modified', 'updated'))) {
@ -436,6 +441,8 @@ class ModelTask extends BakeTask {
$guess = $methods['date']; $guess = $methods['date'];
} elseif ($metaData['type'] == 'time') { } elseif ($metaData['type'] == 'time') {
$guess = $methods['time']; $guess = $methods['time'];
} elseif ($metaData['type'] == 'datetime') {
$guess = $methods['datetime'];
} elseif ($metaData['type'] == 'inet') { } elseif ($metaData['type'] == 'inet') {
$guess = $methods['ip']; $guess = $methods['ip'];
} }
@ -842,8 +849,9 @@ class ModelTask extends BakeTask {
} }
if ($this->interactive === true) { if ($this->interactive === true) {
$this->out(__d('cake_console', 'Possible Models based on your current database:')); $this->out(__d('cake_console', 'Possible Models based on your current database:'));
$len = strlen($count + 1);
for ($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
$this->out($i + 1 . ". " . $this->_modelNames[$i]); $this->out(sprintf("%${len}d. %s", $i + 1, $this->_modelNames[$i]));
} }
} }
return $this->_tables; return $this->_tables;

View file

@ -137,7 +137,7 @@ class ConsoleOutput {
'debug' => array('text' => 'yellow'), 'debug' => array('text' => 'yellow'),
'success' => array('text' => 'green'), 'success' => array('text' => 'green'),
'comment' => array('text' => 'blue'), 'comment' => array('text' => 'blue'),
'question' => array('text' => "magenta"), 'question' => array('text' => 'magenta'),
); );
/** /**

View file

@ -335,7 +335,7 @@ class ModelTaskTest extends CakeTestCase {
$this->Task->expects($this->any())->method('in') $this->Task->expects($this->any())->method('in')
->will($this->onConsecutiveCalls('999999', '23', 'n')); ->will($this->onConsecutiveCalls('999999', '23', 'n'));
$this->Task->expects($this->at(7))->method('out') $this->Task->expects($this->at(10))->method('out')
->with($this->stringContains('make a valid')); ->with($this->stringContains('make a valid'));
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false)); $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));