Permalink
Browse files

Removing support for string input in Shell::nl().

Updating Shell::out() and Shell::err() parameter usage.
Updating method to always return strings, renaming parameter.
Updating docblocks.
Updating test.
  • Loading branch information...
1 parent 78e01cd commit 5ac7361a766af6f61788de2f21408eeae39a2166 @davidpersson davidpersson committed Sep 21, 2009
Showing with 19 additions and 22 deletions.
  1. +14 −21 cake/console/libs/shell.php
  2. +5 −1 cake/tests/cases/console/libs/shell.test.php
@@ -366,60 +366,53 @@ function in($prompt, $options = null, $default = null) {
* Outputs a single or multiple messages to stdout.
*
* @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, $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.
*
* @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, $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
@@ -236,6 +236,7 @@ function testOut() {
$this->Shell->Dispatch->expectAt(2, 'stdout', array("Just\na\ntest\n\n", false));
$this->Shell->out(array('Just', 'a', 'test'), 2);
}
+
/**
* testErr method
*
@@ -252,6 +253,7 @@ function testErr() {
$this->Shell->Dispatch->expectAt(2, 'stderr', array("Just\na\ntest\n\n"));
$this->Shell->err(array('Just', 'a', 'test'), 2);
}
+
/**
* testNl
*
@@ -264,8 +266,8 @@ function testNl() {
$this->assertEqual($this->Shell->nl(false), "");
$this->assertEqual($this->Shell->nl(2), "\n\n");
$this->assertEqual($this->Shell->nl(1), "\n");
- $this->assertEqual($this->Shell->nl("custom"), "custom\n");
}
+
/**
* testHr
*
@@ -290,6 +292,7 @@ function testHr() {
$this->Shell->Dispatch->expectAt(5, 'stdout', array("\n\n", false));
$this->Shell->hr(2);
}
+
/**
* testError
*
@@ -308,6 +311,7 @@ function testError() {
$this->Shell->error('Foo Not Found', 'Searched all...');
$this->assertIdentical($this->Shell->stopped, 1);
}
+
/**
* testLoadTasks method
*

0 comments on commit 5ac7361

Please sign in to comment.