7 * @author Masaki Fujimoto <fujimoto@php.net>
8 * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
12 while (ob_get_level()) {
16 require_once 'PEAR.php';
17 require_once 'Console/Getopt.php';
19 // setup path seprator
20 if (!defined('PATH_SEPARATOR')) {
22 /** include_path separator(Windows) */
23 define('PATH_SEPARATOR', ';');
25 /** include_path separator(Unix) */
26 define('PATH_SEPARATOR', ':');
29 $base = dirname(dirname(dirname(__FILE__)));
30 ini_set('include_path', "$base" . PATH_SEPARATOR . ini_get('include_path'));
32 require_once 'Ethna/Ethna.php';
35 $getopt =& new Console_Getopt();
36 $arg_list = $getopt->readPHPArgv();
37 array_shift($arg_list);
39 $eh =& new Ethna_Handle();
41 list($my_arg_list, $arg_list) = _Ethna_HandleGateway_SeparateArgList($arg_list);
42 $r = $getopt->getopt($my_arg_list, "v", array("version"));
43 if (Ethna::isError($r)) {
49 foreach ($r[0] as $opt) {
50 if ($opt[0] == "v" || $opt[0] == "--version") {
51 _Ethna_HandleGateway_ShowVersion();
56 if (count($arg_list) == 0) {
61 $id = array_shift($arg_list);
63 $handler =& $eh->getHandler($id);
64 if (Ethna::isError($handler)) {
65 printf("no such command: %s\n\n", $id);
70 // don't know what will happen:)
71 $handler->setArgList($arg_list);
72 $r = $handler->perform();
73 if (Ethna::isError($r)) {
74 printf("error occured w/ command [%s]\n -> %s\n\n", $id, $r->getMessage());
75 if ($r->getCode() == 'usage') {
86 $handler_list = $eh->getHandlerList();
87 printf("usage: ethna [option] [command] [args...]\n\n");
88 printf("available options are as follows:\n\n");
89 printf(" -v, --version show version and exit\n");
90 printf("\navailable commands are as follows:\n\n");
91 foreach ($handler_list as $handler) {
92 printf(" %s -> %s\n", $handler->getId(), $handler->getDescription());
97 * fetch options for myself
99 function _Ethna_HandleGateway_SeparateArgList($arg_list)
101 $my_arg_list = array();
102 for ($i = 0; $i < count($arg_list); $i++) {
103 if ($arg_list[$i]{0} == '-') {
104 // assume this should be an option for myself
105 $my_arg_list[] = $arg_list[$i];
110 $arg_list = array_slice($arg_list, $i);
112 return array($my_arg_list, $arg_list);
118 function _Ethna_HandleGateway_ShowVersion()
123 Copyright (c) 2004-2006,
124 Masaki Fujimoto <fujimoto@php.net>
125 halt feits <halt.feits@gmail.com>
126 Takuya Ookubo <sfio@sakura.ai.to>
127 nozzzzz <nozzzzz@gmail.com>
128 cocoitiban <cocoiti@comio.info>
133 printf($version, ETHNA_VERSION);