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()
5
 *
6
 * Examples to run on the command line:
7
 * #getoptplus --help
8
 * #getoptplus -h
9
 * #getoptplus --foo -b car -c
10
 * #getoptplus --foo -b car -c param1
11
 * #getoptplus --foo -b car -cbus param1
12
 * #getoptplus --foo -b car -c=bus param1
13
 * #getoptplus --bar car param1 param2
14
 * #getoptplus --bar car -- param1 param2
15
 * #getoptplus --bar=car param1 param2
16
 */
17
 
18
require_once 'Console/GetoptPlus.php';
19
 
20
try {
21
    $config = array(// /
22
        'options' => array(// /
23
            array('long' => 'foo', 'type' => 'noarg',
24
                'desc' => array('An option without argument with only the long', 'name defined.')),
25
            array('long' => 'bar', 'type' => 'mandatory', 'short' => 'b',
26
                'desc' => array('arg', 'A mandatory option with both the long and', 'the short names defined.')),
27
            array('short' => 'c', 'type' => 'optional',
28
                'desc' => array('arg', 'An option with an optional argument with only', 'the short name defined.'))),
29
        'parameters' => array('[param1] [param2]', 'Some additional parameters.'),
30
        );
31
    // "--help" exits and displays the usage
32
    $options = Console_Getoptplus::getoptplus($config);
33
    // "-help" is returned as an array
34
    // $options = Console_Getoptplus::getoptplus($config, null, true, null, false);
35
    print_r($options);
36
}
37
catch(Console_GetoptPlus_Exception $e) {
38
    $error = array($e->getCode(), $e->getMessage());
39
    print_r($error);
40
}
41
 
42
?>