diff options
-rw-r--r-- | Console_CommandLine-bug18682.patch | 243 | ||||
-rw-r--r-- | Console_CommandLine-bug19683.patch | 25 | ||||
-rw-r--r-- | php-pear-Console-CommandLine.spec | 27 |
3 files changed, 288 insertions, 7 deletions
diff --git a/Console_CommandLine-bug18682.patch b/Console_CommandLine-bug18682.patch new file mode 100644 index 0000000..81537be --- /dev/null +++ b/Console_CommandLine-bug18682.patch @@ -0,0 +1,243 @@ +From 987dd5793550a1cb8930bb06cf8f384bdbbbf2a4 Mon Sep 17 00:00:00 2001 +From: David Jean Louis <izimobil@gmail.com> +Date: Thu, 25 Oct 2012 10:13:42 +0200 +Subject: [PATCH] * Fixed bug #18682 (columnWrap() in Default Renderer eats up + lines with only a EOL) [izi, thanks Helgi] * Fixed bug + #18703 (No way to override reading of stdin with -) [izi, + thanks Gwynne Raskind] * Fixed unit tests [izi] + +--- + Console/CommandLine.php | 18 +++++-- + Console/CommandLine/Renderer/Default.php | 10 +++- + package.xml | 30 ++++++++--- + tests/console_commandline_addargument.phpt | 20 +++++-- + tests/console_commandline_bug18682.phpt | 79 ++++++++++++++++++++++++++++ + 5 files changed, 142 insertions(+), 15 deletions(-) + create mode 100644 tests/console_commandline_bug18682.phpt + +diff --git a/Console/CommandLine.php b/Console/CommandLine.php +index c1b01e1..0ccfb7c 100644 +--- a/Console/CommandLine.php ++++ b/Console/CommandLine.php +@@ -176,6 +176,15 @@ class Console_CommandLine + */ + public $force_options_defaults = false; + ++ ++ /** ++ * Boolean that tells the parser to treat a single - option as an argument ++ * instead of trying to read STDIN. ++ * ++ * @var bool $avoid_reading_stdin Whether to treat - as an argument ++ */ ++ public $avoid_reading_stdin = false; ++ + /** + * An array of Console_CommandLine_Option objects. + * +@@ -999,7 +1008,8 @@ protected function parseToken($token, $result, &$args, $argc) + static $stopflag = false; + $last = $argc === 0; + if (!$stopflag && $lastopt) { +- if (substr($token, 0, 1) == '-') { ++ if (strlen($token) > ($this->avoid_reading_stdin ? 1 : 0) && ++ substr($token, 0, 1) == '-') { + if ($lastopt->argument_optional) { + $this->_dispatchAction($lastopt, '', $result); + if ($lastopt->action != 'StoreArray') { +@@ -1085,10 +1095,12 @@ protected function parseToken($token, $result, &$args, $argc) + $lastopt = $opt; + } + $this->_dispatchAction($opt, $value, $result); +- } else if (!$stopflag && substr($token, 0, 1) == '-') { ++ } else if (!$stopflag && ++ strlen($token) > ($this->avoid_reading_stdin ? 1 : 0) && ++ substr($token, 0, 1) == '-') { + // a short option + $optname = substr($token, 0, 2); +- if ($optname == '-') { ++ if ($optname == '-' && !$this->avoid_reading_stdin) { + // special case of "-": try to read stdin + $args[] = file_get_contents('php://stdin'); + return; +diff --git a/Console/CommandLine/Renderer/Default.php b/Console/CommandLine/Renderer/Default.php +index 59ce33e..8f34b26 100644 +--- a/Console/CommandLine/Renderer/Default.php ++++ b/Console/CommandLine/Renderer/Default.php +@@ -409,12 +409,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; +diff --git a/tests/console_commandline_addargument.phpt b/tests/console_commandline_addargument.phpt +index ca87c65..eb2e3af 100644 +--- a/tests/console_commandline_addargument.phpt ++++ b/tests/console_commandline_addargument.phpt +@@ -27,11 +27,14 @@ $parser->addArgument('Some invalid name'); + --EXPECTF-- + array(4) { + ["arg1"]=> +- object(Console_CommandLine_Argument)#5 (7) { ++ object(Console_CommandLine_Argument)#5 (8) { + ["multiple"]=> + bool(false) + ["optional"]=> + bool(false) ++ ["choices"]=> ++ array(0) { ++ } + ["name"]=> + string(4) "arg1" + ["help_name"]=> +@@ -45,11 +48,14 @@ array(4) { + } + } + ["arg2"]=> +- object(Console_CommandLine_Argument)#6 (7) { ++ object(Console_CommandLine_Argument)#6 (8) { + ["multiple"]=> + bool(true) + ["optional"]=> + bool(false) ++ ["choices"]=> ++ array(0) { ++ } + ["name"]=> + string(4) "arg2" + ["help_name"]=> +@@ -63,11 +69,14 @@ array(4) { + } + } + ["arg3"]=> +- object(Console_CommandLine_Argument)#7 (7) { ++ object(Console_CommandLine_Argument)#7 (8) { + ["multiple"]=> + bool(true) + ["optional"]=> + bool(false) ++ ["choices"]=> ++ array(0) { ++ } + ["name"]=> + string(4) "arg3" + ["help_name"]=> +@@ -81,11 +90,14 @@ array(4) { + } + } + ["arg4"]=> +- object(Console_CommandLine_Argument)#8 (7) { ++ object(Console_CommandLine_Argument)#8 (8) { + ["multiple"]=> + bool(false) + ["optional"]=> + bool(true) ++ ["choices"]=> ++ array(0) { ++ } + ["name"]=> + string(4) "arg4" + ["help_name"]=> +diff --git a/tests/console_commandline_bug18682.phpt b/tests/console_commandline_bug18682.phpt +new file mode 100644 +index 0000000..aa769c3 +--- /dev/null ++++ b/tests/console_commandline_bug18682.phpt +@@ -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: ++ %sconsole_commandline_bug18682.php ++ [options] cmd1 [options] ++ ++Options: ++ -h, --help show this help message and exit +-- +1.7.10 + diff --git a/Console_CommandLine-bug19683.patch b/Console_CommandLine-bug19683.patch new file mode 100644 index 0000000..2fe01b4 --- /dev/null +++ b/Console_CommandLine-bug19683.patch @@ -0,0 +1,25 @@ +From 05eb12793b236ea631eef42d292e31a27746a6aa Mon Sep 17 00:00:00 2001 +From: Laurent Laville <laurent.laville@gmail.com> +Date: Wed, 26 Dec 2012 16:03:20 +0100 +Subject: [PATCH] fix PEAR bug 19683 + +--- + tests/console_commandline_webrequest_2.phpt | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/tests/console_commandline_webrequest_2.phpt b/tests/console_commandline_webrequest_2.phpt +index c9ad9da..1d6b029 100644 +--- a/tests/console_commandline_webrequest_2.phpt ++++ b/tests/console_commandline_webrequest_2.phpt +@@ -15,7 +15,7 @@ $parser->parse(); + Description of our parser goes here... + + Usage: +- some_program [options] <simple> <multiple...> ++ some_program [options] simple [multiple1 multiple2 ...] + + Options: + -t, --true test the StoreTrue action +-- +1.7.10 + diff --git a/php-pear-Console-CommandLine.spec b/php-pear-Console-CommandLine.spec index b1d60c4..82a6a1c 100644 --- a/php-pear-Console-CommandLine.spec +++ b/php-pear-Console-CommandLine.spec @@ -4,7 +4,7 @@ Name: php-pear-Console-CommandLine Version: 1.2.0 -Release: 1%{?dist} +Release: 2%{?dist} Summary: A full featured command line options and arguments parser Group: Development/Libraries @@ -12,12 +12,18 @@ License: MIT URL: http://pear.php.net/package/%{pear_name} Source0: http://pear.php.net/get/%{pear_name}-%{version}.tgz +# columnWrap() in Default Renderer eats up lines with only a EOL +# https://pear.php.net/bugs/18682 +Patch1: %{pear_name}-bug18682.patch +# Unit tests are broken +# https://pear.php.net/bugs/19683 +Patch2: %{pear_name}-bug19683.patch + BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildArch: noarch BuildRequires: php-pear BuildRequires: php-pear(pear.phpunit.de/PHPUnit) -Requires: php(language) >= 5.1.0 Requires: php-spl Requires(post): %{__pear} Requires(postun): %{__pear} @@ -39,9 +45,15 @@ Main features: %prep %setup -qc +# because of our patches +sed -e 's/md5sum=.*name/name/' -i package.xml + cd %{pear_name}-%{version} mv ../package.xml %{name}.xml +%patch1 -p1 -b .bug18682 +%patch2 -p1 -b .bug19683 + %build cd %{pear_name}-%{version} @@ -63,11 +75,6 @@ install -pm 644 %{name}.xml $RPM_BUILD_ROOT%{pear_xmldir} %check cd %{pear_name}-%{version} - -# seems this ones need to be fixed for new feature -rm -f tests/console_commandline_addargument.phpt \ - tests/console_commandline_webrequest_2.phpt - %{_bindir}/phpunit tests @@ -96,6 +103,12 @@ fi %changelog +* Sun Dec 30 2012 Remi Collet <remi@fedoraproject.org> - 1.2.0-2 +- fix for https://pear.php.net/bugs/18682 + columnWrap() in Default Renderer eats up lines with only a EOL +- fix for https://pear.php.net/bugs/19683 + Unit tests are broken + * Thu Oct 25 2012 Remi Collet <remi@fedoraproject.org> - 1.2.0-1 - Version 1.2.0 (stable) - API 1.2.0 (stable) |