]> granicus.if.org Git - php/commitdiff
- Provide working wordwrap for command help
authorMarcus Boerger <helly@php.net>
Fri, 11 May 2007 21:28:41 +0000 (21:28 +0000)
committerMarcus Boerger <helly@php.net>
Fri, 11 May 2007 21:28:41 +0000 (21:28 +0000)
ext/phar/phar/clicommand.inc

index c6b56f4eb8c7c53cd0a667aa405096cff8f75c1c..59982ffe4198228069d3426f502db6835f822806 100755 (executable)
@@ -234,11 +234,18 @@ abstract class CLICommand
        {
                return "This help.";
        }
+       
+       private function cli_wordwrap($what, $l, $sp)
+       {
+               $l = max(80 - $l, 40); // minimum length
+               $what = str_replace("\n", "\n".$sp, $what);
+               return wordwrap($what, $l, "\n".$sp);
+       }
 
-       private function cli_help_get_args($args, $l, $sp, $required)
+       private function cli_help_get_args($func, $l, $sp, $required)
        {
                $inf = "";
-               foreach(call_user_func(array($this, $args)) as $arg => $conf)
+               foreach(call_user_func($func, $l, $sp) as $arg => $conf)
                {
                        if ((isset($conf['required']) && $conf['required']) != $required)
                        {
@@ -303,13 +310,13 @@ Commands:
                        $inf = $name . substr($sp, strlen($name));
                        if (isset($funcs['inf']))
                        {
-                               $inf .= call_user_func(array($this, $funcs['inf'])) . "\n";
+                               $inf .= $this->cli_wordwrap(call_user_func(array($this, $funcs['inf'])), $l, $sp) . "\n";
                                if (isset($funcs['arg']))
                                {
                                        $inf .= "\n";
-                                       $inf .= $this->cli_help_get_args($funcs['arg'], $l, $sp, true);
+                                       $inf .= $this->cli_help_get_args(array($this, $funcs['arg']), $l, $sp, true);
                                        $inf .= "\n";
-                                       $inf .= $this->cli_help_get_args($funcs['arg'], $l, $sp, false);
+                                       $inf .= $this->cli_help_get_args(array($this, $funcs['arg']), $l, $sp, false);
                                }
                        }
                        echo "$inf\n\n";