Subversion Repositories Applications.gtt

Rev

Rev 94 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 187
1
<?php
1
<?php
2
/**
2
/**
3
 * PEAR_Command, command pattern class
3
 * PEAR_Command, command pattern class
4
 *
4
 *
5
 * PHP versions 4 and 5
5
 * PHP versions 4 and 5
6
 *
6
 *
7
 * LICENSE: This source file is subject to version 3.0 of the PHP license
-
 
8
 * that is available through the world-wide-web at the following URI:
-
 
9
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
-
 
10
 * the PHP License and are unable to obtain it through the web, please
-
 
11
 * send a note to license@php.net so we can mail you a copy immediately.
-
 
12
 *
-
 
13
 * @category   pear
7
 * @category   pear
14
 * @package    PEAR
8
 * @package    PEAR
15
 * @author     Stig Bakken <ssb@php.net>
9
 * @author     Stig Bakken <ssb@php.net>
16
 * @author     Greg Beaver <cellog@php.net>
10
 * @author     Greg Beaver <cellog@php.net>
17
 * @copyright  1997-2006 The PHP Group
11
 * @copyright  1997-2009 The Authors
18
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
12
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
19
 * @version    CVS: $Id: Command.php,v 1.38 2006/10/31 02:54:40 cellog Exp $
-
 
20
 * @link       http://pear.php.net/package/PEAR
13
 * @link       http://pear.php.net/package/PEAR
21
 * @since      File available since Release 0.1
14
 * @since      File available since Release 0.1
22
 */
15
 */
23
 
16
 
24
/**
17
/**
25
 * Needed for error handling
18
 * Needed for error handling
26
 */
19
 */
27
require_once 'PEAR.php';
20
require_once 'PEAR.php';
28
require_once 'PEAR/Frontend.php';
21
require_once 'PEAR/Frontend.php';
29
require_once 'PEAR/XMLParser.php';
22
require_once 'PEAR/XMLParser.php';
30
 
23
 
31
/**
24
/**
32
 * List of commands and what classes they are implemented in.
25
 * List of commands and what classes they are implemented in.
33
 * @var array command => implementing class
26
 * @var array command => implementing class
34
 */
27
 */
35
$GLOBALS['_PEAR_Command_commandlist'] = array();
28
$GLOBALS['_PEAR_Command_commandlist'] = array();
36
 
29
 
37
/**
30
/**
38
 * List of commands and their descriptions
31
 * List of commands and their descriptions
39
 * @var array command => description
32
 * @var array command => description
40
 */
33
 */
41
$GLOBALS['_PEAR_Command_commanddesc'] = array();
34
$GLOBALS['_PEAR_Command_commanddesc'] = array();
42
 
35
 
43
/**
36
/**
44
 * List of shortcuts to common commands.
37
 * List of shortcuts to common commands.
45
 * @var array shortcut => command
38
 * @var array shortcut => command
46
 */
39
 */
47
$GLOBALS['_PEAR_Command_shortcuts'] = array();
40
$GLOBALS['_PEAR_Command_shortcuts'] = array();
48
 
41
 
49
/**
42
/**
50
 * Array of command objects
43
 * Array of command objects
51
 * @var array class => object
44
 * @var array class => object
52
 */
45
 */
53
$GLOBALS['_PEAR_Command_objects'] = array();
46
$GLOBALS['_PEAR_Command_objects'] = array();
54
 
47
 
55
/**
48
/**
56
 * PEAR command class, a simple factory class for administrative
49
 * PEAR command class, a simple factory class for administrative
57
 * commands.
50
 * commands.
58
 *
51
 *
59
 * How to implement command classes:
52
 * How to implement command classes:
60
 *
53
 *
61
 * - The class must be called PEAR_Command_Nnn, installed in the
54
 * - The class must be called PEAR_Command_Nnn, installed in the
62
 *   "PEAR/Common" subdir, with a method called getCommands() that
55
 *   "PEAR/Common" subdir, with a method called getCommands() that
63
 *   returns an array of the commands implemented by the class (see
56
 *   returns an array of the commands implemented by the class (see
64
 *   PEAR/Command/Install.php for an example).
57
 *   PEAR/Command/Install.php for an example).
65
 *
58
 *
66
 * - The class must implement a run() function that is called with three
59
 * - The class must implement a run() function that is called with three
67
 *   params:
60
 *   params:
68
 *
61
 *
69
 *    (string) command name
62
 *    (string) command name
70
 *    (array)  assoc array with options, freely defined by each
63
 *    (array)  assoc array with options, freely defined by each
71
 *             command, for example:
64
 *             command, for example:
72
 *             array('force' => true)
65
 *             array('force' => true)
73
 *    (array)  list of the other parameters
66
 *    (array)  list of the other parameters
74
 *
67
 *
75
 *   The run() function returns a PEAR_CommandResponse object.  Use
68
 *   The run() function returns a PEAR_CommandResponse object.  Use
76
 *   these methods to get information:
69
 *   these methods to get information:
77
 *
70
 *
78
 *    int getStatus()   Returns PEAR_COMMAND_(SUCCESS|FAILURE|PARTIAL)
71
 *    int getStatus()   Returns PEAR_COMMAND_(SUCCESS|FAILURE|PARTIAL)
79
 *                      *_PARTIAL means that you need to issue at least
72
 *                      *_PARTIAL means that you need to issue at least
80
 *                      one more command to complete the operation
73
 *                      one more command to complete the operation
81
 *                      (used for example for validation steps).
74
 *                      (used for example for validation steps).
82
 *
75
 *
83
 *    string getMessage()  Returns a message for the user.  Remember,
76
 *    string getMessage()  Returns a message for the user.  Remember,
84
 *                         no HTML or other interface-specific markup.
77
 *                         no HTML or other interface-specific markup.
85
 *
78
 *
86
 *   If something unexpected happens, run() returns a PEAR error.
79
 *   If something unexpected happens, run() returns a PEAR error.
87
 *
80
 *
88
 * - DON'T OUTPUT ANYTHING! Return text for output instead.
81
 * - DON'T OUTPUT ANYTHING! Return text for output instead.
89
 *
82
 *
90
 * - DON'T USE HTML! The text you return will be used from both Gtk,
83
 * - DON'T USE HTML! The text you return will be used from both Gtk,
91
 *   web and command-line interfaces, so for now, keep everything to
84
 *   web and command-line interfaces, so for now, keep everything to
92
 *   plain text.
85
 *   plain text.
93
 *
86
 *
94
 * - DON'T USE EXIT OR DIE! Always use pear errors.  From static
87
 * - DON'T USE EXIT OR DIE! Always use pear errors.  From static
95
 *   classes do PEAR::raiseError(), from other classes do
88
 *   classes do PEAR::raiseError(), from other classes do
96
 *   $this->raiseError().
89
 *   $this->raiseError().
97
 * @category   pear
90
 * @category   pear
98
 * @package    PEAR
91
 * @package    PEAR
99
 * @author     Stig Bakken <ssb@php.net>
92
 * @author     Stig Bakken <ssb@php.net>
100
 * @author     Greg Beaver <cellog@php.net>
93
 * @author     Greg Beaver <cellog@php.net>
101
 * @copyright  1997-2006 The PHP Group
94
 * @copyright  1997-2009 The Authors
102
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
95
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
103
 * @version    Release: 1.5.1
96
 * @version    Release: 1.10.1
104
 * @link       http://pear.php.net/package/PEAR
97
 * @link       http://pear.php.net/package/PEAR
105
 * @since      Class available since Release 0.1
98
 * @since      Class available since Release 0.1
106
 */
99
 */
107
class PEAR_Command
100
class PEAR_Command
108
{
101
{
109
    // {{{ factory()
102
    // {{{ factory()
110
 
103
 
111
    /**
104
    /**
112
     * Get the right object for executing a command.
105
     * Get the right object for executing a command.
113
     *
106
     *
114
     * @param string $command The name of the command
107
     * @param string $command The name of the command
115
     * @param object $config  Instance of PEAR_Config object
108
     * @param object $config  Instance of PEAR_Config object
116
     *
109
     *
117
     * @return object the command object or a PEAR error
110
     * @return object the command object or a PEAR error
118
     *
-
 
119
     * @access public
-
 
120
     * @static
-
 
121
     */
111
     */
122
    function &factory($command, &$config)
112
    public static function &factory($command, &$config)
123
    {
113
    {
124
        if (empty($GLOBALS['_PEAR_Command_commandlist'])) {
114
        if (empty($GLOBALS['_PEAR_Command_commandlist'])) {
125
            PEAR_Command::registerCommands();
115
            PEAR_Command::registerCommands();
126
        }
116
        }
127
        if (isset($GLOBALS['_PEAR_Command_shortcuts'][$command])) {
117
        if (isset($GLOBALS['_PEAR_Command_shortcuts'][$command])) {
128
            $command = $GLOBALS['_PEAR_Command_shortcuts'][$command];
118
            $command = $GLOBALS['_PEAR_Command_shortcuts'][$command];
129
        }
119
        }
130
        if (!isset($GLOBALS['_PEAR_Command_commandlist'][$command])) {
120
        if (!isset($GLOBALS['_PEAR_Command_commandlist'][$command])) {
131
            $a = PEAR::raiseError("unknown command `$command'");
121
            $a = PEAR::raiseError("unknown command `$command'");
132
            return $a;
122
            return $a;
133
        }
123
        }
134
        $class = $GLOBALS['_PEAR_Command_commandlist'][$command];
124
        $class = $GLOBALS['_PEAR_Command_commandlist'][$command];
135
        if (!class_exists($class)) {
125
        if (!class_exists($class)) {
136
            require_once $GLOBALS['_PEAR_Command_objects'][$class];
126
            require_once $GLOBALS['_PEAR_Command_objects'][$class];
137
        }
127
        }
138
        if (!class_exists($class)) {
128
        if (!class_exists($class)) {
139
            $a = PEAR::raiseError("unknown command `$command'");
129
            $a = PEAR::raiseError("unknown command `$command'");
140
            return $a;
130
            return $a;
141
        }
131
        }
142
        $ui =& PEAR_Command::getFrontendObject();
132
        $ui =& PEAR_Command::getFrontendObject();
143
        $obj = &new $class($ui, $config);
133
        $obj = new $class($ui, $config);
144
        return $obj;
134
        return $obj;
145
    }
135
    }
146
 
136
 
147
    // }}}
137
    // }}}
148
    // {{{ & getObject()
138
    // {{{ & getObject()
149
    function &getObject($command)
139
    public static function &getObject($command)
150
    {
140
    {
151
        $class = $GLOBALS['_PEAR_Command_commandlist'][$command];
141
        $class = $GLOBALS['_PEAR_Command_commandlist'][$command];
152
        if (!class_exists($class)) {
142
        if (!class_exists($class)) {
153
            require_once $GLOBALS['_PEAR_Command_objects'][$class];
143
            require_once $GLOBALS['_PEAR_Command_objects'][$class];
154
        }
144
        }
155
        if (!class_exists($class)) {
145
        if (!class_exists($class)) {
156
            return PEAR::raiseError("unknown command `$command'");
146
            return PEAR::raiseError("unknown command `$command'");
157
        }
147
        }
158
        $ui =& PEAR_Command::getFrontendObject();
148
        $ui =& PEAR_Command::getFrontendObject();
159
        $config = &PEAR_Config::singleton();
149
        $config = &PEAR_Config::singleton();
160
        $obj = &new $class($ui, $config);
150
        $obj = new $class($ui, $config);
161
        return $obj;
151
        return $obj;
162
    }
152
    }
163
 
153
 
164
    // }}}
154
    // }}}
165
    // {{{ & getFrontendObject()
155
    // {{{ & getFrontendObject()
166
 
156
 
167
    /**
157
    /**
168
     * Get instance of frontend object.
158
     * Get instance of frontend object.
169
     *
159
     *
170
     * @return object|PEAR_Error
160
     * @return object|PEAR_Error
171
     * @static
-
 
172
     */
161
     */
173
    function &getFrontendObject()
162
    public static function &getFrontendObject()
174
    {
163
    {
175
        $a = &PEAR_Frontend::singleton();
164
        $a = &PEAR_Frontend::singleton();
176
        return $a;
165
        return $a;
177
    }
166
    }
178
 
167
 
179
    // }}}
168
    // }}}
180
    // {{{ & setFrontendClass()
169
    // {{{ & setFrontendClass()
181
 
170
 
182
    /**
171
    /**
183
     * Load current frontend class.
172
     * Load current frontend class.
184
     *
173
     *
185
     * @param string $uiclass Name of class implementing the frontend
174
     * @param string $uiclass Name of class implementing the frontend
186
     *
175
     *
187
     * @return object the frontend object, or a PEAR error
176
     * @return object the frontend object, or a PEAR error
188
     * @static
-
 
189
     */
177
     */
190
    function &setFrontendClass($uiclass)
178
    public static function &setFrontendClass($uiclass)
191
    {
179
    {
192
        $a = &PEAR_Frontend::setFrontendClass($uiclass);
180
        $a = &PEAR_Frontend::setFrontendClass($uiclass);
193
        return $a;
181
        return $a;
194
    }
182
    }
195
 
183
 
196
    // }}}
184
    // }}}
197
    // {{{ setFrontendType()
185
    // {{{ setFrontendType()
198
 
186
 
199
    /**
187
    /**
200
     * Set current frontend.
188
     * Set current frontend.
201
     *
189
     *
202
     * @param string $uitype Name of the frontend type (for example "CLI")
190
     * @param string $uitype Name of the frontend type (for example "CLI")
203
     *
191
     *
204
     * @return object the frontend object, or a PEAR error
192
     * @return object the frontend object, or a PEAR error
205
     * @static
-
 
206
     */
193
     */
207
    function setFrontendType($uitype)
194
    public static function setFrontendType($uitype)
208
    {
195
    {
209
        $uiclass = 'PEAR_Frontend_' . $uitype;
196
        $uiclass = 'PEAR_Frontend_' . $uitype;
210
        return PEAR_Command::setFrontendClass($uiclass);
197
        return PEAR_Command::setFrontendClass($uiclass);
211
    }
198
    }
212
 
199
 
213
    // }}}
200
    // }}}
214
    // {{{ registerCommands()
201
    // {{{ registerCommands()
215
 
202
 
216
    /**
203
    /**
217
     * Scan through the Command directory looking for classes
204
     * Scan through the Command directory looking for classes
218
     * and see what commands they implement.
205
     * and see what commands they implement.
219
     *
206
     *
220
     * @param bool   (optional) if FALSE (default), the new list of
207
     * @param bool   (optional) if FALSE (default), the new list of
221
     *               commands should replace the current one.  If TRUE,
208
     *               commands should replace the current one.  If TRUE,
222
     *               new entries will be merged with old.
209
     *               new entries will be merged with old.
223
     *
210
     *
224
     * @param string (optional) where (what directory) to look for
211
     * @param string (optional) where (what directory) to look for
225
     *               classes, defaults to the Command subdirectory of
212
     *               classes, defaults to the Command subdirectory of
226
     *               the directory from where this file (__FILE__) is
213
     *               the directory from where this file (__FILE__) is
227
     *               included.
214
     *               included.
228
     *
215
     *
229
     * @return bool TRUE on success, a PEAR error on failure
216
     * @return bool TRUE on success, a PEAR error on failure
230
     *
-
 
231
     * @access public
-
 
232
     * @static
-
 
233
     */
217
     */
234
    function registerCommands($merge = false, $dir = null)
218
    public static function registerCommands($merge = false, $dir = null)
235
    {
219
    {
236
        $parser = new PEAR_XMLParser;
220
        $parser = new PEAR_XMLParser;
237
        if ($dir === null) {
221
        if ($dir === null) {
238
            $dir = dirname(__FILE__) . '/Command';
222
            $dir = dirname(__FILE__) . '/Command';
239
        }
223
        }
240
        if (!is_dir($dir)) {
224
        if (!is_dir($dir)) {
241
            return PEAR::raiseError("registerCommands: opendir($dir) '$dir' does not exist or is not a directory");
225
            return PEAR::raiseError("registerCommands: opendir($dir) '$dir' does not exist or is not a directory");
242
        }
226
        }
243
        $dp = @opendir($dir);
227
        $dp = @opendir($dir);
244
        if (empty($dp)) {
228
        if (empty($dp)) {
245
            return PEAR::raiseError("registerCommands: opendir($dir) failed");
229
            return PEAR::raiseError("registerCommands: opendir($dir) failed");
246
        }
230
        }
247
        if (!$merge) {
231
        if (!$merge) {
248
            $GLOBALS['_PEAR_Command_commandlist'] = array();
232
            $GLOBALS['_PEAR_Command_commandlist'] = array();
249
        }
233
        }
-
 
234
 
250
        while ($entry = readdir($dp)) {
235
        while ($file = readdir($dp)) {
251
            if ($entry{0} == '.' || substr($entry, -4) != '.xml') {
236
            if ($file{0} == '.' || substr($file, -4) != '.xml') {
252
                continue;
237
                continue;
253
            }
238
            }
-
 
239
 
254
            $class = "PEAR_Command_".substr($entry, 0, -4);
240
            $f = substr($file, 0, -4);
255
            $file = "$dir/$entry";
241
            $class = "PEAR_Command_" . $f;
256
            $parser->parse(file_get_contents($file));
-
 
257
            $implements = $parser->getData();
-
 
258
            // List of commands
242
            // List of commands
259
            if (empty($GLOBALS['_PEAR_Command_objects'][$class])) {
243
            if (empty($GLOBALS['_PEAR_Command_objects'][$class])) {
260
                $GLOBALS['_PEAR_Command_objects'][$class] = "$dir/" . substr($entry, 0, -4) .
244
                $GLOBALS['_PEAR_Command_objects'][$class] = "$dir/" . $f . '.php';
261
                    '.php';
-
 
262
            }
245
            }
-
 
246
 
-
 
247
            $parser->parse(file_get_contents("$dir/$file"));
-
 
248
            $implements = $parser->getData();
263
            foreach ($implements as $command => $desc) {
249
            foreach ($implements as $command => $desc) {
264
                if ($command == 'attribs') {
250
                if ($command == 'attribs') {
265
                    continue;
251
                    continue;
266
                }
252
                }
-
 
253
 
267
                if (isset($GLOBALS['_PEAR_Command_commandlist'][$command])) {
254
                if (isset($GLOBALS['_PEAR_Command_commandlist'][$command])) {
268
                    return PEAR::raiseError('Command "' . $command . '" already registered in ' .
255
                    return PEAR::raiseError('Command "' . $command . '" already registered in ' .
269
                        'class "' . $GLOBALS['_PEAR_Command_commandlist'][$command] . '"');
256
                        'class "' . $GLOBALS['_PEAR_Command_commandlist'][$command] . '"');
270
                }
257
                }
-
 
258
 
271
                $GLOBALS['_PEAR_Command_commandlist'][$command] = $class;
259
                $GLOBALS['_PEAR_Command_commandlist'][$command] = $class;
272
                $GLOBALS['_PEAR_Command_commanddesc'][$command] = $desc['summary'];
260
                $GLOBALS['_PEAR_Command_commanddesc'][$command] = $desc['summary'];
273
                if (isset($desc['shortcut'])) {
261
                if (isset($desc['shortcut'])) {
274
                    $shortcut = $desc['shortcut'];
262
                    $shortcut = $desc['shortcut'];
275
                    if (isset($GLOBALS['_PEAR_Command_shortcuts'][$shortcut])) {
263
                    if (isset($GLOBALS['_PEAR_Command_shortcuts'][$shortcut])) {
276
                        return PEAR::raiseError('Command shortcut "' . $shortcut . '" already ' .
264
                        return PEAR::raiseError('Command shortcut "' . $shortcut . '" already ' .
277
                            'registered to command "' . $command . '" in class "' .
265
                            'registered to command "' . $command . '" in class "' .
278
                            $GLOBALS['_PEAR_Command_commandlist'][$command] . '"');
266
                            $GLOBALS['_PEAR_Command_commandlist'][$command] . '"');
279
                    }
267
                    }
280
                    $GLOBALS['_PEAR_Command_shortcuts'][$shortcut] = $command;
268
                    $GLOBALS['_PEAR_Command_shortcuts'][$shortcut] = $command;
281
                }
269
                }
-
 
270
 
282
                if (isset($desc['options']) && $desc['options']) {
271
                if (isset($desc['options']) && $desc['options']) {
283
                    foreach ($desc['options'] as $oname => $option) {
272
                    foreach ($desc['options'] as $oname => $option) {
284
                        if (isset($option['shortopt']) && strlen($option['shortopt']) > 1) {
273
                        if (isset($option['shortopt']) && strlen($option['shortopt']) > 1) {
285
                            return PEAR::raiseError('Option "' . $oname . '" short option "' .
274
                            return PEAR::raiseError('Option "' . $oname . '" short option "' .
286
                                $option['shortopt'] . '" must be ' .
275
                                $option['shortopt'] . '" must be ' .
287
                                'only 1 character in Command "' . $command . '" in class "' .
276
                                'only 1 character in Command "' . $command . '" in class "' .
288
                                $class . '"');
277
                                $class . '"');
289
                        }
278
                        }
290
                    }
279
                    }
291
                }
280
                }
292
            }
281
            }
293
        }
282
        }
-
 
283
 
294
        ksort($GLOBALS['_PEAR_Command_shortcuts']);
284
        ksort($GLOBALS['_PEAR_Command_shortcuts']);
295
        ksort($GLOBALS['_PEAR_Command_commandlist']);
285
        ksort($GLOBALS['_PEAR_Command_commandlist']);
296
        @closedir($dp);
286
        @closedir($dp);
297
        return true;
287
        return true;
298
    }
288
    }
299
 
289
 
300
    // }}}
290
    // }}}
301
    // {{{ getCommands()
291
    // {{{ getCommands()
302
 
292
 
303
    /**
293
    /**
304
     * Get the list of currently supported commands, and what
294
     * Get the list of currently supported commands, and what
305
     * classes implement them.
295
     * classes implement them.
306
     *
296
     *
307
     * @return array command => implementing class
297
     * @return array command => implementing class
308
     *
-
 
309
     * @access public
-
 
310
     * @static
-
 
311
     */
298
     */
312
    function getCommands()
299
    public static function getCommands()
313
    {
300
    {
314
        if (empty($GLOBALS['_PEAR_Command_commandlist'])) {
301
        if (empty($GLOBALS['_PEAR_Command_commandlist'])) {
315
            PEAR_Command::registerCommands();
302
            PEAR_Command::registerCommands();
316
        }
303
        }
317
        return $GLOBALS['_PEAR_Command_commandlist'];
304
        return $GLOBALS['_PEAR_Command_commandlist'];
318
    }
305
    }
319
 
306
 
320
    // }}}
307
    // }}}
321
    // {{{ getShortcuts()
308
    // {{{ getShortcuts()
322
 
309
 
323
    /**
310
    /**
324
     * Get the list of command shortcuts.
311
     * Get the list of command shortcuts.
325
     *
312
     *
326
     * @return array shortcut => command
313
     * @return array shortcut => command
327
     *
-
 
328
     * @access public
-
 
329
     * @static
-
 
330
     */
314
     */
331
    function getShortcuts()
315
    public static function getShortcuts()
332
    {
316
    {
333
        if (empty($GLOBALS['_PEAR_Command_shortcuts'])) {
317
        if (empty($GLOBALS['_PEAR_Command_shortcuts'])) {
334
            PEAR_Command::registerCommands();
318
            PEAR_Command::registerCommands();
335
        }
319
        }
336
        return $GLOBALS['_PEAR_Command_shortcuts'];
320
        return $GLOBALS['_PEAR_Command_shortcuts'];
337
    }
321
    }
338
 
322
 
339
    // }}}
323
    // }}}
340
    // {{{ getGetoptArgs()
324
    // {{{ getGetoptArgs()
341
 
325
 
342
    /**
326
    /**
343
     * Compiles arguments for getopt.
327
     * Compiles arguments for getopt.
344
     *
328
     *
345
     * @param string $command     command to get optstring for
329
     * @param string $command     command to get optstring for
346
     * @param string $short_args  (reference) short getopt format
330
     * @param string $short_args  (reference) short getopt format
347
     * @param array  $long_args   (reference) long getopt format
331
     * @param array  $long_args   (reference) long getopt format
348
     *
332
     *
349
     * @return void
333
     * @return void
350
     *
-
 
351
     * @access public
-
 
352
     * @static
-
 
353
     */
334
     */
354
    function getGetoptArgs($command, &$short_args, &$long_args)
335
    public static function getGetoptArgs($command, &$short_args, &$long_args)
355
    {
336
    {
356
        if (empty($GLOBALS['_PEAR_Command_commandlist'])) {
337
        if (empty($GLOBALS['_PEAR_Command_commandlist'])) {
357
            PEAR_Command::registerCommands();
338
            PEAR_Command::registerCommands();
358
        }
339
        }
359
        if (isset($GLOBALS['_PEAR_Command_shortcuts'][$command])) {
340
        if (isset($GLOBALS['_PEAR_Command_shortcuts'][$command])) {
360
            $command = $GLOBALS['_PEAR_Command_shortcuts'][$command];
341
            $command = $GLOBALS['_PEAR_Command_shortcuts'][$command];
361
        }
342
        }
362
        if (!isset($GLOBALS['_PEAR_Command_commandlist'][$command])) {
343
        if (!isset($GLOBALS['_PEAR_Command_commandlist'][$command])) {
363
            return null;
344
            return null;
364
        }
345
        }
365
        $obj = &PEAR_Command::getObject($command);
346
        $obj = &PEAR_Command::getObject($command);
366
        return $obj->getGetoptArgs($command, $short_args, $long_args);
347
        return $obj->getGetoptArgs($command, $short_args, $long_args);
367
    }
348
    }
368
 
349
 
369
    // }}}
350
    // }}}
370
    // {{{ getDescription()
351
    // {{{ getDescription()
371
 
352
 
372
    /**
353
    /**
373
     * Get description for a command.
354
     * Get description for a command.
374
     *
355
     *
375
     * @param  string $command Name of the command
356
     * @param  string $command Name of the command
376
     *
357
     *
377
     * @return string command description
358
     * @return string command description
378
     *
-
 
379
     * @access public
-
 
380
     * @static
-
 
381
     */
359
     */
382
    function getDescription($command)
360
    public static function getDescription($command)
383
    {
361
    {
384
        if (!isset($GLOBALS['_PEAR_Command_commanddesc'][$command])) {
362
        if (!isset($GLOBALS['_PEAR_Command_commanddesc'][$command])) {
385
            return null;
363
            return null;
386
        }
364
        }
387
        return $GLOBALS['_PEAR_Command_commanddesc'][$command];
365
        return $GLOBALS['_PEAR_Command_commanddesc'][$command];
388
    }
366
    }
389
 
367
 
390
    // }}}
368
    // }}}
391
    // {{{ getHelp()
369
    // {{{ getHelp()
392
 
370
 
393
    /**
371
    /**
394
     * Get help for command.
372
     * Get help for command.
395
     *
373
     *
396
     * @param string $command Name of the command to return help for
374
     * @param string $command Name of the command to return help for
397
     *
-
 
398
     * @access public
-
 
399
     * @static
-
 
400
     */
375
     */
401
    function getHelp($command)
376
    public static function getHelp($command)
402
    {
377
    {
403
        $cmds = PEAR_Command::getCommands();
378
        $cmds = PEAR_Command::getCommands();
404
        if (isset($GLOBALS['_PEAR_Command_shortcuts'][$command])) {
379
        if (isset($GLOBALS['_PEAR_Command_shortcuts'][$command])) {
405
            $command = $GLOBALS['_PEAR_Command_shortcuts'][$command];
380
            $command = $GLOBALS['_PEAR_Command_shortcuts'][$command];
406
        }
381
        }
407
        if (isset($cmds[$command])) {
382
        if (isset($cmds[$command])) {
408
            $obj = &PEAR_Command::getObject($command);
383
            $obj = &PEAR_Command::getObject($command);
409
            return $obj->getHelp($command);
384
            return $obj->getHelp($command);
410
        }
385
        }
411
        return false;
386
        return false;
412
    }
387
    }
413
    // }}}
388
    // }}}
414
}
389
}
415
 
-
 
416
?>
-