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

$autoloadPaths = array_filter(array(
    __DIR__ . '/../vendor/autoload.php',    // Binary is regular file in /bin
    __DIR__ . '/../../../autoload.php',     // Binary is regular file in /vendor/cargomedia/cm/bin
), function ($path) {
    return file_exists($path);
});
if (count($autoloadPaths) === 0) {
    die('ERROR: Please install project dependencies with `composer install`.' . PHP_EOL);
}
$autoloadPath = reset($autoloadPaths);

require $autoloadPath;
$bootloader = new CM_Bootloader(dirname(dirname(realpath($autoloadPath))) . '/');
$bootloader->load();

$manager = new CM_Cli_CommandManager();
$manager->autoloadCommands();
$returnCode = $manager->run(new CM_Cli_Arguments($argv));
exit($returnCode);
