]> granicus.if.org Git - php/commitdiff
* remove run() from this class
authorStig Bakken <ssb@php.net>
Mon, 20 May 2002 08:56:00 +0000 (08:56 +0000)
committerStig Bakken <ssb@php.net>
Mon, 20 May 2002 08:56:00 +0000 (08:56 +0000)
pear/PEAR/Command/Registry.php

index be5bf182a8e212accb338ddba379f6bb35869720..fa6114ceceaaba417a1e6aac5a699281a40ccc14 100644 (file)
@@ -25,7 +25,24 @@ require_once 'PEAR/Config.php';
 
 class PEAR_Command_Registry extends PEAR_Command_Common
 {
-    // {{{ constructor
+    var $commands = array(
+        'list-installed' => array(
+            'summary' => 'List Installed Packages',
+            'function' => 'doListInstalled',
+            'options' => array(),
+            'doc' => 'List the PEAR packages installed in your php_dir ({config php_dir)).
+',
+            ),
+        'shell-test' => array(
+            'summary' => 'Shell Script Test',
+            'function' => 'doShellTest',
+            'options' => array(),
+            'doc' => 'Tests if a package is installed in the system. Will exit(1) if it is not.
+   <relation>   The version comparison operator. One of:
+                <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne
+   <version>    The version to compare with
+'),
+        );
 
     /**
      * PEAR_Command_Registry constructor.
@@ -37,125 +54,58 @@ class PEAR_Command_Registry extends PEAR_Command_Common
         parent::PEAR_Command_Common($ui, $config);
     }
 
-    // }}}
-
-    // {{{ getCommands()
-
-    /**
-     * Return a list of all the commands defined by this class.
-     * @return array list of commands
-     * @access public
-     */
-    function getCommands()
-    {
-        return array('list-installed' => 'List Installed Packages',
-                     'shell-test' => 'Shell Script Test');
-    }
-
-    function getHelp($command)
+    function doListInstalled($command, $options, $params)
     {
-        switch ($command) {
-            case 'list-installed':
-                return array(null, 'List the installed PEAR packages in the system');
-            case 'shell-test':
-                return array('<package name> [<relation>] [<version>]',
-                        "Tests if a package is installed in the system. Will exit(1) if it is not.\n".
-                        "   <relation>   The version comparison operator. One of:\n".
-                        "                <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne\n".
-                        "   <version>    The version to compare with");
+        $reg = new PEAR_Registry($this->config->get('php_dir'));
+        $installed = $reg->packageInfo();
+        $i = $j = 0;
+        $this->ui->startTable(
+            array('caption' => 'Installed packages:',
+                  'border' => true));
+        foreach ($installed as $package) {
+            if ($i++ % 20 == 0) {
+                $this->ui->tableRow(
+                    array('Package', 'Version', 'State'),
+                    array('bold' => true));
+            }
+            $this->ui->tableRow(array($package['package'],
+                                      $package['version'],
+                                      @$package['release_state']));
         }
+        if ($i == 0) {
+            $this->ui->tableRow(array('(no packages installed yet)'));
+        }
+        $this->ui->endTable();
+        return true;
     }
 
-    // }}}
-    // {{{ run()
-
-    /**
-     * Execute the command.
-     *
-     * @param string command name
-     *
-     * @param array option_name => value
-     *
-     * @param array list of additional parameters
-     *
-     * @return bool TRUE on success, FALSE if the command was unknown,
-     *              or a PEAR error on failure
-     *
-     * @access public
-     */
-    function run($command, $options, $params)
-    {
-        $failmsg = '';
-        $cf = &PEAR_Config::singleton();
-        switch ($command) {
-            // {{{ list-installed
-
-            case 'list-installed': {
-                $reg = new PEAR_Registry($cf->get('php_dir'));
-                $installed = $reg->packageInfo();
-                $i = $j = 0;
-                $this->ui->startTable(
-                    array('caption' => 'Installed packages:',
-                          'border' => true));
-                foreach ($installed as $package) {
-                    if ($i++ % 20 == 0) {
-                        $this->ui->tableRow(
-                            array('Package', 'Version', 'State'),
-                            array('bold' => true));
-                    }
-                    $this->ui->tableRow(array($package['package'],
-                                              $package['version'],
-                                              @$package['release_state']));
-                }
-                if ($i == 0) {
-                    $this->ui->tableRow(array('(no packages installed yet)'));
-                }
-                $this->ui->endTable();
-                break;
+    function doShellTest($command, $options, $params) {
+        $this->pushErrorHandling(PEAR_ERROR_RETURN);
+        $reg = &new PEAR_Registry($this->config->get('php_dir'));
+        // "pear shell-test Foo"
+        if (sizeof($params) == 1) {
+            if (!$reg->packageExists($params[0])) {
+                exit(1);
             }
-
-            // }}}
-            case 'shell-test': {
-                // silence error messages for the rest of the execution
-                PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
-                $reg = &new PEAR_Registry($this->config->get('php_dir'));
-                // "pear shell-test Foo"
-                if (sizeof($params) == 1) {
-                    if (!$reg->packageExists($params[0])) {
-                        exit(1);
-                    }
-                // "pear shell-test Foo 1.0"
-                } elseif (sizeof($params) == 2) {
-                    $v = $reg->packageInfo($params[0], 'version');
-                    if (!$v || !version_compare($v, $params[1], "ge")) {
-                        exit(1);
-                    }
-                // "pear shell-test Foo ge 1.0"
-                } elseif (sizeof($params) == 3) {
-                    $v = $reg->packageInfo($params[0], 'version');
-                    if (!$v || !version_compare($v, $params[2], $params[1])) {
-                        exit(1);
-                    }
-                } else {
-                    PEAR::popErrorHandling();
-                    PEAR::raiseError("$command: expects 1 to 3 parameters");
-                    exit(1);
-                }
-                break;
+            // "pear shell-test Foo 1.0"
+        } elseif (sizeof($params) == 2) {
+            $v = $reg->packageInfo($params[0], 'version');
+            if (!$v || !version_compare($v, $params[1], "ge")) {
+                exit(1);
             }
-            default: {
-                return false;
+            // "pear shell-test Foo ge 1.0"
+        } elseif (sizeof($params) == 3) {
+            $v = $reg->packageInfo($params[0], 'version');
+            if (!$v || !version_compare($v, $params[2], $params[1])) {
+                exit(1);
             }
+        } else {
+            $this->popErrorHandling();
+            $this->raiseError("$command: expects 1 to 3 parameters");
+            exit(1);
         }
-        if ($failmsg) {
-            return $this->raiseError($failmsg);
-        }
-        return true;
     }
 
-    // }}}
-
-
 }
 
 ?>
\ No newline at end of file