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

require __DIR__.'/../vendor/autoload.php';

use Symfony\Component\Console\Application;
use Symfony\Component\Finder\Finder;

// -----------------------------------------------------------------------------

$app = new Application;
// scaning commands
$finder = new Finder;
$finder->files()->in(__DIR__.'/command')->name('*Command.php');
foreach ($finder as $file) {
    $content = $file->getContents();
    $namespace = null;
    if (preg_match('/namespace ([\w\\\\]+)/', $content, $matches)) {
        $namespace = $matches[1].'\\';
    }
    $class = $file->getBasename('.php');
    $command = $namespace . $class;
    $app->add(new $command);
}
$finder = null;
unset($content, $finder, $config, $basePath);
$app->run();