]> granicus.if.org Git - php/commitdiff
* add -G option to "pear" for php-gtk frontend
authorStig Bakken <ssb@php.net>
Thu, 9 May 2002 02:31:37 +0000 (02:31 +0000)
committerStig Bakken <ssb@php.net>
Thu, 9 May 2002 02:31:37 +0000 (02:31 +0000)
* added Gtk stub (only creates window right now)
* added command descriptions

pear/Makefile.frag
pear/PEAR/Command.php
pear/PEAR/Command/Auth.php
pear/PEAR/Command/Config.php
pear/PEAR/Command/Install.php
pear/PEAR/Command/Package.php
pear/PEAR/Command/Registry.php
pear/PEAR/Command/Remote.php
pear/PEAR/Frontend/Gtk.php [new file with mode: 0644]
pear/package-pear.xml
pear/scripts/pear.in

index 1395913117fc186833fff5a857b5d56e0ed2f00e..a1a352670a470cd2362211d376a666aa70b88700 100644 (file)
@@ -94,25 +94,29 @@ PEAR_FILES = \
 #      Net/Socket.php \
 #      Schedule/At.php \
 
-PEAR_PACKAGES=\
-       Net_Socket-1.0.tgz
-
+#PEARCMD=$(top_builddir)/sapi/cli/php $(builddir)/scripts/pear
+#
+#install-pear-installer: $(top_builddir)/sapi/cli/php
+#      version=`grep '<version>' $(srcdir)/package-pear.xml|head -1|cut -d\> -f2|cut -d\< -f1`; \
+#      if $(PEARCMD) shell-test PEAR; then
+#          if ! $(PEARCMD) shell-test PEAR $$version; then \
+#              $(PEARCMD) upgrade package-pear.xml; \
+#          fi; \
+#      else; \
+#          $(PEARCMD) install package-pear.xml; \
+#      fi
 
 install-pear:
        @if $(mkinstalldirs) $(INSTALL_ROOT)$(peardir); then \
                for i in $(PEAR_SUBDIRS); do \
                        $(mkinstalldirs) $(INSTALL_ROOT)$(peardir)/$$i; \
                done; \
-               for dir in PEAR/CommandUI; do \
-                       test -d $(INSTALL_ROOT)$(peardir)/$$dir && rm -rf $(INSTALL_ROOT)$(peardir)/$$dir; \
-               done; \
                for i in $(PEAR_FILES); do \
                        echo "Installing $$i"; \
                        dir=`echo $$i|sed 's%[^/][^/]*$$%%'`; \
                        $(INSTALL_DATA) $(srcdir)/$$i $(INSTALL_ROOT)$(peardir)/$$dir; \
                done; \
                rm -f $(INSTALL_ROOT)$(peardir)/PEAR/Command/Login.php; \
-               rm -f $(INSTALL_ROOT)$(peardir)/PEAR/CommandUI/CLI.php; \
                rm -f $(INSTALL_ROOT)$(peardir)/PEAR/CommandResponse.php; \
                rm -f $(INSTALL_ROOT)$(peardir)/PEAR/Uploader.php; \
        else \
index b7f2b21923744dd6eac17c6a5a0321aec3ed7a1a..7972f42eb5374372ef7f55c2bf940d502c290a19 100644 (file)
@@ -197,8 +197,9 @@ class PEAR_Command
             include_once $file;
             // List of commands
             $implements = call_user_func(array($class, "getCommands"));
-            foreach ($implements as $command) {
+            foreach ($implements as $command => $desc) {
                 $GLOBALS['_PEAR_Command_commandlist'][$command] = $class;
+                $GLOBALS['_PEAR_Command_commanddesc'][$command] = $desc;
             }
             // List of options accepted
             $cmdopts = array_merge($cmdopts, call_user_func(array($class, "getOptions")));
@@ -239,6 +240,20 @@ class PEAR_Command
         return $GLOBALS['_PEAR_Command_commandopts'];
     }
 
+    /**
+     * Get description for a command.
+     *
+     * @param  string $command Name of the command
+     *
+     * @return string command description
+     *
+     * @access public
+     */
+    function getDescription($command)
+    {
+        return @$GLOBALS['_PEAR_Command_commanddesc'][$command];
+    }
+
     /**
      * Get help for command.
      *
index f59f730b83c243fbe8d739a1ff03e6c2aedf6fcf..8632e95c62430e30a732a497668410744d0d370b 100644 (file)
@@ -51,7 +51,8 @@ class PEAR_Command_Auth extends PEAR_Command_Common
      */
     function getCommands()
     {
-        return array('login', 'logout');
+        return array('login' => 'Log In',
+                     'logout' => 'Log Out');
     }
 
     // }}}
index 009c2d243ebf5210edb2d77aed20b0e4e011c03f..c05389d452596e1dc97ab9465ea0290e0b667acb 100644 (file)
@@ -55,7 +55,9 @@ class PEAR_Command_Config extends PEAR_Command_Common
      */
     function getCommands()
     {
-        return array('config-show', 'config-get', 'config-set');
+        return array('config-show' => 'Show All Settings',
+                     'config-get' => 'Show One Setting',
+                     'config-set' => 'Change Setting');
     }
 
     // }}}
index a4efc90fd9a16eb335727c4cc327b60de9b6006e..cae832aec7ddaf98ac80d880e218d51893aab6db 100644 (file)
@@ -51,7 +51,9 @@ class PEAR_Command_Install extends PEAR_Command_Common
      */
     function getCommands()
     {
-        return array('install', 'uninstall', 'upgrade');
+        return array('install' => 'Install Package',
+                     'uninstall' => 'Uninstall Package',
+                     'upgrade' => 'Upgrade Package');
     }
 
     function getHelp($command)
index 85bade842a9543b05cac1db6c6334bcbd792a584..e63b9cec9130ad69a57cdd753e1989cd71bae7da 100644 (file)
@@ -67,11 +67,11 @@ class PEAR_Command_Package extends PEAR_Command_Common
      */
     function getCommands()
     {
-        return array('package',
-                     'package-info',
-                     'package-list',
-                     'package-validate',
-                     'cvstag');
+        return array('package' => 'Build Package',
+                     'package-info' => 'Show Package Info',
+                     'package-list' => 'List Files in Package',
+                     'package-validate' => 'Validate Package',
+                     'cvstag' => 'Set CVS Release Tag');
     }
 
     // }}}
index 049b89f54c808695af75b7bb3fe56e205a4f06d5..be5bf182a8e212accb338ddba379f6bb35869720 100644 (file)
@@ -48,7 +48,8 @@ class PEAR_Command_Registry extends PEAR_Command_Common
      */
     function getCommands()
     {
-        return array('list-installed', 'shell-test');
+        return array('list-installed' => 'List Installed Packages',
+                     'shell-test' => 'Shell Script Test');
     }
 
     function getHelp($command)
index d9922021418ba4f80152fdbe37dd069036e52bc1..def57a4be19ee05611cf7b7f6a591a36cbd717d3 100644 (file)
@@ -48,10 +48,10 @@ class PEAR_Command_Remote extends PEAR_Command_Common
      */
     function getCommands()
     {
-        return array('remote-package-info',
-                     'list-upgrades',
-                     'list-remote-packages',
-                     'download');
+        return array('remote-package-info' => 'Information About Remote Package',
+                     'list-upgrades' => 'List Available Upgrades',
+                     'list-remote-packages' => 'List Remote Packages',
+                     'download' => 'Download Package');
     }
 
     // }}}
diff --git a/pear/PEAR/Frontend/Gtk.php b/pear/PEAR/Frontend/Gtk.php
new file mode 100644 (file)
index 0000000..f715fb4
--- /dev/null
@@ -0,0 +1,133 @@
+<?php
+/*
+  +----------------------------------------------------------------------+
+  | PHP Version 4                                                        |
+  +----------------------------------------------------------------------+
+  | Copyright (c) 1997-2002 The PHP Group                                |
+  +----------------------------------------------------------------------+
+  | This source file is subject to version 2.02 of the PHP license,      |
+  | that is bundled with this package in the file LICENSE, and is        |
+  | available at through the world-wide-web at                           |
+  | http://www.php.net/license/2_02.txt.                                 |
+  | If you did not receive a copy of the PHP license and are unable to   |
+  | obtain it through the world-wide-web, please send a note to          |
+  | license@php.net so we can mail you a copy immediately.               |
+  +----------------------------------------------------------------------+
+  | Author: Stig Sæther Bakken <ssb@fast.no>                             |
+  +----------------------------------------------------------------------+
+
+  $Id$
+*/
+
+require_once "PEAR.php";
+
+class PEAR_Frontend_Gtk extends PEAR
+{
+    // {{{ properties
+
+    /**
+     * What type of user interface this frontend is for.
+     * @var string
+     * @access public
+     */
+    var $type = 'Gtk';
+
+    var $omode = 'plain';
+    var $params = array();
+    var $window = null;
+
+    // }}}
+
+    // {{{ constructor
+
+    function PEAR_Frontend_Gtk()
+    {
+        parent::PEAR();
+        if (!extension_loaded('php_gtk')) {
+            dl('php_gtk.' . (OS_WINDOWS ? 'dll' : 'so'));
+        }
+        $this->window = &new GtkWindow();
+        $this->window->set_title('PEAR Installer');
+        $this->window->set_usize((gdk::screen_width()/3), (gdk::screen_height()/3));
+        $this->window->show_all();
+    }
+
+    // }}}
+
+    // {{{ displayLine(text)
+
+    function displayLine($text)
+    {
+    }
+
+    function display($text)
+    {
+    }
+
+    // }}}
+    // {{{ displayError(eobj)
+
+    function displayError($eobj)
+    {
+    }
+
+    // }}}
+    // {{{ displayFatalError(eobj)
+
+    function displayFatalError($eobj)
+    {
+    }
+
+    // }}}
+    // {{{ displayHeading(title)
+
+    function displayHeading($title)
+    {
+    }
+
+    // }}}
+    // {{{ userDialog(prompt, [type], [default])
+
+    function userDialog($prompt, $type = 'text', $default = '')
+    {
+    }
+
+    // }}}
+    // {{{ userConfirm(prompt, [default])
+
+    function userConfirm($prompt, $default = 'yes')
+    {
+    }
+
+    // }}}
+    // {{{ startTable([params])
+
+    function startTable($params = array())
+    {
+    }
+
+    // }}}
+    // {{{ tableRow(columns, [rowparams], [colparams])
+
+    function tableRow($columns, $rowparams = array(), $colparams = array())
+    {
+    }
+
+    // }}}
+    // {{{ endTable()
+
+    function endTable()
+    {
+    }
+
+    // }}}
+    // {{{ bold($text)
+
+    function bold($text)
+    {
+    }
+
+    // }}}
+}
+
+?>
index d0516da0aefc49c244aa43127829b73fb8873f03..ea26c4843e6c3bef6b0e411882d4dec57779f94e 100644 (file)
@@ -50,6 +50,7 @@
         <file role="php" name="Dependency.php"/>
         <dir name="Frontend">
           <file role="php" name="CLI.php"/>
+          <file role="php" name="Gtk.php"/>
         </dir>
         <file role="php" name="Installer.php"/>
         <file role="php" name="Packager.php"/>
index dc2561d16bcf4281d69f627668c52269c4ede035..4a386697729a32b6f73eeb5e71ab39b6d930cf8b 100644 (file)
@@ -33,19 +33,27 @@ require_once 'Console/Getopt.php';
 PEAR_Command::setFrontendType('CLI');
 $all_commands = PEAR_Command::getCommands();
 $cmd_options  = PEAR_Command::getOptions();
-$ui = &PEAR_Command::getFrontendObject();
 $progname = basename(__FILE__);
 
 // XXX change Getopt to use raiseError() ?
 $argv = Console_Getopt::readPHPArgv();
-$options = Console_Getopt::getopt($argv, "c:C:d:D:h?sSqu:v" . $cmd_options);
+$options = Console_Getopt::getopt($argv, "c:C:d:D:Gh?sSqu:v" . $cmd_options);
 if (PEAR::isError($options)) {
     usage($options);
 }
 
-PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($ui, "displayFatalError"));
 $opts = $options[0];
 
+$fetype = 'CLI';
+foreach ($opts as $opt) {
+    if ($opt[0] == 'G') {
+        $fetype = 'Gtk';
+    }
+}
+PEAR_Command::setFrontendType($fetype);
+$ui = &PEAR_Command::getFrontendObject();
+PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($ui, "displayFatalError"));
+
 $pear_user_config = '';
 $pear_system_config = '';
 $store_user_config = false;
@@ -114,19 +122,23 @@ if (empty($command) && ($store_user_config || $store_system_config)) {
     exit;
 }
 
-if (empty($all_commands[$command]) || $command == 'help') {
-    usage(null, @$options[1][2]);
-}
-
-$cmd = PEAR_Command::factory($command, $config);
-if (PEAR::isError($cmd)) {
-    die($cmd->getMessage());
-}
-
-$cmdargs = array_slice($options[1], 2);
-$ok = $cmd->run($command, $cmdopts, $cmdargs);
-if ($ok === false) {
-    PEAR::raiseError("unknown command `$command'");
+if ($fetype == 'Gtk') {
+    Gtk::main();
+} else {
+    if (empty($all_commands[$command]) || $command == 'help') {
+        usage(null, @$options[1][2]);
+    }
+    
+    $cmd = PEAR_Command::factory($command, $config);
+    if (PEAR::isError($cmd)) {
+        die($cmd->getMessage());
+    }
+    
+    $cmdargs = array_slice($options[1], 2);
+    $ok = $cmd->run($command, $cmdopts, $cmdargs);
+    if ($ok === false) {
+        PEAR::raiseError("unknown command `$command'");
+    }
 }
 
 // {{{ usage()
@@ -148,9 +160,14 @@ function usage($error = null, $helpsubject = null)
             "Usage: $progname [options] command [command-options] <parameters>\n".
             "Type \"$progname help options\" to list all options.\n".
             "Type \"$progname help <command>\" to get the help for the specified command.\n".
-            "Commands:\n   " . implode("\n   ", array_keys($all_commands));
+            "Commands:\n";
+        $maxlen = max(array_map("strlen", $all_commands));
+        $formatstr = "%-{$maxlen}s  %s\n";
+        foreach ($all_commands as $cmd => $class) {
+            $put .= sprintf($formatstr, $cmd, PEAR_Command::getDescription($cmd));
+        }
     }
-    fputs($stderr, "$put\n\n");
+    fputs($stderr, "$put\n");
     fclose($stderr);
     exit;
 }
@@ -167,6 +184,7 @@ function cmdHelp($command)
         "     -C file    find system configuration in `file'\n".
         "     -d foo=bar set user config variable `foo' to `bar'\n".
         "     -D foo=bar set system config variable `foo' to `bar'\n".
+        "     -G         start in graphical (Gtk) mode\n".
         "     -s         store user configuration\n".
         "     -S         store system configuration\n".
         "     -u foo     unset `foo' in the user configuration\n".