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