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

// Basic CLI actions for PHP Mini Framework

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

use App\Core\CLI;

$cli = new CLI();

//print_r($argc); // number or arguments
//print_r($argv);
$command = $argv[1];

// serve the site
if ($command == 'serve') {
    print_r(getcwd());
    $oldPath = getcwd();
    chdir(getcwd() . '\public');
    $output = shell_exec('php -S 127.0.0.1:8000');
    chdir($oldPath);
    print_r($output);
}

// Create a certain file type
else if (strpos($command, 'new:') !== false && isset($argv[2])) {
    $commandParts = explode(':', $command);
    $makeThis = $commandParts[1];

    // Create a controller
    if ($makeThis == 'controller') {
        $controllerName = $argv[2];
        $cli->createController($controllerName);
    }

    // Create a model
    if ($makeThis == 'model') {
        $modelName = $argv[2];
        $cli->createModel($modelName);
    }

} else {
    print_r("Not a valid Basic Framework command.");
}

echo "\n";
die();