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

require __DIR__.'/../vendor/autoload.php';

if ($argc > 1) {
    $data = @file_get_contents($argv[1]);
} elseif (!posix_isatty(STDIN)) {
    $data = @stream_get_contents(STDIN);
} else {
    echo 'Usage: ', $argv[0], ' [FILE]', PHP_EOL;
    echo 'Dump the contents of Thrift FILE.', PHP_EOL;
    echo PHP_EOL;
    echo 'With no FILE read standard input.', PHP_EOL;

    exit(2);
}

if ($data === false) {
    fwrite(STDERR, 'Failed to read the input.'.PHP_EOL);

    exit(1);
}

try {
    new \Fbns\Client\Thrift\Debug($data);
} catch (\Exception $e) {
    fwrite(STDERR, $e->getMessage().PHP_EOL);

    exit(1);
}

exit(0);
