]> granicus.if.org Git - php/commitdiff
- Add help <command>
authorMarcus Boerger <helly@php.net>
Mon, 14 May 2007 17:14:15 +0000 (17:14 +0000)
committerMarcus Boerger <helly@php.net>
Mon, 14 May 2007 17:14:15 +0000 (17:14 +0000)
- Allow commands to have '-' in their name

ext/phar/phar/clicommand.inc

index e9b040ba46a0de460a4958c1b927e305ddc45942..f2faafccd9ec1d7fc4442f2079436755d32814e7 100755 (executable)
@@ -146,6 +146,7 @@ abstract class CLICommand
                                {
                                        $what = substr($m->name, $l+strlen($sub)+1);
                                        $func = $prefix . $sub . '_' . $what;
+                                       $what = str_replace('_', '-', $what);
                                        if ($r->hasMethod($func))
                                        {
                                                if (!isset($a[$what]))
@@ -316,25 +317,52 @@ abstract class CLICommand
                }
        }
 
-       function cli_cmd_run_help()
+       function cli_cmd_arg_help()
        {
-               $argv = $this->argv;
-
-               echo "
-$argv[0] <command> [options]
-
-Commands:
-
+               return array('' => array('typ'=>'any','val'=>NULL,'inf'=>'Optional command to retrieve help for.'));
+       }
 
-";
-               $l = 0;
-               ksort($this->cmds);
-               foreach($this->cmds as $name => $funcs)
+       function cli_cmd_run_help()
+       {
+               $argv  = $this->argv;
+               $which = $this->args['']['val'];
+               if (isset($which))
+               {
+                       if (count($which) != 1)
+                       {
+                               echo "More than one command given.\n";
+                               exit(1);
+                       }
+                       $which = $which[0];
+                       if (!array_key_exists($which, $this->cmds))
+                       {
+                               echo "Unknown command, cannot retrieve help.\n";
+                               exit(1);
+                       }
+                       $l = strlen($which);
+                       $cmds = array($which => $this->cmds[$which]);
+               }
+               else
                {
-                       $l = max($l, strlen($name));
+                       echo "\n$argv[0] <command> [options]\n\n";
+                       $l = 0;
+                       ksort($this->cmds);
+                       foreach($this->cmds as $name => $funcs)
+                       {
+                               $l = max($l, strlen($name));
+                       }
+                       $inf = "Commands:";
+                       $lst = "";
+                       $ind = strlen($inf) + 1;
+                       foreach($this->cmds as $name => $funcs)
+                       {
+                               $lst .= ' ' . $name;
+                       }
+                       echo $this->cli_wordwrap($inf.$lst, $ind, str_repeat(' ', $ind)) . "\n\n";
+                       $cmds = $this->cmds;
                }
-               $sp = str_repeat(' ', $l+2);
-               foreach($this->cmds as $name => $funcs)
+               $sp = str_repeat(' ', $l + 2);
+               foreach($cmds as $name => $funcs)
                {
                        $inf = $name . substr($sp, strlen($name));
                        if (isset($funcs['inf']))