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

error_reporting(E_ERROR);

if (file_exists(getcwd() . '/wp-test/public/wp-config.php')) {
    require_once getcwd() . '/wp-test/public/wp-config.php';
} elseif (file_exists(getcwd() . '/public/wp-config.php')) {
    require_once getcwd() . '/public/wp-config.php';
} else {
    die('The wrangle cli command must be run from the root of your forme base WordPress installation or a forme plugin/theme project.');
}

use Symfony\Component\Console\Application;

use function Forme\getInstance;

$application = new Application();

// automagically grab all the declared commands and add them to the application
foreach (get_declared_classes() as $class) {
    if (strpos($class, 'Commands\\Wrangle\\') !== false) {
        $command = getInstance($class);
        $application->add($command);
    }
}
$application->run();
