#!/usr/bin/env php
<?php
ini_set('display_errors', 'stderr');
if (PHP_SAPI !== 'cli') {
  printf("cv is a command-line tool. It is designed to run with PHP_SAPI \"%s\". The active PHP_SAPI is \"%s\".\n", 'cli', PHP_SAPI);
  printf("TIP: In a typical shell environment, the \"php\" command should execute php-cli - not php-cgi or similar.\n");
  exit(1);
}
if (version_compare(PHP_VERSION, '5.4', '<')) {
  echo "cv requires PHP 5.4+\n";
  exit(2);
}
$found = 0;
$autoloaders = array(
  dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php',
  dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'autoload.php',
);
foreach ($autoloaders as $autoloader) {
  if (file_exists($autoloader)) {
    require_once $autoloader;
    $found = 1;
    break;
  }
}
if (!$found) {
  die("Failed to find autoloader");
}
\Civi\Cv\Application::main(__DIR__);
