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

/**
 * Load correct autoloader depending on install location.
 */
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
    require __DIR__ . '/vendor/autoload.php';
} else {
    require __DIR__ . '/../../autoload.php';
}

use Knuckles\Pastel\Pastel;
use Silly\Application;

$pastel = new Pastel();

$app = new Application('Pastel', 'v0.1.0');

$arrayKeys = [
    'language_tabs',
    'toc_footers',
    'includes',
];

$app->command(
    'generate source [destination] [--metadata=]*',
    function ($source, $destination, $metadata = []) use ($arrayKeys, $pastel) {
        $overrides = [];
        foreach ($metadata as $item) {
            [$key, $value] = explode('=', $item);
            if (in_array($key, $arrayKeys)) {
                $value = explode(',', $value);
            }
            $overrides[$key] = $value;
        };
        $pastel->generate($source, $destination, $overrides);
    })
    ->descriptions(
        'Generate HTML documentation from provided Markdown file or source folder',
        [
            'source' => 'Path to Markdown docs file or source folder containing Markdown + assets.',
            'destination' => 'Path to output generated doc (HTML + assets) to.',
            '--metadata' => 'Override the values set in the frontmatter.',
        ]
    );

$app->run();