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 // setup path seprator
17 if (!defined('PATH_SEPARATOR')) {
19 /** include_path separator(Windows) */
20 define('PATH_SEPARATOR', ';');
22 /** include_path separator(Unix) */
23 define('PATH_SEPARATOR', ':');
26 $base = dirname(dirname(dirname(__FILE__)));
27 ini_set('include_path', $base.PATH_SEPARATOR.ini_get('include_path'));
29 require_once 'PEAR.php';
30 require_once 'Console/Getopt.php';
31 require_once 'Ethna/Ethna.php';
34 $arg_list = Console_Getopt::readPHPArgv();
35 if (Ethna::isError($arg_list)) {
36 echo $arg_list->getMessage()."\n";
39 array_shift($arg_list);
41 $eh =& new Ethna_Handle();
43 list($my_arg_list, $arg_list) = _Ethna_HandleGateway_SeparateArgList($arg_list);
44 $r = Console_Getopt::getopt($my_arg_list, "v", array("version"));
45 if (Ethna::isError($r)) {
51 foreach ($r[0] as $opt) {
52 if ($opt[0] == "v" || $opt[0] == "--version") {
53 _Ethna_HandleGateway_ShowVersion();
58 if (count($arg_list) == 0) {
63 $id = array_shift($arg_list);
65 $handler =& $eh->getHandler($id);
66 if (Ethna::isError($handler)) {
67 printf("no such command: %s\n\n", $id);
72 // don't know what will happen:)
73 $handler->setArgList($arg_list);
74 $r = $handler->perform();
75 if (Ethna::isError($r)) {
76 printf("error occured w/ command [%s]\n -> %s\n\n", $id, $r->getMessage());
77 if ($r->getCode() == 'usage') {
88 $handler_list = $eh->getHandlerList();
89 printf("usage: ethna [option] [command] [args...]\n\n");
90 printf("available options are as follows:\n\n");
91 printf(" -v, --version show version and exit\n");
92 printf("\navailable commands are as follows:\n\n");
93 foreach ($handler_list as $handler) {
94 printf(" %s -> %s\n", $handler->getId(), $handler->getDescription());
99 * fetch options for myself
101 function _Ethna_HandleGateway_SeparateArgList($arg_list)
103 $my_arg_list = array();
104 for ($i = 0; $i < count($arg_list); $i++) {
105 if ($arg_list[$i]{0} == '-') {
106 // assume this should be an option for myself
107 $my_arg_list[] = $arg_list[$i];
112 $arg_list = array_slice($arg_list, $i);
114 return array($my_arg_list, $arg_list);
120 function _Ethna_HandleGateway_ShowVersion()
125 Copyright (c) 2004-2006,
126 Masaki Fujimoto <fujimoto@php.net>
127 halt feits <halt.feits@gmail.com>
128 Takuya Ookubo <sfio@sakura.ai.to>
129 nozzzzz <nozzzzz@gmail.com>
130 cocoitiban <cocoiti@comio.info>
135 printf($version, ETHNA_VERSION);