Using Action-Domain-Responder on the command line

Yesterday I was working on a project in Radar and needed to create a command line tool for it. #

In the past, I’ve always used Symfony Console which I like. Since my application was already built using Radar and adhering to Action-Domain-Responder and Clean Architecture, I wanted a solution that was more consistent with the rest of the codebase. #

The selling point to Clean Architecture is that your domain logic is separate from the delivery mechanism. So if Radar was my delivery mechanism, I should be able to have a different command line delivery mechanism and my domain shouldn’t know or care. #

I took a look at Aura.Cli which seems nice. However, it’s very much a command line library. Out of the box, it’s not a framework for building command line tools adhering to ADR. #

So I took a stab at writing one (that uses Aura.Cli), it’s called Cadre.CliAdr. #

At this point, it’s more of a proof of concept rather than a production solution. It’s heavily based on Radar and uses the same patterns. #

Here is an example of how you’d use it. It will seem very familiar if you’ve used Radar. #

use Aura\Di\ContainerBuilder;
use Aura\Cli\CliFactory;
require __DIR__ . '/../vendor/autoload.php';
$di = (new ContainerBuilder())
$adr = $di->get('cadre:cliadr/adr');
$factory = new CliFactory();
$context = $factory->newContext($GLOBALS);
$stdio = $factory->newStdio();
$adr->route('test', function ($params) {
	return 'This is a test.';
exit($adr->run($context, $stdio));

Expect revisions and documentation to come. In the meantime, please post any comments here or as an issue on GitHub. #

Published by Andrew Shell on and last updated .