From: Marcus Boerger Date: Mon, 14 May 2007 17:14:15 +0000 (+0000) Subject: - Add help X-Git-Tag: RELEASE_1_2_0~61 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4f620b0c7bf40c2f4772998d9d879abc01b65300;p=php - Add help - Allow commands to have '-' in their name --- diff --git a/ext/phar/phar/clicommand.inc b/ext/phar/phar/clicommand.inc index e9b040ba46..f2faafccd9 100755 --- a/ext/phar/phar/clicommand.inc +++ b/ext/phar/phar/clicommand.inc @@ -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] [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] [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']))