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

namespace BHayes\CLI;

use Error;

use function Composer\Autoload\includeFile;

require_once __DIR__ . '/../bin/_environment.php';

if (php_sapi_name() == 'cli') {

    //attempt to construct the subject to run if a class name is specified as argument one.
    $argumentOne = $argv[1] ?? null;
    if (class_exists($argumentOne)){
        $subject = new $argumentOne();
        //remove the argument before passing control over to the running class.
        unset($argv[1]);
        //reset the arrays so the missing argument doesnt break things.
        $argv = array_values($argv);
        $argc -= 1;
    }

    (new CLI($subject ?? null))->run();
} else {
    throw new Error("This is a command line tool only.");
}
