#!/usr/bin/env php
<?php
/**
 * command-runner.php Handles the loading and running of OpenEMR commands that leverage the php namespaces.
 * Preference would be to use something like Symfony/Console but we are attempting to avoid too many dependencies so
 * we have written this simplified command runner for dev & openemr administration needs
 * @package openemr
 * @link      https://www.open-emr.org
 * @author    Stephen Nielson <stephen@nielson.org>
 * @copyright Copyright (c) 2021 Stephen Nielson <stephen@nielson.org>
 * @license   https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
 */
$rootPath = dirname(__DIR__) . DIRECTORY_SEPARATOR;
require_once $rootPath . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';


use OpenEMR\Common\Command\Runner\CommandRunner;
use OpenEMR\Common\Command\RootCliGuard;

if (php_sapi_name() !== 'cli') {
    echo "Only php cli can execute a command\n";
    die();
}

// Refuse to run as root. Commands dispatched here (CreateAPIDocumentation,
// etc.) write files the web server reads later; root-owned outputs would
// brick those flows. See RootCliGuard for details.
RootCliGuard::assertNotRoot();

$commandRunner = new CommandRunner($rootPath, pathinfo(__FILE__, PATHINFO_FILENAME));
$commandRunner->run();
exit;
