Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
#!/usr/bin/php
2
<?php
3
/**
4
 * This is an example with Console_Getoptplus::getoptplus() set to return
5
 * an associative array with option names converted to their long names if possible.
6
 *
7
 * Examples to run on the command line:
8
 * #getoptplusa --help
9
 * #getoptplusa -h
10
 * #getoptplusa --foo -b car -c
11
 * #getoptplusa --foo -b car -c param1
12
 * #getoptplusa --foo -b car -cbus param1
13
 * #getoptplusa --foo -b car -c=bus param1
14
 * #getoptplusa --bar car param1 param2
15
 * #getoptplusa --bar car -- param1 param2
16
 * #getoptplusa --bar=car param1 param2
17
 */
18
 
19
require_once 'Console/GetoptPlus.php';
20
 
21
try {
22
    $config = array(// /
23
        'options' => array(// /
24
            array('long' => 'foo', 'type' => 'noarg',
25
                'desc' => array('An option without argument with only the long', 'name defined.')),
26
            array('long' => 'bar', 'type' => 'mandatory', 'short' => 'b',
27
                'desc' => array('arg', 'A mandatory option with both the long and', 'the short names defined.')),
28
            array('short' => 'c', 'type' => 'optional',
29
                'desc' => array('arg', 'An option with an optional argument with only', 'the short name defined.'))),
30
        'parameters' => array('[param1] [param2]', 'Some additional parameters.'),
31
        );
32
 
33
    $options = Console_Getoptplus::getoptplus($config, 'short2long', true);
34
    print_r($options);
35
}
36
catch(Console_GetoptPlus_Exception $e) {
37
    $error = array($e->getCode(), $e->getMessage());
38
    print_r($error);
39
}
40
 
41
?>