JuliaStrelkova/project-lvl2-s427

View on GitHub
bin/gendiff

Summary

Maintainability
Test Coverage
#!/usr/bin/env php

<?php

use Gendiff\ASTBuilder;
use  Gendiff\DiffGenerator;
use Gendiff\Parser\Parser;
use Gendiff\Renderer\RendererFactory;

$autoloadPath1 = __DIR__ . '/../../../autoload.php';
$autoloadPath2 = __DIR__ . '/../vendor/autoload.php';

if (file_exists($autoloadPath1)) {
    require_once $autoloadPath1;
} else {
    require_once $autoloadPath2;
}

$doc = <<<HELP
Generate diff

Usage:
  gendiff (-h|--help)
  gendiff [--format <fmt>] <firstFile> <secondFile>

Options:
  -h --help                     Show this screen
  --format <fmt>                Report format [default: pretty]

HELP;

$args = Docopt::handle($doc, ['version' => 'Generate diff 0.6.0']);

try {
    $diffGenerator = new DiffGenerator(
        new ASTBuilder(),
        new Parser(),
        RendererFactory::getRenderer($args['--format'])
    );

    echo $diffGenerator->generateDiff($args['<firstFile>'], $args['<secondFile>']);
} catch (Throwable $e) {
    echo $e->getMessage();
}