#!/usr/bin/env php
<?php

use EasySwoole\Command\Caller;
use EasySwoole\Command\CommandManager;
use EasySwoole\HttpAnnotation\Utility\DocCommand;

$file = null;
foreach ([ __DIR__ . '/../../../autoload.php', __DIR__ . '/../vendor/autoload.php' ] as $file) {
    if (file_exists($file)) {
        require $file;
        break;
    }
}
if(!file_exists($file)){
    die("include composer autoload.php fail\n");
}

$command = new DocCommand();
CommandManager::getInstance()->addCommand($command);

array_splice($argv, 1, 0, $command->commandName());
$caller = new Caller();
$caller->setScript(current($argv));
$caller->setCommand(next($argv));
$caller->setParams($argv);
reset($argv);
echo CommandManager::getInstance()->run($caller);