better help for positional args
authorMichael Wallner <mike@php.net>
Fri, 11 Sep 2015 07:16:03 +0000 (09:16 +0200)
committerMichael Wallner <mike@php.net>
Fri, 11 Sep 2015 07:16:03 +0000 (09:16 +0200)
src/pharext/Cli/Args.php
src/pharext/Cli/Args/Help.php

index c248a74dcc964c81c089d1b2204a8cacfe3dcfb0..7334290f4f070c8b2f5f5474fc619bf6b7a4eb8a 100644 (file)
@@ -207,7 +207,7 @@ class Args implements \ArrayAccess
                $args = [];
                foreach ($this->spec as $spec) {
                        $opt = $this->opt($spec[1]);
-                       $args[$opt] = $this[$opt];
+                       $args[$opt] = is_numeric($spec[0]) ? $this[$spec[0]] : $this[$opt];
                }
                return $args;
        }
index 4284dbb500db5f54259e2e172836edc676545153..e67da9c6b78fcd466bf3a0bac8ca5f732bff5f11 100644 (file)
@@ -89,15 +89,34 @@ class Help
 
        function dumpPositional(array $positional) {
                $dump = " [--]";
+               $conv = [];
                foreach ($positional as $pos) {
-                       if ($pos[3] & Args::REQUIRED) {
-                               $dump .= sprintf(" <%s>", $pos[1]);
+                       $conv[$pos[0]][] = $pos;
+               }
+               $opts = [];
+               foreach ($conv as $positional) {
+                       $args = implode("|", array_column($positional, 1));
+                       if ($positional[0][3] & Args::REQUIRED) {
+                               $dump .= sprintf(" <%s>", $args);
                        } else {
-                               $dump .= sprintf(" [<%s>]", $pos[1]);
+                               $dump .= sprintf(" [<%s>]", $args);
+                       }
+                       if ($positional[0][3] & Args::MULTI) {
+                               $dump .= sprintf(" [<%s>]...", $args);
                        }
-                       if ($pos[3] & Args::MULTI) {
-                               $dump .= sprintf(" [<%s>]...", $pos[1]);
+                       /*
+                       foreach ($positional as $pos) {
+                               if ($pos[3] & Args::REQUIRED) {
+                                       $dump .= sprintf(" <%s>", $pos[1]);
+                               } else {
+                                       $opts[] = $pos;
+                                       //$dump .= sprintf(" [<%s>]", $pos[1]);
+                               }
+                               if ($pos[3] & Args::MULTI) {
+                                       $dump .= sprintf(" [<%s>]...", $pos[1]);
+                               }
                        }
+                        */
                }
                return $dump;
        }
@@ -130,8 +149,9 @@ class Help
                                $dump .= "       ";
                        }
 
-                       $dump .= str_repeat(" ", $max-strlen($spec[1])+3*!isset($spec[0]));
-                       $dump .= $spec[2];
+                       $space = str_repeat(" ", $max-strlen($spec[1])+3*!isset($spec[0]));
+                       $dump .= $space;
+                       $dump .= str_replace("\n", "\n                        $space", $spec[2]);
 
                        if ($spec[3] & Args::REQUIRED) {
                                $dump .= " (REQUIRED)";