ob_end_clean();
}
-include_once('PEAR.php');
-include_once('Console/Getopt.php');
-
-// setup path seprator
-if (!defined('PATH_SEPARATOR')) {
- if (OS_WINDOWS) {
- /** include_path separator(Windows) */
- define('PATH_SEPARATOR', ';');
- } else {
- /** include_path separator(Unix) */
- define('PATH_SEPARATOR', ':');
- }
-}
$base = dirname(dirname(dirname(__FILE__)));
-ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . "$base");
+ini_set('include_path', $base.PATH_SEPARATOR.ini_get('include_path'));
-include_once('Ethna/Ethna.php');
+require_once 'Ethna/Ethna.php';
+require_once ETHNA_BASE . '/class/Ethna_Getopt.php';
// fetch arguments
-$getopt =& new Console_Getopt();
-$arg_list = $getopt->readPHPArgv();
-array_shift($arg_list);
+$opt = new Ethna_Getopt();
+$arg_list = $opt->readPHPArgv();
+if (Ethna::isError($arg_list)) {
+ echo $arg_list->getMessage()."\n";
+ exit(2);
+}
+array_shift($arg_list); // remove "ethna_handle.php"
$eh =& new Ethna_Handle();
+// はじめの引数に - が含まれていればそれを分離する
+// 含まれていた場合、それは -v|--version でなければならない
list($my_arg_list, $arg_list) = _Ethna_HandleGateway_SeparateArgList($arg_list);
-$r = $getopt->getopt($my_arg_list, "v", array("version"));
+$r = $opt->getopt($my_arg_list, "v", array("version"));
if (Ethna::isError($r)) {
- usage($eh);
+ _Ethna_HandleGateway_ShowUsage();
exit(1);
}
}
if (count($arg_list) == 0) {
- usage($eh);
- exit(1);
+ $id = 'help';
+} else {
+ $id = array_shift($arg_list);
}
-$id = array_shift($arg_list);
-
$handler =& $eh->getHandler($id);
+$handler->eh =& $eh;
if (Ethna::isError($handler)) {
printf("no such command: %s\n\n", $id);
- usage($eh);
- exit(1);
+ $id = 'help';
+ $handler =& $eh->getHandler($id);
+ $handler->eh =& $eh;
+ if (Ethna::isError($handler)) {
+ exit(1); // should not happen.
+ }
}
// don't know what will happen:)
}
/**
- * usage
- */
-function usage(&$eh)
-{
- $handler_list = $eh->getHandlerList();
- printf("usage: ethna [option] [command] [args...]\n\n");
- printf("available options are as follows:\n\n");
- printf(" -v, --version show version and exit\n");
- printf("\navailable commands are as follows:\n\n");
- foreach ($handler_list as $handler) {
- printf(" %s -> %s\n", $handler->getId(), $handler->getDescription());
- }
-}
-
-/**
* fetch options for myself
*/
function _Ethna_HandleGateway_SeparateArgList($arg_list)
{
$my_arg_list = array();
+
+ // はじめの引数に - が含まれていたら、
+ // それを $my_arg_list に入れる
+ // これは --version 判定のため
for ($i = 0; $i < count($arg_list); $i++) {
if ($arg_list[$i]{0} == '-') {
// assume this should be an option for myself
function _Ethna_HandleGateway_ShowVersion()
{
$version = <<<EOD
-Ethna %s
+Ethna %s (using PHP %s)
-Copyright (c) 2004-2006,
+Copyright (c) 2004-%s,
Masaki Fujimoto <fujimoto@php.net>
halt feits <halt.feits@gmail.com>
Takuya Ookubo <sfio@sakura.ai.to>
nozzzzz <nozzzzz@gmail.com>
cocoitiban <cocoiti@comio.info>
+ Yoshinari Takaoka <takaoka@beatcraft.com>
http://ethna.jp/
EOD;
- printf($version, ETHNA_VERSION);
+ printf($version, ETHNA_VERSION, PHP_VERSION, date('Y'));
}
-?>