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

use Phalcon\Cli\Dispatcher;
use Phalcon\Cli\Router;
use Phalcon\Config;
use PhalconExt\Cli\Console;
use PhalconExt\Example\MainTask;
use PhalconExt\Example\OtherTask;

// Di instance can be same as for web app!
$di  = require __DIR__ . '/bootstrap.php';

// But here we use cli router, dispatcher and writer!
$di->setShared('dispatcher', Dispatcher::class);
$di->setShared('router', Router::class);

$di->get('config')->merge(new Config([
    // You might want to have console config in some file
    'console' => [
        'tasks' => [
            // Name => FQCN
            'main'  => MainTask::class,
            'other' => OtherTask::class,
        ],
    ],
]));

$cli = new Console($di, 'ExampleApp', '0.0.1');

try {
    $cli->handle($_SERVER['argv']);
} catch (\Throwable $e) {
    $di->get('interactor')->eol()
        ->errorBold($e->getMessage(), true)
        ->comment($e->getTraceAsString(), true);

    exit(255);
}
