]> granicus.if.org Git - php/commitdiff
- Implement command level options
authorTomas V.V.Cox <cox@php.net>
Thu, 21 Mar 2002 20:52:26 +0000 (20:52 +0000)
committerTomas V.V.Cox <cox@php.net>
Thu, 21 Mar 2002 20:52:26 +0000 (20:52 +0000)
- Removed call pass by reference
- Readd $options to command::run() params

pear/PEAR/Command.php
pear/PEAR/Command/Common.php
pear/PEAR/Command/Config.php
pear/PEAR/Command/Install.php
pear/PEAR/Command/List.php
pear/PEAR/Command/Login.php
pear/PEAR/Command/Package.php
pear/PEAR/Config.php
pear/PEAR/Remote.php

index 46c3d232995d25e76e98f0d9dd786477afaa9e36..f0f88eaefe2a778109a76fa2eabccbc28f0ac151 100644 (file)
@@ -33,6 +33,12 @@ $GLOBALS['_PEAR_Command_commandlist'] = array();
  */
 $GLOBALS['_PEAR_Command_uiclass'] = 'PEAR_CommandUI_CLI';
 
+/**
+* The options accepted by the commands
+* @var string the options
+*/
+$GLOBALS['_PEAR_Command_commandopts'] = '';
+
 /**
  * PEAR command class, a simple factory class for administrative
  * commands.
@@ -154,6 +160,7 @@ class PEAR_Command
         if (!$merge) {
             $GLOBALS['_PEAR_Command_commandlist'] = array();
         }
+        $cmdopts = array();
         while ($entry = readdir($dp)) {
             if ($entry{0} == '.' || substr($entry, -4) != '.php' ||
                 $entry == 'Common.php')
@@ -163,11 +170,15 @@ class PEAR_Command
             $class = "PEAR_Command_".substr($entry, 0, -4);
             $file = "$dir/$entry";
             include_once $file;
+            // List of commands
             $implements = call_user_func(array($class, "getCommands"));
             foreach ($implements as $command) {
                 $GLOBALS['_PEAR_Command_commandlist'][$command] = $class;
             }
+            // List of options accepted
+            $cmdopts = array_merge($cmdopts, call_user_func(array($class, "getOptions")));
         }
+        $GLOBALS['_PEAR_Command_commandopts'] = implode('', $cmdopts);
         return true;
     }
 
@@ -186,6 +197,14 @@ class PEAR_Command
         }
         return $GLOBALS['_PEAR_Command_commandlist'];
     }
+
+    function getOptions()
+    {
+        if (empty($GLOBALS['_PEAR_Command_commandlist'])) {
+            PEAR_Command::registerCommands();
+        }
+        return $GLOBALS['_PEAR_Command_commandopts'];
+    }
 }
 
 ?>
\ No newline at end of file
index 8883b5eb5736c42dc34fb2abdf63a5855e9492c4..0ae02ebddd843c78165a17b78c1e1f6fe6f354d4 100644 (file)
@@ -49,6 +49,11 @@ class PEAR_Command_Common extends PEAR
         $this->ui = $ui;
     }
 
+    function getOptions()
+    {
+        return array();
+    }
+
     /**
      * Return a PEAR_CommandResponse object with parameters
      * filled in.
index 06a331399f1cfcfdfeab081b181ba1e75a67434d..71009bc16cf8f246041c91c16f4d8886a0f2758c 100644 (file)
@@ -59,7 +59,7 @@ class PEAR_Command_Config extends PEAR_Command_Common
     // }}}
     // {{{ run()
 
-    function run($command, $params)
+    function run($command, $options, $params)
     {
         $cf =& $this->config;
         $failmsg = '';
index a2131ebce3784877d1c8827fad0bfb5213743d4f..6cfd8e65cc08cddbcf158e9c8483fbbc25c4263f 100644 (file)
@@ -60,22 +60,25 @@ class PEAR_Command_Install extends PEAR_Command_Common
     // }}}
     // {{{ run()
 
-    function run($command, $params)
+    function run($command, $options, $params)
     {
         $installer =& new PEAR_Installer($this->config->get('php_dir'),
                                          $this->config->get('ext_dir'),
                                          $this->config->get('doc_dir'));
         $installer->debug = $this->config->get('verbose');
         $failmsg = '';
-        $options = array();
+        $opts = array();
         switch ($command) {
             case 'install':
             case 'upgrade': {
                 if ($command == 'upgrade') {
-                    $options['upgrade'] = true;
+                    $opts['upgrade'] = true;
+                }
+                if (isset($options['f'])) {
+                    $opts['force'] = true;
                 }
                 // The ['force'] and ['nodeps'] options are still missing
-                if ($installer->install($params[0], $options, $this->config)) {
+                if ($installer->install(@$params[0], $opts, $this->config)) {
                     $this->ui->displayLine("install ok");
                 } else {
                     $failmsg = "install failed";
@@ -101,6 +104,11 @@ class PEAR_Command_Install extends PEAR_Command_Common
     }
 
     // }}}
+
+    function getOptions()
+    {
+        return array('f');
+    }
 }
 
 ?>
\ No newline at end of file
index 489a4bc6d687b7a323257f961a112c9e1666ba4d..7334c1802bf97340f2de23ccc23e690781623cfa 100644 (file)
@@ -59,7 +59,7 @@ class PEAR_Command_List extends PEAR_Command_Common
     // }}}
     // {{{ run()
 
-    function run($command, $params)
+    function run($command, $options, $params)
     {
         $reg = new PEAR_Registry(); // XXX Use config here
         $installed = $reg->packageInfo();
index cd958752fae2a4685bb57d2aac6eda0297c7818a..44c85c909bc2880ecb63591fcf860e0ccc86c1f5 100644 (file)
@@ -70,7 +70,7 @@ class PEAR_Command_Login extends PEAR_Command_Common
      *
      * @access public
      */
-    function run($command, $params)
+    function run($command, $options, $params)
     {
         $cf = $this->config;
         $failmsg = '';
index 03b118c5e4c111cec65912fc2fb69b23a832db18..f3f7a27e67955ec4e3d176383270f482b41cafc2 100644 (file)
@@ -48,7 +48,7 @@ class PEAR_Command_Package extends PEAR_Command_Common
      *
      * @access public
      */
-    function run($command, $params)
+    function run($command, $options, $params)
     {
         $failmsg = '';
         switch ($command) {
index 75d38a2dddfbd9d101beb252cfc38eb442562eab..68e9fa772e0397011fe7d393650a51fb99e0750b 100644 (file)
@@ -355,7 +355,7 @@ class PEAR_Config extends PEAR
         $size = filesize($file);
         $contents = fread($fp, $size);
         $version = '0.1';
-        if (preg_match('/^#PEAR_Config\s+(\S+)\s+/si', $contents, &$matches)) {
+        if (preg_match('/^#PEAR_Config\s+(\S+)\s+/si', $contents, $matches)) {
             $version = $matches[1];
             $contents = substr($contents, strlen($matches[0]));
         }
index aba4b24780e7789d74da2e8272b77ea539789123..3ecbb5f4f541c92dbcb7af0955bcc8c4397d4648 100644 (file)
@@ -74,7 +74,7 @@ class PEAR_Remote extends PEAR
         fwrite($fp, ("POST /xmlrpc.php HTTP/1.0\r\n$req_headers\r\n$request"));
         $response = '';
         $line1 = fgets($fp, 2048);
-        if (!preg_match('!^HTTP/[0-9\.]+ (\d+) (.*)!', $line1, &$matches)) {
+        if (!preg_match('!^HTTP/[0-9\.]+ (\d+) (.*)!', $line1, $matches)) {
             return $this->raiseError("PEAR_Remote: invalid HTTP response from XML-RPC server");
         }
         switch ($matches[1]) {