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

if (php_sapi_name() !== 'cli') {
    exit;
}

use Minicli\App;
use Minicli\Exception\CommandNotFoundException;

$root_app = dirname(__DIR__);

if (!is_file($root_app . '/vendor/autoload.php')) {
    $root_app = dirname(__DIR__, 4);
}

require $root_app . '/vendor/autoload.php';

$gdaisy = new App([
    'app_debug' => false,
    'app_path' => __DIR__ . '/command',
    'default_template' => __DIR__ . '/../resources/templates/cover-default.json',
]);

$signature = <<<EOD
  .-_'''-.    ______        ____    .-./`)    .-'''-.    ____     __  
 '_( )_   \  |    _ `''.  .'  __ `. \ .-.')  / _     \   \   \   /  / 
|(_ o _)|  ' | _ | ) _  \/   '  \  \/ `-' \ (`' )/`--'    \  _. /  '  
. (_,_)/___| |( ''_'  ) ||___|  /  | `-'`"`(_ o _).        _( )_ .'   
|  |  .-----.| . (_) `. |   _.-`   | .---.  (_,_). '.  ___(_ o _)'    
'  \  '-   .'|(_    ._) '.'   _    | |   | .---.  \  :|   |(_,_)'     
 \  `-'`   | |  (_.\.' / |  _( )_  | |   | \    `-'  ||   `-'  /      
  \        / |       .'  \ (_ o _) / |   |  \       /  \      /       
   `'-...-'  '-----'`     '.(_,_).'  '---'   `-...-'    `-..-'  
                  
                  ./vendor/bin/gdaisy help
                  
EOD;
$gdaisy->setSignature($signature);

try {
    $gdaisy->runCommand($argv);
} catch (CommandNotFoundException $notFoundException) {
    $gdaisy->getPrinter()->error("Command Not Found.");
    return 1;
} catch (Exception $exception) {
    if ($gdaisy->config->debug) {
        $gdaisy->getPrinter()->error("An error occurred:");
        $gdaisy->getPrinter()->error($exception->getMessage());
    }
    return 1;
}