cadre/cliadr

This package is abandoned and no longer maintained. No replacement package was suggested.

Command line ADR implementation

0.2.0 2017-07-06 01:41 UTC

This package is not auto-updated.

Last update: 2020-04-14 01:57:46 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\Input\HelpAwareInterface;

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

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

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

        return $help;
    }

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

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

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