cadre/cliadr

0.2.0 2017-07-06 01:41 UTC

README

This is a proof of concept command line Action-Domain-Responder (ADR) implementation.

It's heavily inspired by Radar.

Example

use Aura\Cli\CliFactory;
use Aura\Cli\Context;
use Aura\Cli\Help;
use Aura\Cli\Stdio;
use Cadre\CliAdr\Boot;
use Cadre\CliAdr\HelpAware;

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

$boot = new Boot();
$adr = $boot->adr();

$adr->route('hello', function ($name) {
    return "Hello, {$name}";
})->input(new class implements HelpAware {
    public function help(Help $help)
    {
        $help->setSummary('Hello, World');
        $help->setOptions([
            '#name?' => 'First name [default: "World"]',
        ]);

        return $help;
    }

    public function __invoke(Context $context, Stdio $stdio)
    {
        $getopt = $context->getopt([]);
        return [$getopt->get(2, 'World')];
    }
});

$factory = new CliFactory();
$context = $factory->newContext($GLOBALS);
$stdio = $factory->newStdio();

exit($adr->run($context, $stdio));