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

/**
 * This file is part of Gush.
 *
 * (c) Luis Cordova <cordoval@gmail.com>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */
    
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\BufferedOutput;

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

$app = new Gush\Application();
$app->setAutoExit(false);

foreach ($app->getCommands() as $command) {
    $output = new BufferedOutput();
    $input = new StringInput(sprintf('%s --help --format md', $command->getName()));

    $app->run($input, $output);

    $header = <<<EOT
---
layout: docu-page
full_title: "Gush: Rapid workflow for project maintainers and contributors"
---
{% block content %}
EOT;

    $footer = <<<EOT
{% endblock content %}
EOT;

    file_put_contents(
        'web/'.$command->getName().'.md',
        sprintf("%s\n%s\n%s", $header, $output->fetch(), $footer)
    );
}
