cvs: php4 /pear/PEAR/Command Common.php
| From: | Tomas V.V.Cox | Date: | Sun, 19 May 2002 15:44:47 +0000 |
| Subject: | cvs: php4 /pear/PEAR/Command Common.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-3933@lists.php.net to get a copy of this message | ||
cox Sun May 19 11:44:47 2002 EDT
Modified files:
/php4/pear/PEAR/Command Common.php
Log:
Put "pear help command" working again
Index: php4/pear/PEAR/Command/Common.php
diff -u php4/pear/PEAR/Command/Common.php:1.11 php4/pear/PEAR/Command/Common.php:1.12
--- php4/pear/PEAR/Command/Common.php:1.11 Mon May 13 21:48:20 2002
+++ php4/pear/PEAR/Command/Common.php Sun May 19 11:44:47 2002
@@ -16,7 +16,7 @@
// | Author: Stig Sæther Bakken <ssb@fast.no> |
// +----------------------------------------------------------------------+
//
-// $Id: Common.php,v 1.11 2002/05/14 01:48:20 ssb Exp $
+// $Id: Common.php,v 1.12 2002/05/19 15:44:47 cox Exp $
require_once "PEAR.php";
@@ -112,11 +112,53 @@
// }}}
// {{{ getHelp()
-
+ /**
+ * Returns the help message for the given command
+ *
+ * @param string $command The command
+ * @return mixed A fail string if the command does not have help or
+ * a two elements array containing [0]=>help string,
+ * [1]=> help string for the accepted cmd args
+ */
function getHelp($command)
{
- $help = preg_replace('/{config\s+([^\}]+)}/e',
"\$config->get('\1')", @$this->commands[$command]['doc']);
- return $help;
+ $config = &PEAR_Config::singleton();
+ $help = @$this->commands[$command]['doc'];
+ if (empty($help)) {
+ // XXX (cox) Fallback to summary if there is no doc (show both?)
+ if (!$help = @$this->commands[$command]['summary']) {
+ return "No help for command \"$command\"";
+ }
+ }
+ if (preg_match_all('/{config\s+([^\}]+)}/e', $help, $matches)) {
+ foreach($matches[0] as $k => $v) {
+ $help = preg_replace("/$v/", $config->get($matches[1][$k]), $help);
+ }
+ }
+ return array($help, $this->getHelpArgs($command));
+ }
+
+ // }}}
+ // {{{ getHelpArgs()
+ /**
+ * Returns the help for the accepted arguments of a command
+ *
+ * @param string $command
+ * @return string The help string
+ */
+ function getHelpArgs($command)
+ {
+ if (isset($this->commands[$command]['options']) &&
+ count($this->commands[$command]['options']))
+ {
+ $help = "Accepted options:\n";
+ // XXX Add long options
+ foreach ($this->commands[$command]['options'] as $k => $v) {
+ $help .= " -" . $v['shortopt'] . " " .
$v['doc'] . "\n";
+ }
+ return $help;
+ }
+ return null;
}
// }}}