geozhur/project-lvl2-s337

View on GitHub
src/Cli.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php
namespace GenDiff;

use Docopt;
use function \cli\line;

const HELP = <<<DOC
    
Generate diff
    
Usage:
    gendiff (-h|--help)
    gendiff [--format <fmt>] <firstFile> <secondFile>
    
Options:
    -h --help                     Show this screen
    --format <fmt>                Report format [default: pretty]
DOC;

function run()
{
    try {
        $result = Docopt::handle(HELP, array('version' => '4.0.0'));

        $firstFile = $result->args['<firstFile>'];
        $secondFile = $result->args['<secondFile>'];
        $format = $result->args['--format'];

        line();
        line(Differ\genDiff($firstFile, $secondFile, $format));
        line();
    } catch (\Exception $e) {
        echo "Message: " . $e->getMessage();
    }
}