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

$vendorDir = __DIR__.'/../vendor';

$file = $vendorDir.'/autoload.php';
if (file_exists($file)) {
    $autoload = require_once $file;
} else {
    die("Install dependencies before using this command.\n");
}

$configFile = getcwd() . DIRECTORY_SEPARATOR . 'cli-config.php';

$helperSet = null;
if (file_exists($configFile)) {
    if (!is_readable($configFile)) {
        trigger_error(
            'Configuration file [' . $configFile . '] does not have read permission.', E_USER_ERROR
        );
    }

    require $configFile;

    foreach ($GLOBALS as $helperSetCandidate) {
        if ($helperSetCandidate instanceof \Symfony\Component\Console\Helper\HelperSet) {
            $helperSet = $helperSetCandidate;
            break;
        }
    }
} else {
    trigger_error(
        'Configuration file [' . $configFile . '] does not exist. See https://github.com/doctrine/phpcr-odm/wiki/Command-line-tool-configuration', E_USER_ERROR
    );
}

$helperSet = ($helperSet) ?: new \Symfony\Component\Console\Helper\HelperSet();

$cli = new \Symfony\Component\Console\Application('PHPCR Command Line Interface', '0.1');
$cli->setCatchExceptions(true);
$cli->setHelperSet($helperSet);
$cli->addCommands(array(
    new \PHPCR\Util\Console\Command\NodeDumpCommand(),
    new \PHPCR\Util\Console\Command\NodeMoveCommand(),
    new \PHPCR\Util\Console\Command\NodeRemoveCommand(),
    new \PHPCR\Util\Console\Command\NodeTouchCommand(),
    new \PHPCR\Util\Console\Command\NodesUpdateCommand(),
    new \PHPCR\Util\Console\Command\NodeTypeListCommand(),
    new \PHPCR\Util\Console\Command\NodeTypeRegisterCommand(),
    new \PHPCR\Util\Console\Command\WorkspaceCreateCommand(),
    new \PHPCR\Util\Console\Command\WorkspaceDeleteCommand(),
    new \PHPCR\Util\Console\Command\WorkspaceExportCommand(),
    new \PHPCR\Util\Console\Command\WorkspaceImportCommand(),
    new \PHPCR\Util\Console\Command\WorkspacePurgeCommand(),
    new \PHPCR\Util\Console\Command\WorkspaceQueryCommand(),
));
$cli->run();

