#!/usr/bin/env php
<?php
use Dotenv\Dotenv;
use Symfony\Component\Console\Application;

require_once(__DIR__.'/utils/bootstrap.php');

/**
 * CLI Codeigniter Crafstman
 *
 * @author     David Sosa Valdes <https://github.com/davidsosavaldes>
 * @license    MIT License
 * @link       https://github.com/davidsosavaldes/Craftsman
 * @copyright  Copyright (c) 2016, David Sosa Valdes.
 */
try {
	$dotenv = new Dotenv(getcwd(), '.craftsman');
	$dotenv->load();
	$dotenv->required(['VENDOR_PATH','CI_APPPATH'])->notEmpty();

	define('CRAFTSMANPATH', __DIR__.'/');

} catch (Exception $e) {
	exit(preg_replace('/\s+/', ' ', $e->getMessage()));
}

$generators = [
	new Craftsman\Commands\Generators\Controller,
	new Craftsman\Commands\Generators\Model,
	new Craftsman\Commands\Generators\Migration,
	new Craftsman\Commands\Generators\Seeder
];

$migrations = [
	new Craftsman\Commands\Migrations\Info,
	new Craftsman\Commands\Migrations\Version,
	new Craftsman\Commands\Migrations\Latest,
	new Craftsman\Commands\Migrations\Rollback,
	new Craftsman\Commands\Migrations\Reset,
	new Craftsman\Commands\Migrations\Refresh
];

$general = [
	new Craftsman\Commands\Serve,
	new Craftsman\Commands\Console,
	new Craftsman\Commands\Notes,
	new Craftsman\Commands\Seeder
];

// Set the commands
$commands = array_merge($generators, $migrations, $general);

$application = new Application('Craftsman', '4.2.3');
// Add the default commands
foreach ($commands as $key => $command) {
	$application->add($command);
}
$application->run();
