PEAR2_Console_CommandLine › PEAR2_Console_CommandLine-0.2.0/doc/pear2.php.net/PEAR2_Console_CommandLine/examples/examples/ex3.php
- PEAR2_Console_CommandLine-0.2.0/
- data/
- pear2.php.net/
- PEAR2_Console_CommandLine/
- pear2.php.net/
- doc/
- php/
- PEAR2/
- Autoload.php
- Console/
- CommandLine/
- Action/
- Action.php
- Argument.php
- Command.php
- CustomMessageProvider.php
- Element.php
- Exception.php
- MessageProvider/
- MessageProvider.php
- Option.php
- Outputter/
- Outputter.php
- Renderer/
- Renderer.php
- Result.php
- XmlParser.php
- CommandLine.php
- CommandLine/
- Exception.php
- MultiErrors/
- MultiErrors.php
- PEAR2/
- test/
- pear2.php.net/
- PEAR2_Console_CommandLine/
- AllTests.php
- console_commandline_accept.phpt
- console_commandline_addargument.phpt
- console_commandline_addargument2.phpt
- console_commandline_addcommand.phpt
- console_commandline_addcommand_3.phpt
- console_commandline_addoption.phpt
- console_commandline_addoption_errors_1.phpt
- console_commandline_addoption_errors_2.phpt
- console_commandline_addoption_errors_3.phpt
- console_commandline_addoption_errors_4.phpt
- console_commandline_addoption_errors_5.phpt
- console_commandline_addoption_errors_6.phpt
- console_commandline_addoption_errors_7.phpt
- console_commandline_fromxmlfile.phpt
- console_commandline_fromxmlfile_error.phpt
- console_commandline_fromxmlstring.phpt
- console_commandline_options_defaults.phpt
- console_commandline_parse_1.phpt
- console_commandline_parse_10.phpt
- console_commandline_parse_11.phpt
- console_commandline_parse_12.phpt
- console_commandline_parse_13.phpt
- console_commandline_parse_14.phpt
- console_commandline_parse_15.phpt
- console_commandline_parse_16.phpt
- console_commandline_parse_17.phpt
- console_commandline_parse_18.phpt
- console_commandline_parse_19.phpt
- console_commandline_parse_2.phpt
- console_commandline_parse_20.phpt
- console_commandline_parse_21.phpt
- console_commandline_parse_22.phpt
- console_commandline_parse_23.phpt
- console_commandline_parse_24.phpt
- console_commandline_parse_25.phpt
- console_commandline_parse_26.phpt
- console_commandline_parse_27.phpt
- console_commandline_parse_28.phpt
- console_commandline_parse_29.phpt
- console_commandline_parse_3.phpt
- console_commandline_parse_4.phpt
- console_commandline_parse_5.phpt
- console_commandline_parse_6.phpt
- console_commandline_parse_7.phpt
- console_commandline_parse_8.phpt
- console_commandline_parse_9.phpt
- console_commandline_webrequest_1.phpt
- console_commandline_webrequest_2.phpt
- console_commandline_webrequest_3.phpt
- test.xml
- tests.inc.php
- PEAR2_Console_CommandLine/
- pear2.php.net/
- data/
- package.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* This file is part of the PEAR PEAR2_Console_CommandLine package.
*
* A simple example demonstrating the use of subcommands.
*
* PHP version 5
*
* LICENSE: This source file is subject to the MIT license that is available
* through the world-wide-web at the following URI:
* http://opensource.org/licenses/mit-license.php
*
* @category Console
* @package PEAR2_Console_CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
* @version CVS: $Id: ex3.php,v 1.1 2008/12/06 11:46:28 izi Exp $
* @link http://pear.php.net/package/Console_CommandLine
* @since File available since release 0.1.0
*/
// uncomment this when package won't be in the SandBox anymore
// $basedir = __DIR__ . '/../..';
$basedir = __DIR__ . '/../../..';
// Include PEAR2 autoload
require_once $basedir . '/autoload.php';
// create the parser
$parser = new PEAR2_Console_CommandLine(array(
'description' => 'A great program that can foo and bar !',
'version' => '1.0.0'
));
// add a global option to make the program verbose
$parser->addOption('verbose', array(
'short_name' => '-v',
'long_name' => '--verbose',
'action' => 'StoreTrue',
'description' => 'turn on verbose output'
));
// add the foo subcommand
$foo_cmd = $parser->addCommand('foo', array(
'description' => 'output the given string with a foo prefix'
));
$foo_cmd->addOption('reverse', array(
'short_name' => '-r',
'long_name' => '--reverse',
'action' => 'StoreTrue',
'description' => 'reverse the given string before echoing it'
));
$foo_cmd->addArgument('text', array(
'description' => 'the text to output'
));
// add the bar subcommand with a "baz" alias
$bar_cmd = $parser->addCommand('bar', array(
'description' => 'output the given string with a bar prefix',
'aliases' => array('baz'),
));
$bar_cmd->addOption('reverse', array(
'short_name' => '-r',
'long_name' => '--reverse',
'action' => 'StoreTrue',
'description' => 'reverse the given string before echoing it'
));
$bar_cmd->addArgument('text', array(
'description' => 'the text to output'
));
// run the parser
try {
$result = $parser->parse();
if ($result->command_name) {
$st = $result->command->options['reverse']
? strrev($result->command->args['text'])
: $result->command->args['text'];
if ($result->command_name == 'foo') {
echo "Foo says: $st\n";
} else if ($result->command_name == 'bar') {
echo "Bar says: $st\n";
}
}
} catch (Exception $exc) {
$parser->displayError($exc->getMessage());
}
?>
EOF
