Skip to content

Commit

Permalink
Deal with EOLs that are on a line by them self so columnWrap doesn't …
Browse files Browse the repository at this point in the history
…sallow them up. pear2/PEAR2_Console_CommandLine#2
  • Loading branch information
helgi committed Jul 23, 2011
1 parent eff47cc commit 223be45
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Console/CommandLine/Renderer/Default.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
79 changes: 79 additions & 0 deletions tests/console_commandline_bug18682.phpt
Original file line number Diff line number Diff line change
@@ -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.