Permalink
Browse files

Deal with EOLs that are on a line by them self so columnWrap doesn't …

…sallow them up. pear2/PEAR2_Console_CommandLine#2
  • Loading branch information...
1 parent eff47cc commit 223be45c82f12a68a9c6a7db9fd03892811ace5b @helgi committed Jul 23, 2011
Showing with 87 additions and 2 deletions.
  1. +8 −2 src/Console/CommandLine/Renderer/Default.php
  2. +79 −0 tests/console_commandline_bug18682.phpt
@@ -404,12 +404,18 @@ protected function columnWrap($text, $cw)
{
$tokens = explode("\n", $this->wrap($text));
$ret = $tokens[0];
- $chunks = $this->wrap(trim(substr($text, strlen($ret))),
- $this->line_width - $cw);
+ $text = trim(substr($text, strlen($ret)));
+ if (empty($text)) {
+ return $ret;
+ }
+
+ $chunks = $this->wrap($text, $this->line_width - $cw);
$tokens = explode("\n", $chunks);
foreach ($tokens as $token) {
if (!empty($token)) {
$ret .= "\n" . str_repeat(' ', $cw) . $token;
+ } else {
+ $ret .= "\n";
}
}
return $ret;
@@ -0,0 +1,79 @@
+--TEST--
+Test for bug #18682: columnWrap() in Default Renderer eats up lines with only a EOL.
+--ARGS--
+cmd1 --help 2>&1
+--FILE--
+<?php
+
+require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'tests.inc.php';
+
+class Renderer extends Console_CommandLine_Renderer_Default {
+ protected function description() {
+ return $this->columnWrap($this->parser->description, 2);
+ }
+}
+
+$parser = new Console_CommandLine();
+$parser->accept(new Renderer);
+$parser->renderer->line_width = 75;
+$parser->addCommand('cmd1', array(
+ 'description' => '
+Installs listed packages.
+
+local package.xml example:
+php pyrus.phar install package.xml
+
+local package archive example:
+php pyrus.phar install PackageName-1.2.0.tar
+
+remote package archive example:
+php pyrus.phar install http://www.example.com/PackageName-1.2.0.tgz
+
+Examples of an abstract package:
+php pyrus.phar install PackageName
+ installs PackageName from the default channel with stability preferred_state
+php pyrus.phar pear/PackageName
+ installs PackageName from the pear.php.net channel with stability preferred_state
+php pyrus.phar install channel://doc.php.net/PackageName
+ installs PackageName from the doc.php.net channel with stability preferred_state
+php pyrus.phar install PackageName-beta
+ installs PackageName from the default channel, beta or stable stability
+php pyrus.phar install PackageName-1.2.0
+ installs PackageName from the default channel, version 1.2.0'
+));
+$parser->parse();
+
+?>
+--EXPECTF--
+ Installs listed packages.
+
+ local package.xml example:
+ php pyrus.phar install package.xml
+
+ local package archive example:
+ php pyrus.phar install PackageName-1.2.0.tar
+
+ remote package archive example:
+ php pyrus.phar install http://www.example.com/PackageName-1.2.0.tgz
+
+ Examples of an abstract package:
+ php pyrus.phar install PackageName
+ installs PackageName from the default channel with stability
+ preferred_state
+ php pyrus.phar pear/PackageName
+ installs PackageName from the pear.php.net channel with stability
+ preferred_state
+ php pyrus.phar install channel://doc.php.net/PackageName
+ installs PackageName from the doc.php.net channel with stability
+ preferred_state
+ php pyrus.phar install PackageName-beta
+ installs PackageName from the default channel, beta or stable stability
+ php pyrus.phar install PackageName-1.2.0
+ installs PackageName from the default channel, version 1.2.0
+
+Usage:
+ /Users/helgi/projects/projects/php/pear/packages/Console_CommandLine/trunk/tests/console_commandline_bug18682.php
+ [options] cmd1 [options]
+
+Options:
+ -h, --help show this help message and exit

0 comments on commit 223be45

Please sign in to comment.